Advertisement
Foereaper

Eluna Object Triggering Example

Apr 23rd, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local Quest = {
  2.     creature_entry = 123,
  3.     quest_entry = 123,
  4.     gate_entry = 123
  5. }
  6.  
  7. function Quest.OnQuestAccept(event, player, creature, quest)
  8.     -- Check if the quest we pick up matches the expected quest id.
  9.     if(quest:GetId() == Quest.quest_entry) then
  10.         -- Trigger the gate open and reset function.
  11.         Quest.TriggerGate(player)
  12.     end
  13. end
  14.  
  15. function Quest.TriggerGate(player)
  16.     -- Retrieve the gate object with a specific entry within 20 yard range of the player.
  17.     -- Can be substituted with other methods of retrieving the gate object.
  18.     local gate = player:GetGameObjectsInRange(20, Quest.gate_entry)
  19.    
  20.     if(gate) then
  21.         if(gate:GetGoState() == 1) then
  22.             -- If the object state is closed, open gate and register the gate reset event below.
  23.             gate:SetGoState(0)
  24.         elseif(gate:GetGoState() == 0)
  25.             -- If the gate is already open, remove the previous registered timed
  26.             -- event to close the gate, so it can be safely re-registered below.
  27.             gate:RemoveEvents()
  28.         end
  29.         -- Register timed event to close the gate after a set amount of time.
  30.         gate:RegisterEvent(function(_, _, _, gate) gate:SetGoState(1); return; end, 10000, 1)
  31.     end
  32. end
  33.  
  34. -- Unfortunately we can only hook quest accept event when picked up from a creature.
  35. RegisterCreatureEvent(Quest.creature_entry, 31, Quest.OnQuestAccept)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement