Would you be able to make a guard say something when you come close in Lua, i know you can in C++ but i need it in Lua and if you are able to how would it look?
thanks
Would you be able to make a guard say something when you come close in Lua, i know you can in C++ but i need it in Lua and if you are able to how would it look?
thanks
Code:function OnSpawn(pUnit, Event) pUnit:RegisterEvent("CheckForPlayers", 1000, 0) end function CheckForPlayers(pUnit) local plr = pUnit:GetClosestPlayer() if plr ~= nil then if pUnit:GetDistanceYards(plr) < 10 then pUnit:SendChatMessage(12,0,"Stay away!") end end end RegisterUnitEvent(npcid, 18, "OnSpawn")
Yes, in yards.
Currently it will keep sending that message very second while you are less than 10 yards away from the npc.
You can make it only sent the message by removing events (pUnit:RemoveEvents()) and then registering when you next want the function to be called.
i cant seem to get it to worki placed it in script folder as guard.lua
Code:function OnSpawn(pUnit, Event) pUnit:RegisterEvent("CheckForPlayers", 1000, 0) end function CheckForPlayers(pUnit) local plr = pUnit:GetClosestPlayer() if plr ~= nil then if pUnit:GetDistanceYards(plr) < 10 then pUnit:SendChatMessage(12,0,"Its dangerous out there!") end end end RegisterUnitEvent(99990, 99990, "OnSpawn")
Last edited by Fumi; 03-31-2011 at 01:01 PM.
The problem is in this line
you changed the "18" (on load) to the NPCs ID. Just write it back to 18.Code:RegisterUnitEvent(99990, 99990, "OnSpawn")
Code:RegisterUnitEvent(99990, 18, "OnSpawn")