Advertisement
kusanagy

BeastMaster

Oct 19th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. local Beastmaster = {
  2.     entry = 1000330, -- Beastmaster entry.
  3.     maxObj = 13, -- 13 = Max amt. of menu objects.
  4. }
  5.  
  6. function Beastmaster.OnHello(event, player, unit)
  7.     -- Check whether the player is actually a hunter or not.
  8.     if(player:GetClass() == 3) then
  9.         -- Check if player is able to tame pets.
  10.         if(player:HasSpell(1515)) then
  11.             Beastmaster.GenerateMenu(1, player, unit);
  12.         else
  13.             player:SendBroadcastMessage("[Eluna Beastmaster]: You are not able to tame pets.")
  14.         end
  15.     else
  16.         player:SendBroadcastMessage("[Eluna Beastmaster]: Only Hunters can use this service!")
  17.     end
  18. end
  19.  
  20. function Beastmaster.OnSelect(event, player, unit, sender, intid, code)
  21.     -- Intid 0 is used solely for menu pages and 1 for pet selection.
  22.     if(intid == 0) then
  23.         Beastmaster.GenerateMenu(sender, player, unit);
  24.     elseif(intid == 1) then
  25.         -- Spawn a temporary, friendly version of the selected creature and force tame it.
  26.         local pet = PerformIngameSpawn(1, sender, unit:GetMapId(), unit:GetInstanceId(), unit:GetX(), unit:GetY(), unit:GetZ(), unit:GetO(), false, 5000)
  27.         pet:SetFaction(35)
  28.         player:CastSpell(pet, 2650, true)
  29.         player:GossipComplete()
  30.     end
  31. end
  32.  
  33. function Beastmaster.GenerateMenu(id, player, unit)
  34.     local low = ((Beastmaster.maxObj*id)-Beastmaster.maxObj+1)
  35.     local high = Beastmaster.maxObj*id
  36.    
  37.     -- Retrieve the current page sets' gossip option information.
  38.     for i = low, high do
  39.         local t = Beastmaster["Cache"][i]
  40.        
  41.         -- Do not list gossip options with creatures above the players level.
  42.         if(player:GetLevel() >= t["level"]) then
  43.             player:GossipMenuAddItem(2, "Level: "..t["level"].." - "..t["name"], t["entry"], 1)
  44.         end
  45.     end
  46.    
  47.     -- If the menu is not the first menu, show Previous button.
  48.     if(id ~= 1) then
  49.         player:GossipMenuAddItem(4, "<-- Previous", id-1, 0)
  50.     end
  51.    
  52.     -- If the next menu has available objects and object is within player level, show Next button.
  53.     if(Beastmaster["Cache"][high+1]) and (player:GetLevel() >= Beastmaster["Cache"][high+1]["level"]) then
  54.         player:GossipMenuAddItem(4, "Next -->", id+1, 0)
  55.     end
  56.    
  57.     player:GossipSendMenu(1, unit)
  58. end
  59.  
  60. function Beastmaster.LoadCache()
  61.     Beastmaster["Cache"] = {}
  62.     local i = 1;
  63.     local Query;
  64.    
  65.     if(GetCoreName() == "MaNGOS") then
  66.         Query = WorldDBQuery("SELECT Entry, Name, MaxLevel FROM creature_template WHERE CreatureType=1 AND CreatureTypeFlags&1 <> 0 AND Family!=0 ORDER BY MaxLevel ASC;")
  67.     elseif(GetCoreName() == "TrinityCore") then
  68.         Query = WorldDBQuery("SELECT Entry, Name, MaxLevel FROM creature_template WHERE Type=1 AND Type_Flags&1 <> 0 AND Family!=0 ORDER BY MaxLevel ASC;")
  69.     end
  70.    
  71.     if(Query) then
  72.         repeat
  73.             Beastmaster["Cache"][i] = {
  74.                 entry = Query:GetUInt32(0),
  75.                 name = Query:GetString(1),
  76.                 level = Query:GetUInt32(2)
  77.             };
  78.             i = i+1
  79.         until not Query:NextRow()
  80.         print("[Eluna Beastmaster]: Cache initialized. Loaded "..Query:GetRowCount().." tameable beasts.")
  81.     else
  82.         print("[Eluna Beastmaster]: Cache initialized. No results found.")
  83.     end
  84. end
  85.  
  86. Beastmaster.LoadCache()
  87. RegisterCreatureGossipEvent(Beastmaster.entry, 1, Beastmaster.OnHello)
  88. RegisterCreatureGossipEvent(Beastmaster.entry, 2, Beastmaster.OnSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement