• 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!

Lua [TFS 1.3] How to get target player vocation ID

E

Evil Puncker

Guest
How do I edit the transfer money part of the bank script to check if player vocationID == 0 by player name (offline/online)?

I've already created the function bellow:
Lua:
function playerExists(name)
    local resultId = db.storeQuery('SELECT `name` FROM `players` WHERE `name` = ' .. db.escapeString(name))
    if resultId then
        result.free(resultId)
        return true
    end
    return false
end

function playerVocationByName(name)
    local targetPlayer = Player(name)
    if targetPlayer then
        targetPlayer:getVocation():getId()
        -- how to return here if online?
        -- return targetPlayer:getVocation():getId()
        -- ^ ?
    else
        if not playerExists(name) then
            return false
        end
        local query = db.storeQuery("SELECT `vocation` FROM `players` WHERE `name` = " .. db.escapeString(name))
        if not query then
            return false
        end
        local value = result.getNumber(query, "vocation")
        result.free(query)
        print(value)
        return value
    end
end


here is the npc script part:
Lua:
    elseif npcHandler.topic[cid] == 12 then
        transfer[cid] = msg
        if player:getName() == transfer[cid] then
            npcHandler:say("Fill in this field with person who receives your gold!", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if playerExists(transfer[cid]) then
            if playerVocationByName(transfer[cid]) == 0 then -- is where the check should be done
                npcHandler:say("I'm afraid this character only holds a junior account at our bank. Do not worry, though. Once he has chosen his vocation, his account will be upgraded.", cid)
                npcHandler.topic[cid] = 0
            end
            npcHandler:say("So you would like to transfer " .. count[cid] .. " gold to " .. transfer[cid] .. "?", cid)
            npcHandler.topic[cid] = 13
        else
            npcHandler:say("This player does not exist.", cid)
            npcHandler.topic[cid] = 0
        end
 
Last edited by a moderator:
Solution
sorry I've just edited my post 😋 what should I put on the NPC part, that is where I'm confuse since I need to check both online and offline player vocation
That?
Lua:
if playerExists(transfer[cid]) then
            local transferPlayer = Player(transfer[cid])
            local currentVocation = transferPlayer and transferPlayer:getVocation():getId() or getPlayerVocationAux(transfer[cid])
            if currentVocation == VOCATION_NONE then
                npcHandler:say("I'm afraid this character only holds a junior account at our bank. Do not worry, though. Once he has chosen his vocation, his account will be upgraded.", cid)
                npcHandler.topic[cid] = 0
            end
            npcHandler:say("So you would like to...
Here a example:
Lua:
function getPlayerVocationAux(playerName)
    local query = db.storeQuery("SELECT `vocation` FROM `players` WHERE `name` = \"" ..playerName .. "\";")
    if not query then
        return
    end
    return result.getNumber(query, "vocation")
end
 
Here a example:
Lua:
function getPlayerVocationAux(playerName)
    local query = db.storeQuery("SELECT `vocation` FROM `players` WHERE `name` = \"" ..playerName .. "\";")
    if not query then
        return
    end
    return result.getNumber(query, "vocation")
end
sorry I've just edited my post 😋 what should I put on the NPC part, that is where I'm confuse since I need to check both online and offline player vocation
 
sorry I've just edited my post 😋 what should I put on the NPC part, that is where I'm confuse since I need to check both online and offline player vocation
That?
Lua:
if playerExists(transfer[cid]) then
            local transferPlayer = Player(transfer[cid])
            local currentVocation = transferPlayer and transferPlayer:getVocation():getId() or getPlayerVocationAux(transfer[cid])
            if currentVocation == VOCATION_NONE then
                npcHandler:say("I'm afraid this character only holds a junior account at our bank. Do not worry, though. Once he has chosen his vocation, his account will be upgraded.", cid)
                npcHandler.topic[cid] = 0
            end
            npcHandler:say("So you would like to transfer " .. count[cid] .. " gold to " .. transfer[cid] .. "?", cid)
            npcHandler.topic[cid] = 13
        else

I don't know if it's exactly what you want, but I'm giving you ideas.
 
Solution
It is really strange that I am returning you null, this works perfectly on my server.
Test again
Lua:
if playerExists(transfer[cid]) then
            local transferPlayer = Player(transfer[cid])
            local currentVocation = VOCATION_NONE
            if transferPlayer then
                   currentVocation = transferPlayer:getVocation():getId()
               else
                   currentVocation = getPlayerVocationAux(transfer[cid])
               end
            if currentVocation == VOCATION_NONE then
                npcHandler:say("I'm afraid this character only holds a junior account at our bank. Do not worry, though. Once he has chosen his vocation, his account will be upgraded.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
            npcHandler:say("So you would like to transfer " .. count[cid] .. " gold to " .. transfer[cid] .. "?", cid)
            npcHandler.topic[cid] = 13
        else
 
It is really strange that I am returning you null, this works perfectly on my server.
Test again
Lua:
if playerExists(transfer[cid]) then
            local transferPlayer = Player(transfer[cid])
            local currentVocation = VOCATION_NONE
            if transferPlayer then
                   currentVocation = transferPlayer:getVocation():getId()
               else
                   currentVocation = getPlayerVocationAux(transfer[cid])
               end
            if currentVocation == VOCATION_NONE then
                npcHandler:say("I'm afraid this character only holds a junior account at our bank. Do not worry, though. Once he has chosen his vocation, his account will be upgraded.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
            npcHandler:say("So you would like to transfer " .. count[cid] .. " gold to " .. transfer[cid] .. "?", cid)
            npcHandler.topic[cid] = 13
        else
sorry it was my bad for missing a return true, it was running the entire if block, thanks for the help
 
Back
Top