Advertisement
Rochet2

Untitled

Aug 17th, 2014
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. local Lazy_Peon = {
  2.     ENTRY_LAZY_PEON = 10556,
  3.     ENTRY_LUMBERPILE = 175784,
  4.     SAY_PEON_AWAKE = {
  5.         "Just was resting eyes! Back to work now!",
  6.         "OK boss, I get back to tree-hitting.",
  7.         "Ow! OK, I'll get back to work, %s!",
  8.     },
  9.     SAY_PEON_ASLEEP = "Sleepy... so sleepy...",
  10.     SPELL_PEON_SLEEP = 17743,
  11.     SPELL_PEON_AWAKEN = 19938,
  12. };
  13.  
  14. function Lazy_Peon.OnSpawn(event, creature)
  15.     Lazy_Peon.Reset(creature)
  16.     creature:SetData(StopSleepingTimer, math.random(30000, 120000))
  17. end
  18.  
  19. function Lazy_Peon.Reset(creature)
  20.     local reset, stop = creature:GetData(ResetSleepingTimer), creature:GetData(StopSleepingTimer)
  21.     if (sleep) then
  22.         creature:RemoveEventById(sleep)
  23.         creature:SetData(ResetSleepingTimer, nil)
  24.     end
  25.     if (stop) then
  26.         creature:RemoveEventById(stop)
  27.     end
  28.     creature:SetData(StopSleepingTimer, creature:RegisterEvent(Lazy_Peon.OnStopSleepingTimer, math.random(90000, 120000), 1))
  29. end
  30.  
  31. function Lazy_Peon.OnResetSleepingTimer(eventId, delay, repeats, creature)
  32.     creature:SetData(ResetSleepingTimer, nil)
  33.     -- DoScriptText(SAY_PEON_AWAKE_2, m_creature);
  34.     creature:Emote(EMOTE_STATE_NONE);
  35.     -- EnterEvadeMode();
  36. end
  37.  
  38. function Lazy_Peon.OnStopSleepingTimer(eventId, delay, repeats, creature)
  39.     creature:SetData(StopSleepingTimer, nil)
  40.     Lazy_Peon.StartLumbering(creature, creature)
  41. end
  42.  
  43. function Lazy_Peon.StartLumbering(creature, unit)
  44.     local stop = creature:GetData(StopSleepingTimer)
  45.     if (stop) then
  46.         creature:RemoveEventById(stop)
  47.         creature:SetData(StopSleepingTimer, nil)
  48.     end
  49.     local lumber = creature:GetNearestGameObject(15, Lazy_Peon.ENTRY_LUMBERPILE)
  50.     if(lumber) then
  51.         creature:RemoveAura(Lazy_Peon.SPELL_PEON_SLEEP)
  52.         creature:SetWalk(false)
  53.         local x, y, z = lumber:GetLocation()
  54.        
  55.         if(unit:GetTypeId() == 4) then -- Player type ID
  56.             local StringSelect = string.format(Lazy_Peon.SAY_PEON_AWAKE[math.random(#Lazy_Peon.SAY_PEON_AWAKE)], unit:GetName())
  57.             creature:SendChatMessageToPlayer(1, 0, StringSelect, unit)
  58.             unit:KilledMonsterCredit(Lazy_Peon.ENTRY_LAZY_PEON)
  59.             creature:MoveTo(1, x, y, z)
  60.         else
  61.             creature:MoveTo(2, x, y, z)
  62.         end
  63.     end
  64. end
  65.  
  66. function Lazy_Peon.OnReachWP(event, creature, movetype, id)
  67.     local stop = creature:GetData(ResetSleepingTimer)
  68.     if (stop) then
  69.         creature:RemoveEventById(stop)
  70.     end
  71.     local ResetTime = id == 1 and 80000 or math.random(30000, 60000)
  72.     creature:SetData(ResetSleepingTimer, creature:RegisterEvent(Lazy_Peon.OnResetSleepingTimer, ResetTime, 1))
  73.     creature:Emote(234) -- EMOTE_STATE_WORK_CHOPWOOD
  74. end
  75.  
  76. function Lazy_Peon.AwakenSpellCast(event, player, spell)
  77.     if(spell:GetEntry() == Lazy_Peon.SPELL_PEON_AWAKEN) then
  78.         local target = spell:GetTarget()
  79.         if(not target:HasAura(Lazy_Peon.SPELL_PEON_SLEEP)) or (not target:GetEntry() == Lazy_Peon.ENTRY_LAZY_PEON) then
  80.             return;
  81.         end
  82.        
  83.         StartLumbering(target, player)
  84.     end
  85. end
  86.  
  87. RegisterCreatureEvent(Lazy_Peon.ENTRY_LAZY_PEON, 5, Lazy_Peon.OnSpawn)
  88. RegisterCreatureEvent(Lazy_Peon.ENTRY_LAZY_PEON, 5, Lazy_Peon.OnReachWP)
  89. RegisterPlayerEvent(5, Lazy_Peon.AwakenSpellCast)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement