Advertisement
Rochet2

Starter NPC

Mar 16th, 2012
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- Settings:
  2. local NPC_Entry_1 = 123123
  3. local NPC_Entry_2 = 234234
  4. --
  5.  
  6. local Running = false
  7.  
  8. -- This is not really needed .. its just here so I can make a functioning example of the event.
  9. local function GetXY(pUnit, dist, Deg) -- left = 90 | right = -90
  10.     if(not pUnit or not dist) then return nil; elseif(not Deg) then Deg = 0; end
  11.     local o = pUnit:GetO() - math.pi/2 + math.rad(Deg)
  12.     return pUnit:GetX()-(dist*math.sin(o)), pUnit:GetY()+(dist*math.cos(o))
  13. end
  14. --
  15.  
  16. local function Run(pUnit, event)
  17.     local X,Y = GetXY(pUnit, 30, 180)
  18.     if(X and Y) then
  19.         pUnit:SetMovementFlags(1)
  20.         pUnit:MoveTo(X, Y, pUnit:GetLandHeight(X, Y), pUnit:GetO() + math.pi)
  21.         pUnit:Despawn(3000, 0)
  22.     end
  23.     Running = false
  24. end
  25.  
  26. local function Spawn(pUnit, event)
  27.     local X,Y = GetXY(pUnit, 10, 90)
  28.     if(X and Y) then
  29.         local NPC = pUnit:SpawnCreature(NPC_Entry_2, X, Y, pUnit:GetLandHeight(X, Y), pUnit:GetO()-(math.pi/4), 35, 0)
  30.         if(NPC) then
  31.             NPC:EventChat(12, 0, "Hi. I just thought I would stop by and say hello. I'll be off now, see ya!", 3000)
  32.             NPC:RegisterEvent(Run, 7000, 1)
  33.             return
  34.         end
  35.     end
  36.     Running = false
  37. end
  38.  
  39. local function FindNPC(event, pPlayer)
  40.     if(not Running) then -- If the NPCs are not already executing the script, then we can continue
  41.         local x,y,z = pPlayer:GetLocation()
  42.         local pUnit = pPlayer:GetCreatureNearestCoords(x, y, z, NPC_Entry_1) -- Find the first NPC
  43.         if(pUnit) then -- If we found the NPC, then continue
  44.             Running = true -- Set that we are now running the script and the script. This prevents the NPCs from spamming the messages
  45.             pUnit:RegisterEvent(Spawn, 13000, 1) -- Run Spawn() after 13 seconds (13000 milliseconds), one time.
  46.             pUnit:EventChat(12, 0, "Hello! This is an automatic message that will fire 10 seconds after logging in.", 10000)
  47.         end
  48.     end
  49. end
  50.  
  51. RegisterServerHook(3, FindNPC) -- Run FindNPC on player login (The first login ever)
  52. RegisterUnitEvent(NPC_Entry_1, 18, function() return; end) -- Enable the use of timed events: pUnit:RegisterEvent()
  53. 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