Ive got a Horde and Alliance Only Area on my Server. To keep the oposite faction out im using the following script.
Thats an Example of the Anti-Horde Script it works perfectly the problem is my world.exe is being spammed withCode:RegisterUnitEvent(70000, 18, "Announcer") RegisterUnitEvent(70000, 4, "Announcer_Died") function Announcer_Died(Unit, event, player) Unit:RemoveEvents() end function Announcer(Unit, event, player) Unit:RegisterEvent("Announcer_Say",100, 0) end function Announcer_Say(Unit, event, player) local plr=Unit:GetRandomPlayer(2) local race=plr:GetPlayerRace() if race==1 or race==3 or race==4 or race==7 or race==11 then else Unit:CastSpellOnTarget(54028,plr) plr:Teleport(1, -2725.112, -4990.3989, 27.738) plr:SendAreaTriggerMessage("You Have Tried to Enter the Area of Your Enemy") end end
Im guessing this is when there isnt any players close to the NPC. I tried adding an if so it went like thisCode:attempt to index local 'plr' (a nil value)
And the script still runs but im still getting spammed. What could be the issue?Code:RegisterUnitEvent(70000, 18, "Announcer") RegisterUnitEvent(70000, 4, "Announcer_Died") function Announcer_Died(Unit, event, player) Unit:RemoveEvents() end function Announcer(Unit, event, player) Unit:RegisterEvent("Announcer_Say",100, 0) end function Announcer_Say(Unit, event, player) local plr=Unit:GetRandomPlayer(2) local race=plr:GetPlayerRace() if (plr==nil) then else if race==1 or race==3 or race==4 or race==7 or race==11 then else Unit:CastSpellOnTarget(54028,plr) plr:Teleport(1, -2725.112, -4990.3989, 27.738) plr:SendAreaTriggerMessage("You Have Tried to Enter the Area of Your Enemy, Alenya Has Saved you!") end end end
Also the spell isnt getting cast on the player its being cast on the NPC, its no big deal as it works without it but would be a nice touch