• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved TFS 1.0 Creaturescript : onAdvance

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
2,124
Solutions
14
Reaction score
1,518
Location
USA
GitHub
Codinablack
Greetings Otland.

Here I come to you today in regards of a script I have been working on to enhance skill points. More of an advanced skill points system altogether. Anyways I seem to be stuck. I want the script to add points in groups, table groups by vocations. Anyways, I can't seem to get it to add the points.

NOTE: All variables not defined in script are defined in my global.lua

Code:
local Mages = {MAGE, WARLOCK, SORCEROR, MEDIUM, WITCHDOCTOR, ELEMENTALIST, PYROMANCER, HYDROMANCER, GEOMANCER, AEROMANCER, SCHOLAR, PHILOSOPHER, SAGE, CONJURER, SUMMONER, PROSELYTE, CLERIC, BISHOP, DRUID, ACOLYTE}
local Rangers = {NEOPHYTE, ARCHER, KNAVE, THIEF, BANDIT, ROGUE, MARSKMAN, SNIPER}
local Assault = {SQUIRE, KNIGHT, HOLY_KNIGHT, DARK_KNIGHT, BARON, WARRIOR, MONK, LEGENDARY_FIGHTER, TYRO, SOLDIER, MERCENARY}
local Defense = {SENTRY, SENTINEL, GUARDIAN, ENGINEER, TECHNICIAN, SMITH, CHEMIST}

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = player:getVocation()
        if (skill == 8) then
       
            if player:getStorageValue(ATTRIBUTE_LEVEL) < newlevel then
                if player:getStorageValue(ATTRIBUTE_POINTS) < 0 then
                    player:setStorageValue(ATTRIBUTE_POINTS, 0)
                        player:setStorageValue(ATTRIBUTE_LEVEL, 0)
                            player:setStorageValue(VITALITY, 0)
                            player:setStorageValue(DEXTERITY, 0)
                        player:setStorageValue(INTELLIGENCE, 0)
                    player:setStorageValue(STRENGTH, 0)
                end
            end
           
            if isInArray(Mages, vocation) then
                    player:setStorageValue(VITALITY, (player:getStorageValue(VITALITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(DEXTERITY, (player:getStorageValue(DEXTERITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(INTELLIGENCE, (player:getStorageValue(INTELLIGENCE) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(STRENGTH, (player:getStorageValue(STRENGTH) + ((newlevel - oldlevel) * 1)))
            end
            player:setStorageValue(ATTRIBUTE_LEVEL, newlevel)
            doCreatureSay(cid, '+ Attribute Points!', TALKTYPE_ORANGE_1)
        end
    return true
end

I was mistakenly using a loop before, "for index, vocation in ipairs(Mages) do" and it did successfully add points, but of course it added 20 points because that's how many values I have in that table, so yeah that was totally the wrong way to do...

Still having trouble with these tables apparently, I would be very appreciative of any help I could get please.
 
I tried it a different way and it is still not working like this:

Code:
local Mages = {MAGE, WARLOCK, SORCEROR, MEDIUM, WITCHDOCTOR, ELEMENTALIST, PYROMANCER, HYDROMANCER, GEOMANCER, AEROMANCER, SCHOLAR, PHILOSOPHER, SAGE, CONJURER, SUMMONER, PROSELYTE, CLERIC, BISHOP, DRUID, ACOLYTE}
local Rangers = {NEOPHYTE, ARCHER, KNAVE, THIEF, BANDIT, ROGUE, MARSKMAN, SNIPER}
local Assault = {SQUIRE, KNIGHT, HOLY_KNIGHT, DARK_KNIGHT, BARON, WARRIOR, MONK, LEGENDARY_FIGHTER, TYRO, SOLDIER, MERCENARY}
local Defense = {SENTRY, SENTINEL, GUARDIAN, ENGINEER, TECHNICIAN, SMITH, CHEMIST}

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = player:getVocation()
        if (skill == 8) then
       
            if player:getStorageValue(ATTRIBUTE_LEVEL) < newlevel then
                if player:getStorageValue(ATTRIBUTE_POINTS) < 0 then
                    player:setStorageValue(ATTRIBUTE_POINTS, 0)
                        player:setStorageValue(ATTRIBUTE_LEVEL, 0)
                            player:setStorageValue(VITALITY, 0)
                            player:setStorageValue(DEXTERITY, 0)
                        player:setStorageValue(INTELLIGENCE, 0)
                    player:setStorageValue(STRENGTH, 0)
                end
            end
           
            if vocation == isInArray(Mages) then
                    player:setStorageValue(VITALITY, (player:getStorageValue(VITALITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(DEXTERITY, (player:getStorageValue(DEXTERITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(INTELLIGENCE, (player:getStorageValue(INTELLIGENCE) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(STRENGTH, (player:getStorageValue(STRENGTH) + ((newlevel - oldlevel) * 1)))
            end
            player:setStorageValue(ATTRIBUTE_LEVEL, newlevel)
            doCreatureSay(cid, '+ Attribute Points!', TALKTYPE_ORANGE_1)
        end
    return true
end
 
I assume that the variables represents vocation ids so you should check id instead of userdata.

local vocation = player:getVocation():getId()
 
Now I am getting this error in console for a new table I added....

Code:
Lua Script Error: [Test Interface]
data/creaturescripts/scripts/attributegain.lua
data/creaturescripts/scripts/attributegain.lua:6: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/creaturescripts/scripts/attributegain.lua:6: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/attributegain.lua

here is the new script...

Code:
local Mages = {MAGE, WARLOCK, SORCEROR, MEDIUM, WITCHDOCTOR, ELEMENTALIST, PYROMANCER, HYDROMANCER, GEOMANCER, AEROMANCER, SCHOLAR, PHILOSOPHER, SAGE, CONJURER, SUMMONER, PROSELYTE, CLERIC, BISHOP, DRUID, ACOLYTE}
local Rangers = {NEOPHYTE, ARCHER, KNAVE, THIEF, BANDIT, ROGUE, MARSKMAN, SNIPER}
local Assault = {SQUIRE, KNIGHT, HOLY_KNIGHT, DARK_KNIGHT, BARON, WARRIOR, MONK, LEGENDARY_FIGHTER, TYRO, SOLDIER, MERCENARY}
local Defense = {SENTRY, SENTINEL, GUARDIAN, ENGINEER, TECHNICIAN, SMITH, CHEMIST}

local Vitality = {[Mage] = 1, [Ranger] = 1, [Assault] = 1, [Defense] = 1}
local Dexterity = {[Mage] = 1, [Ranger] = 1, [Assault] = 1, [Defense] = 1}
local Intelligence = {[Mage] = 1, [Ranger] = 1, [Assault] = 1, [Defense] = 1}
local Strength = {[Mage] = 1, [Ranger] = 1, [Assault] = 1, [Defense] = 1}

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = player:getVocation():getId()
        if (skill == 8) then
       
            if player:getStorageValue(ATTRIBUTE_LEVEL) < newlevel then
                if player:getStorageValue(ATTRIBUTE_POINTS) < 0 then
                    player:setStorageValue(ATTRIBUTE_POINTS, 0)
                        player:setStorageValue(ATTRIBUTE_LEVEL, 0)
                            player:setStorageValue(VITALITY, 0)
                            player:setStorageValue(DEXTERITY, 0)
                        player:setStorageValue(INTELLIGENCE, 0)
                    player:setStorageValue(STRENGTH, 0)
                end
            end
           
            if isInArray(Mages, vocation) then
                    player:setStorageValue(VITALITY, (player:getStorageValue(VITALITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(DEXTERITY, (player:getStorageValue(DEXTERITY) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(INTELLIGENCE, (player:getStorageValue(INTELLIGENCE) + ((newlevel - oldlevel) * 1)))
                    player:setStorageValue(STRENGTH, (player:getStorageValue(STRENGTH) + ((newlevel - oldlevel) * 1)))
            end
            player:setStorageValue(ATTRIBUTE_LEVEL, newlevel)
            doCreatureSay(cid, '+ Attribute Points!', TALKTYPE_ORANGE_1)
        end
    return true
end

thought it may have been because of the "local" in front of my tables, so I removed all the local's from my tables and still same exact error...
 
You are using undefined/nil values as indexes. I'm assuming you want for example Mage to be the index, so you should enter the index as a string, wrapped in quotes.
Code:
local Vitality = {["Mage"] = 1, ["Ranger"] = 1, ["Assault"] = 1, ["Defense"] = 1}
 
You are using undefined/nil values as indexes. I'm assuming you want for example Mage to be the index, so you should enter the index as a string, wrapped in quotes.
Code:
local Vitality = {["Mage"] = 1, ["Ranger"] = 1, ["Assault"] = 1, ["Defense"] = 1}

Ah, thank you very much forgee, that is indeed what I forgot to do.... thank you man...
 
You are using undefined/nil values as indexes. I'm assuming you want for example Mage to be the index, so you should enter the index as a string, wrapped in quotes.
Code:
local Vitality = {["Mage"] = 1, ["Ranger"] = 1, ["Assault"] = 1, ["Defense"] = 1}

Hey couldn't I do this?

if skill ~= 8 then return true end

at the beginning of the script and then if it is anything but level it doesn't do the rest of the script?
 
Back
Top