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:
here is the npc script part:
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: