Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings:
- local NPC_Entry_1 = 123123
- local NPC_Entry_2 = 234234
- --
- local Running = false
- -- This is not really needed .. its just here so I can make a functioning example of the event.
- local function GetXY(pUnit, dist, Deg) -- left = 90 | right = -90
- if(not pUnit or not dist) then return nil; elseif(not Deg) then Deg = 0; end
- local o = pUnit:GetO() - math.pi/2 + math.rad(Deg)
- return pUnit:GetX()-(dist*math.sin(o)), pUnit:GetY()+(dist*math.cos(o))
- end
- --
- local function Run(pUnit, event)
- local X,Y = GetXY(pUnit, 30, 180)
- if(X and Y) then
- pUnit:SetMovementFlags(1)
- pUnit:MoveTo(X, Y, pUnit:GetLandHeight(X, Y), pUnit:GetO() + math.pi)
- pUnit:Despawn(3000, 0)
- end
- Running = false
- end
- local function Spawn(pUnit, event)
- local X,Y = GetXY(pUnit, 10, 90)
- if(X and Y) then
- local NPC = pUnit:SpawnCreature(NPC_Entry_2, X, Y, pUnit:GetLandHeight(X, Y), pUnit:GetO()-(math.pi/4), 35, 0)
- if(NPC) then
- NPC:EventChat(12, 0, "Hi. I just thought I would stop by and say hello. I'll be off now, see ya!", 3000)
- NPC:RegisterEvent(Run, 7000, 1)
- return
- end
- end
- Running = false
- end
- local function FindNPC(event, pPlayer)
- if(not Running) then -- If the NPCs are not already executing the script, then we can continue
- local x,y,z = pPlayer:GetLocation()
- local pUnit = pPlayer:GetCreatureNearestCoords(x, y, z, NPC_Entry_1) -- Find the first NPC
- if(pUnit) then -- If we found the NPC, then continue
- Running = true -- Set that we are now running the script and the script. This prevents the NPCs from spamming the messages
- pUnit:RegisterEvent(Spawn, 13000, 1) -- Run Spawn() after 13 seconds (13000 milliseconds), one time.
- pUnit:EventChat(12, 0, "Hello! This is an automatic message that will fire 10 seconds after logging in.", 10000)
- end
- end
- end
- RegisterServerHook(3, FindNPC) -- Run FindNPC on player login (The first login ever)
- RegisterUnitEvent(NPC_Entry_1, 18, function() return; end) -- Enable the use of timed events: pUnit:RegisterEvent()
- RegisterUnitEvent(NPC_Entry_2, 18, function() return; end) -- Enable the use of timed events: pUnit:RegisterEvent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement