Advertisement
Rochet2

Eluna profession NPC

May 4th, 2015
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. local NPC_ID = 600000
  2.  
  3. local prof = {
  4.     [1] = {
  5.         --  {skill, spell, "name",      "npc_trainer reference IDs"},
  6.         {171, 51303, "Alchemy",         "201001, 201002, 201003"},
  7.         {164, 51298, "Blacksmithing",   "201004, 201005, 201006"},
  8.         {333, 51312, "Enchanting",      "201009, 201010, 201011"},
  9.         {202, 51305, "Engineering",     "201012, 201013, 201014"},
  10.         {182, 50301, "Herbalism",       "201018, 201019, 201020"},
  11.         {773, 45380, "Inscription",     "201021, 201022, 201023"},
  12.         {755, 51310, "Jewelcrafting",   "201024, 201025, 201026"},
  13.         {165, 51301, "Leatherworking",  "201027, 201028, 201029"},
  14.         {186, 50309, "Mining",          "201033, 201034, 201035"},
  15.         {393, 50307, "Skinning",        "201036, 201037, 201038"},
  16.         {197, 51308, "Tailoring",       "201039, 201040, 201041"},
  17.     },
  18.    
  19.     [2] = {
  20.         --  {skill, spell, "name",  "npc_trainer reference IDs"},
  21.         {356, 51293, "Fishing",     "202001, 202002, 202003"},
  22.         {185, 51295, "Cooking",     "202004, 202005, 202006"},
  23.         {129, 50299, "First Aid",   "202007, 202008, 202009"},
  24.     },
  25. }
  26.  
  27. for _, p in ipairs(prof) do
  28.     for k, v in ipairs(p) do
  29.         local skill, spell, name, profrefs = table.unpack(v)
  30.         local q = WorldDBQuery("SELECT spell FROM npc_trainer WHERE entry in("..profrefs..")")
  31.         v[4] = {};
  32.         local recipes = v[4]
  33.         if q then
  34.             repeat
  35.                 table.insert(recipes, q:GetUInt32(0))
  36.             until not q:NextRow()
  37.         end
  38.     end
  39. end
  40.  
  41. local function On_Gossip(event, player, unit)
  42.     player:GossipClearMenu()
  43.     player:GossipMenuAddItem(3, "Primary Professions", 0, 1)
  44.     player:GossipMenuAddItem(3, "Secondary Professions", 0, 2)
  45.     player:GossipSendMenu(100, unit)
  46. end
  47.  
  48. local function On_Select(event, player, unit, id, intid, code)
  49.     player:GossipClearMenu()
  50.     if id == 0 then
  51.         if intid == 1 or intid == 2 then
  52.             for k, v in ipairs(prof[intid]) do
  53.                 local skill, spell, name, recipes = table.unpack(v)
  54.                 if not player:HasSkill(skill) then
  55.                     player:GossipMenuAddItem(3, "Learn "..name, 3+intid, k)
  56.                 else
  57.                     player:GossipMenuAddItem(3, "Unlearn "..name, 3+intid, k)
  58.                 end
  59.             end
  60.             player:GossipMenuAddItem(7, "Back..", 0, 3)
  61.             player:GossipSendMenu(100, unit)
  62.             return
  63.         elseif intid == 3 then
  64.             On_Gossip(event, player, unit)
  65.             return
  66.         end
  67.     end
  68.    
  69.     if id == 4 or id == 5 then
  70.         id = id-3
  71.        
  72.         local skill, spell, name, recipes = table.unpack(prof[id][intid])
  73.         if not player:HasSkill(skill) then
  74.             -- if id is primary prof and we cant learn more
  75.             if id == 1 and player:GetUInt32Value(1021) <= 0 then
  76.                 player:SendNotification("You can not learn more primary professions")
  77.             else
  78.                 player:CastSpell(player, spell)
  79.                 player:AdvanceSkill(skill, 450)
  80.                 for k, v in ipairs(recipes) do
  81.                     if not player:HasSpell(v) then
  82.                         player:LearnSpell(v)
  83.                     end
  84.                 end
  85.             end
  86.         else
  87.             player:SetSkill(skill, 0, 0, 0)
  88.         end
  89.        
  90.         On_Select(event, player, unit, 0, id)
  91.         return
  92.     end
  93.    
  94.     player:GossipComplete()
  95. end
  96.  
  97. RegisterCreatureGossipEvent(NPC_ID, 1, On_Gossip)
  98. RegisterCreatureGossipEvent(NPC_ID, 2, On_Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement