• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved isSorcerer(cid) not working correctly

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
Working Code

Code:
local spells = {
["Barrier"] = {
actionID = 1102,
vocation = function(cid) return isSorcerer(cid) end,
vocation2 = "sorcerer",
minL = 2
}


}


function onUse(cid, item)
local itemID = item.actionid
local L = getPlayerLevel(cid)
local player = Player(cid)

    for k, v in pairs(spells) do
        if itemID == spells[k].actionID then
          if spells[k].vocation(player) then
                if L >= spells[k].minL then  
                    if  getPlayerLearnedInstantSpell(cid, k) == false then
                        playerLearnInstantSpell(cid, k)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "you learned " ..k.. " spell")
                        --possibly different text color than default green
                        doRemoveItem(item.uid, 1)
                        return true
                    else player:sendTextMessage(MESSAGE_INFO_DESCR, "You already know this spell")
                        return true
                    end
                else player:sendTextMessage(MESSAGE_INFO_DESCR, "Need level " ..spells[k].minL.. ", to learn this spell")
                    return true
                end  
            else player:sendTextMessage(MESSAGE_INFO_DESCR, "This is "..spells[k].vocation2.." spell")
                --possibly different text color than default green  
            end
        end
    end
end
 
Last edited:
its cool that we can pull functions from tables, but i don't really know what function is isSorcerer using
I tried this(and few others), but its not working

vocation = function(cid) isSorcerer(cid) end,
 
I don't think there's such function similar to isSorcerer() provided by default in 1.0+.
You can easily add them into compat.lua though.

Code:
function isSorcerer(cid) return Player(cid):getVocation():getId() == 1 end
Or something similar
 
Code:
isSorcerer(player)

works for me in latest tfs gajs, ur script is fuckd up :p

Oh, you're right. It's already in global.lua, I checked compat.
And you're not wrong with the script, it's pretty lousy.

@whitevo
Can you explain exactly what you're trying to do so we can change up the script in its entirety?
 
if spells[k].vocation then
with this line i want it to take a spell from table and check if requirement vocation == vocation you are.
if not, it should say: what vocation can learn this spell.
 
vocation = function(cid) return isSorcerer(cid) end,

if spells[k].vocation(player) then
this is perfect

I don't think there's such function similar to isSorcerer() provided by default in 1.0+.
You can easily add them into compat.lua though.

Code:
function isSorcerer(cid) return Player(cid):getVocation():getId() == 1 end
Or something similar

This also works if i put vocation id to table and the getVocation method to function
 
Code:
local spells = {
    ["Barrier"] = {
        AID = 1102,
        vocation = 1, -- 0: none, 1: sorcerer, 2: druid, 3: paladin, 4: knight
        vocation2 = "sorcerer",
        min = 2 -- min level
    }
}


local player = {
    level = 0,
    vocation = 0
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local p = Player(cid)
    player.vocation = p:getVocation():getId()
    player.level = p:getLevel()

    for spellname, v in pairs(spells) do
        if item.actionid == spells[spellname].AID and spells[spellname].vocation == player.vocation then
            if player.level >= spells[spellname].min then
                if not p:hasLearnedSpell(spellname) then 
                    p:learnSpell(spellname)
                    --possibly different text color than default green
                    p:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations "..p:getName().."!!, you have just learned the " ..spellname.. " spell.. :)")
                    Item(item.uid):remove(1)
                else
                    p:sendTextMessage(MESSAGE_INFO_DESCR, p:getName()..", you already know this spell.")
                    return false
                end
            else
                p:sendTextMessage(MESSAGE_INFO_DESCR, p:getName().." you need to be at least level " ..spells[spellname].min.. ", to learn this spell.")
                return false
            end 
        else
            --possibly different text color than default green
            p:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry "..p:getName()..", "..spellname.." is a spell for a "..spells[spellname].vocation2..". :(")
            return false
        end
    end
    return true
end
 
Last edited:
Back
Top