I use this code:
Code:
function AddsSpawnKeymaster(pUnit, Event)
pUnit:RegisterEvent("AddsAttackKeymaster", 800, 1)
end
-- This function is used by scripts accross the zone
function AddsAttackKeymaster(pUnit)
pUnit:CastSpell(61456) -- spawn visual
local plr = pUnit:GetClosestPlayer()
if plr then
pUnit:AttackReaction(plr, 1, 0)
end
end
RegisterUnitEvent(442200, 18, "AddsSpawnKeymaster")
When creature spawns, wait near to a second so that the creature has a chance to be fully pushed to the world, then cast a spawn visual, find the closest player and set aggro with them for the creature to enter combat with them.