Advertisement
Rochet2

Gurubashi Theme Generator

Jul 28th, 2012
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. --[[
  2. ## Gurubashi Theme Generator ##
  3. Original credits to Hkarta.
  4.  
  5. Base for this script here by Sdyess:
  6. http://www.ac-web.org/forums/showthread.php?t=150939
  7.  
  8. Modified to lua by Rochet2
  9.  
  10. Use the SQL provieded by Sdyess!
  11. ]]
  12.  
  13. local NPCID = 123123 -- NPC ENTRY HERE
  14.  
  15. local OFFSET_THEME = 1000
  16.  
  17. local function GetLastThemeTime()
  18.     local Q = WorldDBQuery("SELECT `time` FROM `gurubashi_lastspawned`")
  19.     if (Q) then
  20.         return Q:GetColumn(0):GetUInt32()
  21.     else
  22.         return 0
  23.     end
  24. end
  25.  
  26. local function GossipObjects(player, m_creature)
  27.     m_creature:GossipCreateMenu(1, pPlayer, 0)
  28.     if (GetLastThemeTime() + 600 <= os.time()) then
  29.         local Q = WorldDBQuery("SELECT `id`, `name` FROM `gurubashi_themes`")
  30.         if (Q) then
  31.             for i = 1, Q:GetRowCount() do
  32.                 m_creature:GossipMenuAddItem(4, Q:GetColumn(1):GetString(), OFFSET_THEME + Q:GetColumn(0):GetInt32(), 0)
  33.                 Q:NextRow()
  34.             end
  35.         end
  36.     else
  37.         local time2 = GetLastThemeTime() + 600 - os.time()
  38.         local msg = ""
  39.         if (time2 < 60) then
  40.             msg = "Next change possible in less than minute."
  41.         else
  42.             msg = "Next change possible in "..(time2 / 60).." minute/s."
  43.         end
  44.         m_creature:GossipMenuAddItem(0, msg, 2, 0)
  45.     end
  46.     m_creature:GossipMenuAddItem(0, "Good bye", 1, 0)
  47.     m_creature:GossipSendMenu(player)
  48. end
  49.  
  50. local function OnGossipHello(pCreature, event, pPlayer)
  51.     GossipObjects(pPlayer, pCreature)
  52. end
  53.        
  54. local function OnGossipSelect(m_creature, event, player, sender, action, code)
  55.     if (action > OFFSET_THEME) then
  56.         WorldDBQuery("DELETE FROM `gurubashi_lastspawned`")
  57.         WorldDBQuery("INSERT INTO `gurubashi_lastspawned` VALUES ("..os.time()..")")
  58.         local Q = WorldDBQuery("SELECT `x`, `y`, `z`, `o`, `entry` FROM `gurubashi_spawns` WHERE `theme` = "..(action - OFFSET_THEME))
  59.         if (Q) then
  60.             player:SendAreaTriggerMessage(12, 0, "Spawning gameobjects..")
  61.             for i = 1, Q:GetRowCount() do
  62.                 m_creature:SpawnGameObject(Q:GetColumn(4):GetInt32(), Q:GetColumn(0):GetFloat(), Q:GetColumn(1):GetFloat(), Q:GetColumn(2):GetFloat(), Q:GetColumn(3):GetFloat(), 600000, 100)
  63.                 Q:NextRow()
  64.             end
  65.         else
  66.             player:SendAreaTriggerMessage("No gameobjects found")
  67.             OnGossipHello(m_creature, event, player)
  68.         end
  69.     elseif(action == 1) then
  70.         player:GossipComplete()
  71.     elseif(action == 2) then
  72.         GossipObjects(player, m_creature)
  73.     end
  74. end
  75.  
  76. RegisterUnitGossipEvent(NPCID, 1, OnGossipHello)
  77. RegisterUnitGossipEvent(NPCID, 2, OnGossipSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement