I'm currently trying to write a Level/XP script. I have got the leveling up and all that to work using a pair of custom functions called GainXP and LevelUpb , but then it comes to actually writing I initially started off using something along the lines of this:
Code: Select all
function onNPCKill(EventObj, killedNPC, killReason)
if killedNPC.id == 1 then
GainXP(1)
end
end
GainXP is a function I made to automate the experience gaining process, along with another function, LevelUp. Since if killedNPC == x has to be typed out every single time, it's a pain to use and isn't exactly multi-level. Instead, I declared a table and a function to go with it called xpDrop, with the intention of adding xpDrop to each level's luna.lua, as well as in the singular one for the episode. However, when I try to run this code:
Code: Select all
function onNPCKill(EventObj, killedNPC, killReason)
if xpDrops[killedNPC.id] ~= nil then
GainXP(xpDrops[killedNPC.id])
end
end
Nothing happens. If I run GainXP(xpDrops[x]) using the tab prompt then I do get the experience for that NPC. What is the proper way of doing this?