Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ProfessionNPC = {}
- ProfessionNPC.Entry = 10001001
- ProfessionNPC.prof = {
- [1] = {{171, 51303, "Alchemy", "201001, 201002, 201003", 51304},
- {164, 51298, "Blacksmithing", "201004, 201005, 201006", 51300},
- {333, 51312, "Enchanting", "201009, 201010, 201011", 51313},
- {202, 51305, "Engineering", "201012, 201013, 201014", 51306},
- {182, 50301, "Herbalism", "201018, 201019, 201020", 50300},
- {755, 51310, "Jewelcrafting", "201024, 201025, 201026", 51311},
- {165, 51301, "Leatherworking", "201027, 201028, 201029", 51302},
- {186, 50309, "Mining", "201033, 201034, 201035", 50310},
- {393, 50307, "Skinning", "201036, 201037, 201038", 50305},
- {197, 51308, "Tailoring", "201039, 201040, 201041", 51309}},
- [2] = {{356, 51293, "Fishing", "202001, 202002, 202003", 51294},
- {185, 51295, "Cooking", "202004, 202005, 202006", 51296},
- {129, 50299, "First Aid", "202007, 202008, 202009", 45542}}
- }
- function ProfessionNPC.LoadCache()
- for _, p in ipairs(ProfessionNPC.prof) do
- for k, v in ipairs(p) do
- local skill, spell, name, profrefs = table.unpack(v)
- local q = WorldDBQuery("SELECT SpellID FROM npc_trainer WHERE ID in(" .. profrefs .. ")")
- v[4] = {};
- local recipes = v[4]
- if q then
- repeat
- table.insert(recipes, q:GetUInt32(0))
- until not q:NextRow()
- end
- end
- end
- PrintInfo(
- "[Profession NPC]: Cache initialized. Loaded " .. #ProfessionNPC.prof[1] + #ProfessionNPC.prof[2] ..
- " professions.")
- end
- function ProfessionNPC.OnGossip(event, player, unit)
- player:GossipClearMenu()
- player:GossipMenuAddItem(3, "Primary Professions", 0, 1)
- player:GossipMenuAddItem(3, "Secondary Professions", 0, 2)
- player:GossipSendMenu(100, unit)
- end
- function ProfessionNPC.OnSelect(event, player, unit, id, intid, code)
- player:GossipClearMenu()
- if id == 0 then
- if intid == 1 or intid == 2 then
- for k, v in ipairs(ProfessionNPC.prof[intid]) do
- local skill, spell, name, recipes = table.unpack(v)
- if not player:HasSkill(skill) then
- player:GossipMenuAddItem(3, "Learn " .. name, 3 + intid, k)
- else
- player:GossipMenuAddItem(3, "Unlearn " .. name, 3 + intid, k)
- end
- end
- player:GossipMenuAddItem(7, "Back..", 0, 3)
- player:GossipSendMenu(100, unit)
- return
- elseif intid == 3 then
- On_Gossip(event, player, unit)
- return
- end
- end
- if id == 4 or id == 5 then
- id = id - 3
- local skill, spell, name, recipes, unlearnspell = table.unpack(ProfessionNPC.prof[id][intid])
- if not player:HasSkill(skill) then
- -- if id is primary prof and we cant learn more
- if id == 1 and player:GetUInt32Value(PLAYER_CHARACTER_POINTS2) <= 0 then
- player:SendNotification("You can not learn more primary professions!")
- On_Select(event, player, unit, 0, 3)
- return
- else
- player:CastSpell(player, spell)
- player:AdvanceSkill(skill, player:GetPureMaxSkillValue(skill))
- for k, v in ipairs(recipes) do
- if not player:HasSpell(v) then
- player:LearnSpell(v)
- end
- end
- end
- if id == 1 then
- player:SetUInt32Value(PLAYER_CHARACTER_POINTS2, player:GetUInt32Value(PLAYER_CHARACTER_POINTS2) - 1)
- end
- else
- for k, v in ipairs(recipes) do
- if player:HasSpell(v) then
- player:RemoveAura(v)
- player:RemoveSpell(v)
- end
- end
- player:RemoveAura(spell)
- player:RemoveAura(unlearnspell)
- player:RemoveSpell(spell)
- player:RemoveSpell(unlearnspell)
- player:SetSkill(skill, 0, 0, 0)
- if id == 1 then
- player:SetUInt32Value(PLAYER_CHARACTER_POINTS2, player:GetUInt32Value(PLAYER_CHARACTER_POINTS2) + 1)
- end
- end
- On_Select(event, player, unit, 0, id)
- return
- end
- player:GossipComplete()
- end
- ProfessionNPC.LoadCache()
- RegisterCreatureGossipEvent(ProfessionNPC.Entry, 1, ProfessionNPC.OnGossip)
- RegisterCreatureGossipEvent(ProfessionNPC.Entry, 2, ProfessionNPC.OnSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement