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

bank transfer to voc > 0

Mauzim

Member
Joined
Jan 3, 2011
Messages
568
Reaction score
9
how to add it here
Code:
-- transfer 
    if talk_state[cid] == 40 and getCount(msg) > 0 then 
        if getPlayerBalance(cid) >= getCount(msg) then 
            talk_state[cid] = 41 
            last_count[cid] = getCount(msg) 
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?' 
        else 
            talk_state[cid] = 0 
            sayText = 'There is not enough gold on your account.' 
        end 
    elseif talk_state[cid] == 41 then 
        local toPlayer = doPlayerExist(msg) 
        if toPlayer ~= 0 then 
            last_name[cid] = toPlayer 
            talk_state[cid] = 42 
            sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. last_name[cid] .. '?' 
        else 
            talk_state[cid] = 0 
            sayText = 'This player does not exist.' 
        end
 
something like this maybe
PHP:
-- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer ~= 0 then
            if getPlayerVocation(toPlayer) > 0 then
                last_name[cid] = toPlayer
                talk_state[cid] = 42
                sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. last_name[cid] .. '?'
            else
                talk_state[cid] = 0
                sayText = 'You cannot transfer money to rookgaard.'          
            end
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end

I used "toPlayer" as cid.. as I'm not sure if toPlayer is the "target cid".
 
[Error - NpcScript Interface]
data/npc/scripts/Znozel.lua:eek:nCreatureSay
Description:
(LuaInterface::internalGetPlayerInfo) Player not found when requesting player in
fo #6

[Error - NpcScript Interface]
data/npc/scripts/Znozel.lua:eek:nCreatureSay
Description:
data/npc/scripts/Znozel.lua:259: attempt to compare number with boolean
stack traceback:
data/npc/scripts/Znozel.lua:259: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:501: in function 'onCreatureSay'
data/npc/scripts/Znozel.lua:56: in function <data/npc/scripts/Znozel.lua
:56>
 
Code:
function doPlayerExist(name)
    local result = db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if (result:getID() ~= -1) then
        local return_name = result:getDataString("name")
        result:free()
        return return_name
    end
    return 0
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)    npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                        npcHandler:onThink()    end

local talk_state = {}
local last_count = {}
local last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end

so dude u can do something with it i think create other function like
function doPlayerExist with vocation but how to do that
 
Last edited by a moderator:
PHP:
function doPlayerExist(name)
    player = getPlayerGUIDByName(name)
    if player > 0 then
        return player
    else
        return 0
    end
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)    npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                        npcHandler:onThink()    end

local talk_state = {}
local last_count = {}
local last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end

PHP:
-- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer > 0 then
            player_name = getPlayerName(toPlayer)
            talk_state[cid] = 42
            sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. player_name .. '?'
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
 
hmm what is that?;d that isn't work right i need w/o voc 0
sorry, I did your things kinda in last second before bed and I messed up a bit due to had hurry + tired as a cow..
eating breakfast now and I'll fix the codes when I'm done

PHP:
-- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer > 0 then
            player_cid = getPlayerByName(toPlayer)
            if getPlayerVocation(player_cid) > 0 then
                player_name = getPlayerName(player_cid)
                talk_state[cid] = 42
                sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. player_name .. '?'
            else
                talk_state[cid] = 0
                sayText = 'You cannot send money to rookgaard.'          
            end
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
 
Last edited by a moderator:
[Error - NpcScript Interface]
data/npc/scripts/Znozel.lua:eek:nCreatureSay
Description:
(LuaInterface::internalGetPlayerInfo) Player not found when requesting player in
fo #6

[Error - NpcScript Interface]
data/npc/scripts/Znozel.lua:eek:nCreatureSay
Description:
data/npc/scripts/Znozel.lua:260: attempt to compare number with boolean
stack traceback:
data/npc/scripts/Znozel.lua:260: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:501: in function 'onCreatureSay'
data/npc/scripts/Znozel.lua:56: in function <data/npc/scripts/Znozel.lua
:56>
still same problem with boolean ;d have u tested it in tfs 4.0?

it is 260 line if getPlayerVocation(player_cid) > 0 then
 
I don't have TFS 4.0, and I haven't tested them.
if you could post the entire Znozel.lua script it would be easier for me to understand the error.
if you don't want it public you can send it by PM to me so I can check what's causing it without guessing
 
Code:
function getCount(msg)
    local ret = -1
    local b, e = string.find(msg, "%d+")
    if b ~= nil and e ~= nil then
      ret = tonumber(string.sub(msg, b, e))
    end
    if ret > 10000000 then
        return 10000000
    end
    return ret
end

function msgcontains(message, keyword)
    local a, b = string.find(message, keyword)
    if a == nil or b == nil then
        return false
    end
    return true
end

function addCoin(cid, itemid, count)
    if count > 100 then
        while(count > 100) do
            cash = doCreateItemEx(itemid, 100)
            doPlayerAddItemEx(cid, cash, 1)
            count = count - 100
        end
    end
    if count > 0 then
        cash = doCreateItemEx(itemid, count)
        doPlayerAddItemEx(cid, cash, 1)
    end
end

function doPlayerExist(name)
    local result = db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if (result:getID() ~= -1) then
        local return_name = result:getDataString("name")
        result:free()
        return return_name
    end
    return 0
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    talk_state[cid] = 0
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                            npcHandler:onThink()                        end

talk_state = {}
last_count = {}
last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end
    local sayText = ""
    if talk_state[cid] == nil then
        talk_state[cid] = 0
        last_count[cid] = 0
        last_name[cid] = ""
    end
    -- select action
    if msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 10
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 0
        local balance = getPlayerBalance(cid)
        if balance == 0 then
            sayText = ''
        else 
            sayText = ''
        end
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 20
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 30
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 40
        sayText = ''
    end
    --  change
    if talk_state[cid] == 10 then
        if msgcontains(msg, '') then
            talk_state[cid] = 12
            sayText = ''
        elseif msgcontains(msg, '' then
            talk_state[cid] = 11
            sayText = ''
        elseif msgcontains(msg, 'crystal') then
            talk_state[cid] = 13
            sayText = ''
        end
    end
    if talk_state[cid] >= 11 and talk_state[cid] <= 13 then
        if talk_state[cid] == 11 and getCount(msg) > 0 then
            talk_state[cid] = 14
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 12 then
            if msgcontains(msg, '') then
                talk_state[cid] = 15
                sayText = ''
            elseif msgcontains(msg, '') then
                talk_state[cid] = 16
                sayText = ''
            end
        elseif talk_state[cid] == 13 and getCount(msg) > 0 then
            talk_state[cid] = 17
            last_count[cid] = getCount(msg)
            sayText = ''
        end
    end
    if talk_state[cid] >= 14 and talk_state[cid] <= 17 then
        if talk_state[cid] == 14 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, GOLD_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, GOLD_COIN, last_count[cid] * 100)
                    addCoin(cid, PLATINUM_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 15 and getCount(msg) > 0 then
            talk_state[cid] = 18
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 16 and getCount(msg) > 0 then
            talk_state[cid] = 19
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 17 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if getPlayerItemCount(cid, CRYSTAL_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, CRYSTAL_COIN, last_count[cid])
                    addCoin(cid, PLATINUM_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    if talk_state[cid] >= 18 and talk_state[cid] <= 19 then
        if talk_state[cid] == 18 and getCount(msg) <= 0 then
            if msgcontains(msg, '') then
                print(2)
                if getPlayerItemCount(cid, PLATINUM_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid])
                    addCoin(cid, GOLD_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 19 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, PLATINUM_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid] * 100)
                    addCoin(cid, CRYSTAL_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    --deposit
    if talk_state[cid] == 20 and getCount(msg) > 0 then
        talk_state[cid] = 21
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
        if getPlayerMoney(cid) <= 0 then
            talk_state[cid] = 0
            sayText = ''
        else
            talk_state[cid] = 21
            last_count[cid] = getPlayerMoney(cid)
            sayText = ''
        end
    elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    --withdraw
    if talk_state[cid] == 30 and getCount(msg) > 0 then
        talk_state[cid] = 31
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
            talk_state[cid] = 0
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    -- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer ~= 0 then
            last_name[cid] = toPlayer
            talk_state[cid] = 42
            sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. last_name[cid] .. '?'
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
            if doPlayerTransferMoneyTo(cid, last_name[cid], last_count[cid]) == TRUE then
                sayText = 'You have transferred ' .. last_count[cid] .. ' gold to ' .. last_name[cid] .. '.'
            else
                sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins on your bank account or player with name ' .. last_name[cid] .. ' doesn\'t exist. Money not transfered.'
                last_name[cid] = ""
            end
        else
            sayText = 'Ok. What is next?'
        end
        talk_state[cid] = 0
    end
    if sayText ~= "" then
        npcHandler:say(sayText, cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
try this, post possible errors:
PHP:
function getCount(msg)
    local ret = -1
    local b, e = string.find(msg, "%d+")
    if b ~= nil and e ~= nil then
      ret = tonumber(string.sub(msg, b, e))
    end
    if ret > 10000000 then
        return 10000000
    end
    return ret
end

function msgcontains(message, keyword)
    local a, b = string.find(message, keyword)
    if a == nil or b == nil then
        return false
    end
    return true
end

function addCoin(cid, itemid, count)
    if count > 100 then
        while(count > 100) do
            cash = doCreateItemEx(itemid, 100)
            doPlayerAddItemEx(cid, cash, 1)
            count = count - 100
        end
    end
    if count > 0 then
        cash = doCreateItemEx(itemid, count)
        doPlayerAddItemEx(cid, cash, 1)
    end
end

function doPlayerExist(name)
    local result = db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if (result:getID() ~= -1) then
        local return_name = result:getDataString("name")
        result:free()
        return return_name
    end
    return 0
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                            npcHandler:onThink()                        end

talk_state = {}
last_count = {}
last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end
    local sayText = ""
    if talk_state[cid] == nil then
        talk_state[cid] = 0
        last_count[cid] = 0
        last_name[cid] = ""
    end
    -- select action
    if msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 10
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 0
        local balance = getPlayerBalance(cid)
        if balance == 0 then
            sayText = ''
        else
            sayText = ''
        end
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 20
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 30
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 40
        sayText = ''
    end
    --  change
    if talk_state[cid] == 10 then
        if msgcontains(msg, '') then
            talk_state[cid] = 12
            sayText = ''
        elseif msgcontains(msg, '' then
            talk_state[cid] = 11
            sayText = ''
        elseif msgcontains(msg, 'crystal') then
            talk_state[cid] = 13
            sayText = ''
        end
    end
    if talk_state[cid] >= 11 and talk_state[cid] <= 13 then
        if talk_state[cid] == 11 and getCount(msg) > 0 then
            talk_state[cid] = 14
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 12 then
            if msgcontains(msg, '') then
                talk_state[cid] = 15
                sayText = ''
            elseif msgcontains(msg, '') then
                talk_state[cid] = 16
                sayText = ''
            end
        elseif talk_state[cid] == 13 and getCount(msg) > 0 then
            talk_state[cid] = 17
            last_count[cid] = getCount(msg)
            sayText = ''
        end
    end
    if talk_state[cid] >= 14 and talk_state[cid] <= 17 then
        if talk_state[cid] == 14 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, GOLD_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, GOLD_COIN, last_count[cid] * 100)
                    addCoin(cid, PLATINUM_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 15 and getCount(msg) > 0 then
            talk_state[cid] = 18
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 16 and getCount(msg) > 0 then
            talk_state[cid] = 19
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 17 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if getPlayerItemCount(cid, CRYSTAL_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, CRYSTAL_COIN, last_count[cid])
                    addCoin(cid, PLATINUM_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    if talk_state[cid] >= 18 and talk_state[cid] <= 19 then
        if talk_state[cid] == 18 and getCount(msg) <= 0 then
            if msgcontains(msg, '') then
                print(2)
                if getPlayerItemCount(cid, PLATINUM_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid])
                    addCoin(cid, GOLD_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 19 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, PLATINUM_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid] * 100)
                    addCoin(cid, CRYSTAL_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    --deposit
    if talk_state[cid] == 20 and getCount(msg) > 0 then
        talk_state[cid] = 21
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
        if getPlayerMoney(cid) <= 0 then
            talk_state[cid] = 0
            sayText = ''
        else
            talk_state[cid] = 21
            last_count[cid] = getPlayerMoney(cid)
            sayText = ''
        end
    elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    --withdraw
    if talk_state[cid] == 30 and getCount(msg) > 0 then
        talk_state[cid] = 31
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
            talk_state[cid] = 0
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    -- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer ~= 0 then
            last_name[cid] = toPlayer
            talk_state[cid] = 42
            sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. last_name[cid] .. '?'
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
            if doPlayerTransferMoneyTo(cid, last_name[cid], last_count[cid]) == TRUE then
                sayText = 'You have transferred ' .. last_count[cid] .. ' gold to ' .. last_name[cid] .. '.'
            else
                sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins on your bank account or player with name ' .. last_name[cid] .. ' doesn\'t exist. Money not transfered.'
                last_name[cid] = ""
            end
        else
            sayText = 'Ok. What is next?'
        end
        talk_state[cid] = 0
    end
    if sayText ~= "" then
        npcHandler:say(sayText, cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I assume you used my code for checking if player existed (the other code, not the npc one)
This script should work with that now.
I added vocation stuffs, again... and I found 1 misspell in your script, that made rest of it bug.
try this:
 
PHP:
function getCount(msg)
    local ret = -1
    local b, e = string.find(msg, "%d+")
    if b ~= nil and e ~= nil then
      ret = tonumber(string.sub(msg, b, e))
    end
    if ret > 10000000 then
        return 10000000
    end
    return ret
end

function msgcontains(message, keyword)
    local a, b = string.find(message, keyword)
    if a == nil or b == nil then
        return false
    end
    return true
end

function addCoin(cid, itemid, count)
    if count > 100 then
        while(count > 100) do
            cash = doCreateItemEx(itemid, 100)
            doPlayerAddItemEx(cid, cash, 1)
            count = count - 100
        end
    end
    if count > 0 then
        cash = doCreateItemEx(itemid, count)
        doPlayerAddItemEx(cid, cash, 1)
    end
end

function doPlayerExist(name)
    local result = db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if (result:getID() ~= -1) then
        local return_name = result:getDataString("name")
        result:free()
        return return_name
    end
    return 0
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                            npcHandler:onThink()                        end

talk_state = {}
last_count = {}
last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end
    local sayText = ""
    if talk_state[cid] == nil then
        talk_state[cid] = 0
        last_count[cid] = 0
        last_name[cid] = ""
    end
    -- select action
    if msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 10
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 0
        local balance = getPlayerBalance(cid)
        if balance == 0 then
            sayText = ''
        else
            sayText = ''
        end
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 20
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 30
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 40
        sayText = ''
    end
    --  change
    if talk_state[cid] == 10 then
        if msgcontains(msg, '') then
            talk_state[cid] = 12
            sayText = ''
        elseif msgcontains(msg, '') then
            talk_state[cid] = 11
            sayText = ''
        elseif msgcontains(msg, 'crystal') then
            talk_state[cid] = 13
            sayText = ''
        end
    end
    if talk_state[cid] >= 11 and talk_state[cid] <= 13 then
        if talk_state[cid] == 11 and getCount(msg) > 0 then
            talk_state[cid] = 14
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 12 then
            if msgcontains(msg, '') then
                talk_state[cid] = 15
                sayText = ''
            elseif msgcontains(msg, '') then
                talk_state[cid] = 16
                sayText = ''
            end
        elseif talk_state[cid] == 13 and getCount(msg) > 0 then
            talk_state[cid] = 17
            last_count[cid] = getCount(msg)
            sayText = ''
        end
    end
    if talk_state[cid] >= 14 and talk_state[cid] <= 17 then
        if talk_state[cid] == 14 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, GOLD_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, GOLD_COIN, last_count[cid] * 100)
                    addCoin(cid, PLATINUM_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 15 and getCount(msg) > 0 then
            talk_state[cid] = 18
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 16 and getCount(msg) > 0 then
            talk_state[cid] = 19
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 17 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if getPlayerItemCount(cid, CRYSTAL_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, CRYSTAL_COIN, last_count[cid])
                    addCoin(cid, PLATINUM_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    if talk_state[cid] >= 18 and talk_state[cid] <= 19 then
        if talk_state[cid] == 18 and getCount(msg) <= 0 then
            if msgcontains(msg, '') then
                print(2)
                if getPlayerItemCount(cid, PLATINUM_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid])
                    addCoin(cid, GOLD_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 19 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, PLATINUM_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid] * 100)
                    addCoin(cid, CRYSTAL_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    --deposit
    if talk_state[cid] == 20 and getCount(msg) > 0 then
        talk_state[cid] = 21
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
        if getPlayerMoney(cid) <= 0 then
            talk_state[cid] = 0
            sayText = ''
        else
            talk_state[cid] = 21
            last_count[cid] = getPlayerMoney(cid)
            sayText = ''
        end
    elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    --withdraw
    if talk_state[cid] == 30 and getCount(msg) > 0 then
        talk_state[cid] = 31
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
            talk_state[cid] = 0
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    -- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer > 0 then
            player_cid = getPlayerByName(toPlayer)
            if getPlayerVocation(player_cid) > 0 then
                player_name = getPlayerName(player_cid)
                talk_state[cid] = 42
                sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. player_name .. '?'
            else
                talk_state[cid] = 0
                sayText = 'You cannot send money to rookgaard.'        
            end
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
            if doPlayerTransferMoneyTo(cid, last_name[cid], last_count[cid]) == TRUE then
                sayText = 'You have transferred ' .. last_count[cid] .. ' gold to ' .. last_name[cid] .. '.'
            else
                sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins on your bank account or player with name ' .. last_name[cid] .. ' doesn\'t exist. Money not transfered.'
                last_name[cid] = ""
            end
        else
            sayText = 'Ok. What is next?'
        end
        talk_state[cid] = 0
    end
        if sayText ~= "" then
            npcHandler:say(sayText, cid)
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I checked a little more carefully now.. you haven't added anything of that I've posted earlier, no wonder it wont work then..
you were supposed to change doplayerexist from using queries to use guid instead as it's smoother..

here's the code after I added the things you should have added yesterday:
(next post because can't write posts with more than 1000 chars)

PHP:
function getCount(msg)
    local ret = -1
    local b, e = string.find(msg, "%d+")
    if b ~= nil and e ~= nil then
      ret = tonumber(string.sub(msg, b, e))
    end
    if ret > 10000000 then
        return 10000000
    end
    return ret
end

function msgcontains(message, keyword)
    local a, b = string.find(message, keyword)
    if a == nil or b == nil then
        return false
    end
    return true
end

function addCoin(cid, itemid, count)
    if count > 100 then
        while(count > 100) do
            cash = doCreateItemEx(itemid, 100)
            doPlayerAddItemEx(cid, cash, 1)
            count = count - 100
        end
    end
    if count > 0 then
        cash = doCreateItemEx(itemid, count)
        doPlayerAddItemEx(cid, cash, 1)
    end
end

function doPlayerExist(name)
    player = getPlayerGUIDByName(name)
    if player > 0 then
        return player
    else
        return 0
    end
end

GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                            npcHandler:onThink()                        end

talk_state = {}
last_count = {}
last_name = {}
function creatureSayCallback(cid, type, msg)
    orginal_msg = msg
    msg = string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        talk_state[cid] = 0
        return false
    end
    local sayText = ""
    if talk_state[cid] == nil then
        talk_state[cid] = 0
        last_count[cid] = 0
        last_name[cid] = ""
    end
    -- select action
    if msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 10
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 0
        local balance = getPlayerBalance(cid)
        if balance == 0 then
            sayText = ''
        else
            sayText = ''
        end
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 20
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 30
        sayText = ''
    elseif msgcontains(msg, '') and talk_state[cid] ~= 41 then
        talk_state[cid] = 40
        sayText = ''
    end
    --  change
    if talk_state[cid] == 10 then
        if msgcontains(msg, '') then
            talk_state[cid] = 12
            sayText = ''
        elseif msgcontains(msg, '') then
            talk_state[cid] = 11
            sayText = ''
        elseif msgcontains(msg, 'crystal') then
            talk_state[cid] = 13
            sayText = ''
        end
    end
    if talk_state[cid] >= 11 and talk_state[cid] <= 13 then
        if talk_state[cid] == 11 and getCount(msg) > 0 then
            talk_state[cid] = 14
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 12 then
            if msgcontains(msg, '') then
                talk_state[cid] = 15
                sayText = ''
            elseif msgcontains(msg, '') then
                talk_state[cid] = 16
                sayText = ''
            end
        elseif talk_state[cid] == 13 and getCount(msg) > 0 then
            talk_state[cid] = 17
            last_count[cid] = getCount(msg)
            sayText = ''
        end
    end
    if talk_state[cid] >= 14 and talk_state[cid] <= 17 then
        if talk_state[cid] == 14 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, GOLD_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, GOLD_COIN, last_count[cid] * 100)
                    addCoin(cid, PLATINUM_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 15 and getCount(msg) > 0 then
            talk_state[cid] = 18
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 16 and getCount(msg) > 0 then
            talk_state[cid] = 19
            last_count[cid] = getCount(msg)
            sayText = ''
        elseif talk_state[cid] == 17 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if getPlayerItemCount(cid, CRYSTAL_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, CRYSTAL_COIN, last_count[cid])
                    addCoin(cid, PLATINUM_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    if talk_state[cid] >= 18 and talk_state[cid] <= 19 then
        if talk_state[cid] == 18 and getCount(msg) <= 0 then
            if msgcontains(msg, '') then
                print(2)
                if getPlayerItemCount(cid, PLATINUM_COIN) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid])
                    addCoin(cid, GOLD_COIN, last_count[cid] * 100)
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 19 and getCount(msg) <= 0 then
            if msgcontains(msg, 'yes') then
                if math.floor(getPlayerItemCount(cid, PLATINUM_COIN) / 100) >= last_count[cid] then
                    doPlayerRemoveItem(cid, PLATINUM_COIN, last_count[cid] * 100)
                    addCoin(cid, CRYSTAL_COIN, last_count[cid])
                    sayText = ''
                else
                    sayText = ''
                end
            else
                sayText = ''
            end
            talk_state[cid] = 0
        end
    end
    --deposit
    if talk_state[cid] == 20 and getCount(msg) > 0 then
        talk_state[cid] = 21
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
        if getPlayerMoney(cid) <= 0 then
            talk_state[cid] = 0
            sayText = ''
        else
            talk_state[cid] = 21
            last_count[cid] = getPlayerMoney(cid)
            sayText = ''
        end
    elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    --withdraw
    if talk_state[cid] == 30 and getCount(msg) > 0 then
        talk_state[cid] = 31
        last_count[cid] = getCount(msg)
        sayText = ''
    elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
        if msgcontains(msg, '') then
            if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
                sayText = ''
            else
                sayText = ''
            end
            talk_state[cid] = 0
        else
            sayText = ''
        end
        talk_state[cid] = 0
    end
    -- transfer
    if talk_state[cid] == 40 and getCount(msg) > 0 then
        if getPlayerBalance(cid) >= getCount(msg) then
            talk_state[cid] = 41
            last_count[cid] = getCount(msg)
            sayText = 'Who would you like transfer ' .. last_count[cid] .. ' gold to?'
        else
            talk_state[cid] = 0
            sayText = 'There is not enough gold on your account.'
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer > 0 then
            player_cid = getPlayerByName(toPlayer)
            if getPlayerVocation(player_cid) > 0 then
                player_name = getPlayerName(player_cid)
                talk_state[cid] = 42
                sayText = 'So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. player_name .. '?'
            else
                talk_state[cid] = 0
                sayText = 'You cannot send money to rookgaard.'       
            end
        else
            talk_state[cid] = 0
            sayText = 'This player does not exist.'
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
            if doPlayerTransferMoneyTo(cid, last_name[cid], last_count[cid]) == TRUE then
                sayText = 'You have transferred ' .. last_count[cid] .. ' gold to ' .. last_name[cid] .. '.'
            else
                sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins on your bank account or player with name ' .. last_name[cid] .. ' doesn\'t exist. Money not transfered.'
                last_name[cid] = ""
            end
        else
            sayText = 'Ok. What is next?'
        end
        talk_state[cid] = 0
    end
        if sayText ~= "" then
            npcHandler:say(sayText, cid)
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Back
Top