Advertisement
0Voltage

[Eluna] Profession NPC

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