Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function print_table(self) -- by MaXwEllDeN
- local str = "{"
- for i, v in pairs(self) do
- local index = type(i) == "string" and "[\"".. i .. "\"]" or "[".. i .. "]"
- local value = type(v) == "table" and print_table(v) or type(v) == "string" and "\"".. v .. "\"" or tostring(v)
- str = str .. index .. " = ".. value .. ", "
- end
- return (#str > 1 and str:sub(1, #str - 2)) .. "}"
- end
- function getPetSpellsTable(item_uid)
- local ret = {}
- if item_uid > 100 then
- local str = getItemAttribute(item_uid, "pet_spells")
- if str then
- ret = loadstring("return ".. str)()
- end
- end
- if #ret > 1 then
- table.sort(ret, function(a, b) return a.level < b.level end)
- end
- return ret
- end
- function savePetSpells(item_uid, spell_table)
- return doItemSetAttribute(item_uid, "pet_spells", print_table(spell_table))
- end
- function doPetAddSpell(item_uid, spell)
- local spells = getPetSpellsTable(item_uid)
- table.insert(spells, spell)
- return savePetSpells(item_uid, spells)
- end
- function doPetForgetSpell(item_uid, spell_name)
- local spells = {}
- for _, spell in pairs(getPetSpellsTable(item_uid)) do
- if spell.name ~= spell_name then
- table.insert(spells, spell)
- end
- end
- return savePetSpells(item_uid, spells)
- end
- function getPetSpell(item_uid, spell_name)
- for _, spell in pairs(getPetSpellsTable(item_uid)) do
- if spell.name == spell_name then
- return spell
- end
- end
- return nil
- end
Advertisement
Add Comment
Please, Sign In to add comment