• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Bank NPC for TFS 0.3beta

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,979
Solutions
100
Reaction score
3,423
Location
Poland
GitHub
gesior
Bank NPC for TFS 0.3.x

IN CONFIG.LUA OF OTS SET!!!
PHP:
bankSystem = "yes"
-----------------------------------------
New bank NPC for TFS 0.3
- change gold, platinum, crystal
16:59 Bank: Greetings Qwert. I'm banker.
16:59 Qwert [151]: change gold 2
16:59 Bank: So I should change 200 of your gold coins to 2 platinum coins for you?
16:59 Qwert [151]: yes
16:59 Bank: Here you are.
or:
17:00 Qwert [151]: change
17:00 Bank: We exchange gold, platinum and crystal coins.
17:00 Qwert [151]: gold
17:00 Bank: How many platinum coins do you want to get?
17:00 Qwert [151]: 2
17:00 Bank: So I should change 200 of your gold coins to 2 platinum coins for you?
17:00 Qwert [151]: yes
17:00 Bank: Here you are.
- deposit / deposit all
17:04 Qwert [151]: deposit
17:04 Bank: How much gold you would like to deposit?
17:04 Qwert [151]: 50
17:04 Bank: Would you really like to deposit 50 gold coins?
17:04 Qwert [151]: yes
17:04 Bank: You deposited 50 gold coins. Now your account balance is 9700 gold coins.
or:
17:04 Qwert [151]: deposit 50
17:04 Bank: Would you really like to deposit 50 gold coins?
17:04 Qwert [151]: yes
17:04 Bank: You deposited 50 gold coins. Now your account balance is 9750 gold coins.
or:
17:04 Qwert [151]: deposit all
17:04 Bank: Would you really like to deposit your all money, 21500 gold coins?
17:04 Qwert [151]: yes
17:04 Bank: You deposited 21500 gold coins. Now your account balance is 31250 gold coins.
- withdraw / withdraw all - use like deposit
- balance
- transfer
17:08 Qwert [151]: transfer
17:08 Bank: How much gold you would like to transfer?
17:08 Qwert [151]: 50
17:08 Bank: To who would you like transfer 50 gold coins from your account? Tell me his or her name.
17:08 Qwert [151]: omger
17:08 Bank: So you would like to transfer 50 gold coins to Omger?
17:08 Qwert [151]: yes
17:08 Bank: You have transfered 50 gold coins to bank account of player Omger. Now your account balance is 31200.
or:
17:08 Qwert [151]: transfer 500
17:08 Bank: To who would you like transfer 500 gold coins from your account? Tell me his or her name.
17:08 Qwert [151]: omger
17:08 Bank: So you would like to transfer 500 gold coins to Omger?
17:08 Qwert [151]: yes
17:08 Bank: You have transfered 500 gold coins to bank account of player Omger. Now your account balance is 30700.
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Bank" script="data/npc/scripts/bank.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="78" body="88" legs="0" feet="88" addons="3"/>
</npc>
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)
	talk_state[cid] = 0
	npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()                             npcHandler:onThink()                         end

npcHandler:setMessage(MESSAGE_GREET, "Greetings |PLAYERNAME|. I'm banker.")

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, 'change') and talk_state[cid] ~= 41 then
		talk_state[cid] = 10
		sayText = 'We exchange gold, platinum and crystal coins.'
	elseif msgcontains(msg, 'balance') and talk_state[cid] ~= 41 then
		talk_state[cid] = 0
		local balance = getPlayerBalance(cid)
		if balance == 0 then
			sayText = 'Your bank account is empty.'
		elseif balance <= 100000 then
			sayText = 'Your account balance is ' .. balance .. ' gold coins.'
		elseif balance <= 1000000 then
			sayText = 'Your account balance is ' .. balance .. ' gold coins.'
		else 
			sayText = 'Your account balance is ' .. balance .. ' gold coins.'
		end
	elseif msgcontains(msg, 'deposit') and talk_state[cid] ~= 41 then
		talk_state[cid] = 20
		sayText = 'How much gold you would like to deposit?'
	elseif msgcontains(msg, 'withdraw') and talk_state[cid] ~= 41 then
		talk_state[cid] = 30
		sayText = 'How much gold you would like to withdraw?'
	elseif msgcontains(msg, 'transfer') and talk_state[cid] ~= 41 then
		talk_state[cid] = 40
		sayText = 'How much gold you would like to transfer?'
	end
	--  change
	if talk_state[cid] == 10 then
		if msgcontains(msg, 'platinum') then
			talk_state[cid] = 12
			sayText = 'Do you want to change your platinum coins to gold or crystal?'
		elseif msgcontains(msg, 'gold') then
			talk_state[cid] = 11
			sayText = 'How many platinum coins do you want to get?'
		elseif msgcontains(msg, 'crystal') then
			talk_state[cid] = 13
			sayText = 'How many crystal coins do you want to change to platinum?'
		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 = 'So I should change ' .. getCount(msg) * 100 .. ' of your gold coins to ' .. getCount(msg) .. ' platinum coins for you?'
		elseif talk_state[cid] == 12 then
			if msgcontains(msg, 'gold') then
				talk_state[cid] = 15
				sayText = 'How many platinum coins do you want to change to gold?'
			elseif msgcontains(msg, 'crystal') then
				talk_state[cid] = 16
				sayText = 'How many crystal coins do you want to get?'
			end
		elseif talk_state[cid] == 13 and getCount(msg) > 0 then
			talk_state[cid] = 17
			last_count[cid] = getCount(msg)
			sayText = 'So I should change ' .. getCount(msg) .. ' of your crystal coins to ' .. getCount(msg)*100 .. ' platinum coins for you?'
		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 = 'Here you are.'
				else
					sayText = 'You don\'t have ' .. last_count[cid] * 100 .. ' gold coins.'
				end
			else
				sayText = 'Well, can I help you with something else?'
			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 = 'So I should change ' .. getCount(msg) .. ' of your platinum coins to ' .. getCount(msg) * 100 .. ' gold coins for you?'
		elseif talk_state[cid] == 16 and getCount(msg) > 0 then
			talk_state[cid] = 19
			last_count[cid] = getCount(msg)
			sayText = 'So I should change ' .. getCount(msg) * 100 .. ' of your platinum coins to ' .. getCount(msg) .. ' crystal coins for you?'
		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 = 'Here you are.'
				else
					sayText = 'You don\'t have ' .. last_count[cid] .. ' crystal coins.'
				end
			else
				sayText = 'Well, can I help you with something else?'
			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, 'yes') 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 = 'Here you are.'
				else
					sayText = 'You don\'t have ' .. last_count[cid] .. ' platinum coins.'
				end
			else
				sayText = 'Well, can I help you with something else?'
			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 = 'Here you are.'
				else
					sayText = 'You don\'t have ' .. last_count[cid] * 100 .. ' platinum coins.'
				end
			else
				sayText = 'Well, can I help you with something else?'
			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 = 'Would you really like to deposit ' .. last_count[cid] .. ' gold coins?'
	elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
		if getPlayerMoney(cid) <= 0 then
			talk_state[cid] = 0
			sayText = 'You don\'t have any money.'
		else
			talk_state[cid] = 21
			last_count[cid] = getPlayerMoney(cid)
			sayText = 'Would you really like to deposit your all money, ' .. last_count[cid] .. ' gold coins?'
		end
	elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
		if msgcontains(msg, 'yes') then
			if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
				sayText = 'You deposited ' .. last_count[cid] .. ' gold coins. Now your account balance is ' .. getPlayerBalance(cid) .. ' gold coins.'
			else
				sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins.'
			end
		else
			sayText = 'Well, can I help you with something else?'
		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 = 'Would you really like to withdraw ' .. last_count[cid] .. ' gold coins?'
	elseif talk_state[cid] == 30 and msgcontains(msg, 'all') then
			talk_state[cid] = 31
			last_count[cid] = getPlayerBalance(cid)
			sayText = 'Would you really like to withdraw your all money, ' .. last_count[cid] .. ' gold coins?'
	elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
		if msgcontains(msg, 'yes') then
			if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
				sayText = 'You withdrawed ' .. last_count[cid] .. ' gold coins. Now your account balance is ' .. getPlayerBalance(cid) .. ' gold coins.'
			else
				sayText = 'You don\'t have ' .. last_count[cid] .. ' gold coins on your account. You account balance is ' .. getPlayerBalance(cid) .. '.'
			end
			talk_state[cid] = 0
		else
			sayText = 'Well, can I help you with something else?'
		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 = 'To who would you like transfer ' .. last_count[cid] .. ' gold coins from your account? Tell me his or her name.'
		else
			talk_state[cid] = 0
			sayText = 'You don\'t have ' .. getCount(msg) .. ' gold coins 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 = 'I don\'t know player with name ' .. orginal_msg .. '.'
		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 transfered ' .. last_count[cid] .. ' gold coins to bank account of player ' .. last_name[cid] .. '. Now your account balance is ' .. getPlayerBalance(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 = 'Well, can I help you with something else?'
		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())
FIXED CLONE CASH BUG! MAX. deposit/withdraw 10,000,000

Fixed bug with npc say texts.
 
Last edited:
Code:
GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160
It's already included to distributions.

Code:
  elseif balance <= 100000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
        elseif balance <= 1000000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
Why it's doubled?
 
Code:
GOLD_COIN = 2148
PLATINUM_COIN = 2152
CRYSTAL_COIN = 2160
It's already included to distributions.

Code:
  elseif balance <= 100,000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
        elseif balance <= 1,000,000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
Why it's doubled?

Added , and you'll see better
 
Bug:
dibujopm4.png


How to fix this? :S
 
Rizz I changed what you said and now:

27481141cd9.jpg

Try to use this

PHP:
local talk_state = {}

local 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
 
    return ret
end

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

local 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

local 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

npcHandler:setMessage(MESSAGE_GREET, "Greetings |PLAYERNAME|. I'm banker.")

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
    if talk_state[cid] == nil then
        talk_state[cid] = 0
        last_count[cid] = 0
        last_name[cid] = ""
    end
    -- select action
    if msgcontains(msg, 'change') and talk_state[cid] ~= 41 then
        talk_state[cid] = 10
        npcHandler:say('We exchange gold, platinum and crystal coins.', cid)
    elseif msgcontains(msg, 'balance') and talk_state[cid] ~= 41 then
        talk_state[cid] = 0
        local balance = getPlayerBalance(cid)
        if balance == 0 then
            npcHandler:say('Your bank account is empty.', cid)
        elseif balance <= 100000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
        elseif balance <= 1000000 then
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
        else 
            npcHandler:say('Your account balance is ' .. balance .. ' gold coins.', cid)
        end
    elseif msgcontains(msg, 'deposit') and talk_state[cid] ~= 41 then
        talk_state[cid] = 20
        npcHandler:say('How much gold you would like to deposit?', cid)
    elseif msgcontains(msg, 'withdraw') and talk_state[cid] ~= 41 then
        talk_state[cid] = 30
        npcHandler:say('How much gold you would like to withdraw?', cid)
    elseif msgcontains(msg, 'transfer') and talk_state[cid] ~= 41 then
        talk_state[cid] = 40
        npcHandler:say('How much gold you would like to transfer?', cid)
    end
    --  change
    if talk_state[cid] == 10 then
        if msgcontains(msg, 'platinum') then
            talk_state[cid] = 12
            npcHandler:say('Do you want to change your platinum coins to gold or crystal?', cid)
        elseif msgcontains(msg, 'gold') then
            talk_state[cid] = 11
            npcHandler:say('How many platinum coins do you want to get?', cid)
        elseif msgcontains(msg, 'crystal') then
            talk_state[cid] = 13
            npcHandler:say('How many crystal coins do you want to change to platinum?', cid)
        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)
            npcHandler:say('So I should change ' .. getCount(msg) * 100 .. ' of your gold coins to ' .. getCount(msg) .. ' platinum coins for you?', cid)
        elseif talk_state[cid] == 12 then
            if msgcontains(msg, 'gold') then
                talk_state[cid] = 15
                npcHandler:say('How many platinum coins do you want to change to gold?', cid)
            elseif msgcontains(msg, 'crystal') then
                talk_state[cid] = 16
                npcHandler:say('How many crystal coins do you want to get?', cid)
            end
        elseif talk_state[cid] == 13 and getCount(msg) > 0 then
            talk_state[cid] = 17
            last_count[cid] = getCount(msg)
            npcHandler:say('So I should change ' .. getCount(msg) .. ' of your crystal coins to ' .. getCount(msg)*100 .. ' platinum coins for you?', cid)
        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])
                    npcHandler:say('Here you are.', cid)
                else
                    npcHandler:say('You don\'t have ' .. last_count[cid] * 100 .. ' gold coins.', cid)
                end
            else
                npcHandler:say('Well, can I help you with something else?', cid)
            end
            talk_state[cid] = 0
        elseif talk_state[cid] == 15 and getCount(msg) > 0 then
            talk_state[cid] = 18
            last_count[cid] = getCount(msg)
            npcHandler:say('So I should change ' .. getCount(msg) .. ' of your platinum coins to ' .. getCount(msg) * 100 .. ' gold coins for you?', cid)
        elseif talk_state[cid] == 16 and getCount(msg) > 0 then
            talk_state[cid] = 19
            last_count[cid] = getCount(msg)
            npcHandler:say('So I should change ' .. getCount(msg) * 100 .. ' of your platinum coins to ' .. getCount(msg) .. ' crystal coins for you?', cid)
        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)
                    npcHandler:say('Here you are.', cid)
                else
                    npcHandler:say('You don\'t have ' .. last_count[cid] .. ' crystal coins.', cid)
                end
            else
                npcHandler:say('Well, can I help you with something else?', cid)
            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, 'yes') 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)
                    npcHandler:say('Here you are.', cid)
                else
                    npcHandler:say('You don\'t have ' .. last_count[cid] .. ' platinum coins.', cid)
                end
            else
                npcHandler:say('Well, can I help you with something else?', cid)
            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])
                    npcHandler:say('Here you are.', cid)
                else
                    npcHandler:say('You don\'t have ' .. last_count[cid] * 100 .. ' platinum coins.', cid)
                end
            else
                npcHandler:say('Well, can I help you with something else?', cid)
            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)
        npcHandler:say('Would you really like to deposit ' .. last_count[cid] .. ' gold coins?', cid)
    elseif talk_state[cid] == 20 and msgcontains(msg, 'all') then
        if getPlayerMoney(cid) <= 0 then
            talk_state[cid] = 0
            npcHandler:say('You don\'t have any money.', cid)
        else
            talk_state[cid] = 21
            last_count[cid] = getPlayerMoney(cid)
            npcHandler:say('Would you really like to deposit your all money, ' .. last_count[cid] .. ' gold coins?', cid)
        end
    elseif talk_state[cid] == 21 and getCount(msg) <= 0 then
        if msgcontains(msg, 'yes') then
            if doPlayerDepositMoney(cid, last_count[cid]) == TRUE then
                npcHandler:say('You deposited ' .. last_count[cid] .. ' gold coins. Now your account balance is ' .. getPlayerBalance(cid) .. ' gold coins.', cid)
            else
                npcHandler:say('You don\'t have ' .. last_count[cid] .. ' gold coins.', cid)
            end
        else
            npcHandler:say('Well, can I help you with something else?', cid)
        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)
        npcHandler:say('Would you really like to withdraw ' .. last_count[cid] .. ' gold coins?', cid)
    elseif talk_state[cid] == 30 and msgcontains(msg, 'all') then
            talk_state[cid] = 31
            last_count[cid] = getPlayerBalance(cid)
            npcHandler:say('Would you really like to withdraw your all money, ' .. last_count[cid] .. ' gold coins?', cid)
    elseif talk_state[cid] == 31 and getCount(msg) <= 0 then
        if msgcontains(msg, 'yes') then
            if doPlayerWithdrawMoney(cid, last_count[cid]) == TRUE then
                npcHandler:say('You withdrawed ' .. last_count[cid] .. ' gold coins. Now your account balance is ' .. getPlayerBalance(cid) .. ' gold coins.', cid)
            else
                npcHandler:say('You don\'t have ' .. last_count[cid] .. ' gold coins on your account. You account balance is ' .. getPlayerBalance(cid) .. '.', cid)
            end
            talk_state[cid] = 0
        else
            npcHandler:say('Well, can I help you with something else?', cid)
        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)
            npcHandler:say('To who would you like transfer ' .. last_count[cid] .. ' gold coins from your account? Tell me his or her name.', cid)
        else
            talk_state[cid] = 0
            npcHandler:say('You don\'t have ' .. getCount(msg) .. ' gold coins on your account.', cid)
        end
    elseif talk_state[cid] == 41 then
        local toPlayer = doPlayerExist(msg)
        if toPlayer ~= 0 then
            last_name[cid] = toPlayer
            talk_state[cid] = 42
            npcHandler:say('So you would like to transfer ' .. last_count[cid] .. ' gold coins to ' .. last_name[cid] .. '?', cid)
        else
            talk_state[cid] = 0
            npcHandler:say('I don\'t know player with name ' .. orginal_msg .. '.', cid)
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
            if doPlayerTransferMoneyTo(cid, last_name[cid], last_count[cid]) == TRUE then
                npcHandler:say('You have transfered ' .. last_count[cid] .. ' gold coins to bank account of player ' .. last_name[cid] .. '. Now your account balance is ' .. getPlayerBalance(cid) .. '.', cid)
            else
                npcHandler:say('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.', cid)
                last_name[cid] = ""
            end
        else
            npcHandler:say('Well, can I help you with something else?', cid)
        end
        talk_state[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hello

I am using

The Forgotten Server, version 0.3 (Beta 2)

and the npc works fine for me but when i try to transfer money to other player it just tell me

21:30 Durango: I don't know player with name Testo.

I am using sqlite db

Rep+ for you gesior and Rep for who solve my problem or try to solve :D Respect to all the nice users of this forum
 
Last edited:
Back
Top