• 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.2] Spell Learner Problem.

Status
Not open for further replies.
Joined
Mar 24, 2013
Messages
59
Reaction score
9
So first off its a Long time ago i acctuly made a script and i was in the progress of learning lua but i didnt really finish it because i simply didnt understand... but oh well excuses aside the problem with the script is that i dont know the problem it doesnt give me a error or anything it just doesnt do the thing its supposed to do i tryd checking luascript.lua, compat.lua to see if i used something wrong but i couldnt find it i also tryd https://www.lua.org/pil/contents.html to see if i did something wrong but i couldnt find anything either so... what did i do wrong here?.

i simply used 1 spell for all vocations to see if it acctuly works or not.. ( it didnt)

Code:
    <instant group="attack" spellid="654" name="kabloei" words="kabloei" lvl="50"  mana="25" exhaustion="1000" prem="0" needlearn="1" needtarget="1" blockwalls="0" aggressive="1" script="kabloei.lua">

Code:
local t = {
    [{1, 5}] = {"kabloei"},
    [{2, 6}] = {"kabloei"},
    [{3, 7}] = {"kabloei"},
    [{4, 8}] = {"kabloei"}
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    for k, v in pairs(t) do
        if isInArray(k, player:getVocation()) then
            if not player:hasLearnedSpell(v[1]) then
                player:learnSpell(v[1])
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have learned the spell " .. v[1])
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                item:remove(1)
            else
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already Learned this spell")
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
            end
        end
    end
    return true
end
 
It will never get past the first conditional expression isInArray(k, player:getVocation()) because when you use 'player:getVocation()' you are actually accessing a Vocation userdata object. You need to use the Vocation method ':getId()' to return the vocation ID.

So basically what you should use is 'player:getVocation():getId()'.
 
Status
Not open for further replies.
Back
Top