• 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 SOLVED Banker won't work =S

Vikarious

New Member
Joined
Dec 16, 2008
Messages
93
Reaction score
2
Hello there!

I'm having a strange issue with my bank npc, I'm using this script:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic, count, transfer = {}, {}, {}
 
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 function getCount(s)
	local b, e = s:find('%d+')
	return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
end
 
local function findPlayer(name)
	local q = db.getResult('SELECT name FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil
	if q:getID() == -1 then
		return
	end
	local r = q:getDataString('name')
	q:free()
	return r
end
 
function greet(cid)
	Topic[cid], count[cid], transfer[cid] = nil, nil, nil
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'balance') then
		npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
		Topic[cid] = nil
	elseif msgcontains(msg, 'deposit') and msgcontains(msg, 'all') then
		if getPlayerMoney(cid) == 0 then
			npcHandler:say('You don\'t have any gold with you.', cid)
			Topic[cid] = nil
		else
			count[cid] = getPlayerMoney(cid)
			npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
			Topic[cid] = 2
		end
	elseif msgcontains(msg, 'deposit') then
		if getCount(msg) == 0 then
			npcHandler:say('You are joking, aren\'t you??', cid)
			Topic[cid] = nil
		elseif getCount(msg) ~= -1 then
			if getPlayerMoney(cid) >= getCount(msg) then
				count[cid] = getCount(msg)
				npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
				Topic[cid] = 2
			else
				npcHandler:say('You do not have enough gold.', cid)
				Topic[cid] = nil
			end
		elseif getPlayerMoney(cid) == 0 then
			npcHandler:say('You don\'t have any gold with you.', cid)
			Topic[cid] = nil
		else
			npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
			Topic[cid] = 1
		end
	elseif Topic[cid] == 1 then
		if getCount(msg) == -1 then
			npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
			Topic[cid] = 1
		elseif getPlayerMoney(cid) >= getCount(msg) then
			count[cid] = getCount(msg)
			npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
			Topic[cid] = 2
		else
			npcHandler:say('You do not have enough gold.', cid)
			Topic[cid] = nil
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
		if doPlayerRemoveMoney(cid, count[cid]) then
			doPlayerSetBalance(cid, getPlayerBalance(cid) + count[cid])
			npcHandler:say('Alright, we have added the amount of ' .. count[cid] .. ' gold to your balance. You can withdraw your money anytime you want to.', cid)
		else
			npcHandler:say('I am inconsolable, but it seems you have lost your gold. I hope you get it back.', cid)
		end
		Topic[cid] = nil
	elseif msgcontains(msg, 'no') and Topic[cid] == 2 then
		npcHandler:say('As you wish. Is there something else I can do for you?', cid)
		Topic[cid] = nil
	elseif msgcontains(msg, 'withdraw') then
		if getCount(msg) == 0 then
			npcHandler:say('Sure, you want nothing you get nothing!', cid)
			Topic[cid] = nil
		elseif getCount(msg) ~= -1 then
			if getPlayerBalance(cid) >= getCount(msg) then
				count[cid] = getCount(msg)
				npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
				Topic[cid] = 4
			else
				npcHandler:say('There is not enough gold on your account.', cid)
				Topic[cid] = nil
			end
		elseif getPlayerBalance(cid) == 0 then
			npcHandler:say('You don\'t have any money on your bank account.', cid)
			Topic[cid] = nil
		else
			npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
			Topic[cid] = 3
		end
	elseif Topic[cid] == 3 then
		if getCount(msg) == -1 then
			npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
			Topic[cid] = 3
		elseif getPlayerBalance(cid) >= getCount(msg) then
			count[cid] = getCount(msg)
			npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
			Topic[cid] = 4
		else
			npcHandler:say('There is not enough gold on your account.', cid)
			Topic[cid] = nil
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 4 then
		if getPlayerBalance(cid) >= count[cid] then
			doPlayerAddMoney(cid, count[cid])
			doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
			npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
		else
			npcHandler:say('There is not enough gold on your account.', cid)
		end
		Topic[cid] = nil
	elseif msgcontains(msg, 'no') and Topic[cid] == 4 then
		npcHandler:say('The customer is king! Come back anytime you want to if you wish to withdraw your money.', cid)
		Topic[cid] = nil
	elseif msgcontains(msg, 'transfer') then
		if getCount(msg) == 0 then
			npcHandler:say('Please think about it. Okay?', cid)
			Topic[cid] = nil
		elseif getCount(msg) ~= -1 then
			count[cid] = getCount(msg)
			if getPlayerBalance(cid) >= count[cid] then
				npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
				Topic[cid] = 6
			else
				npcHandler:say('There is not enough gold on your account.', cid)
				Topic[cid] = nil
			end
		else
			npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
			Topic[cid] = 5
		end
	elseif Topic[cid] == 5 then
		if getCount(msg) == -1 then
			npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
			Topic[cid] = 5
		else
			count[cid] = getCount(msg)
			if getPlayerBalance(cid) >= count[cid] then
				npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
				Topic[cid] = 6
			else
				npcHandler:say('There is not enough gold on your account.', cid)
				Topic[cid] = nil
			end
		end
	elseif Topic[cid] == 6 then
		local v = getPlayerByName(msg)
		if getPlayerBalance(cid) >= count[cid] then
			if v then
				transfer[cid] = msg
				npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. getPlayerName(v) .. '?', cid)
				Topic[cid] = 7
			elseif findPlayer(msg):lower() == msg:lower() then
				transfer[cid] = msg
				npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. findPlayer(msg) .. '?', cid)
				Topic[cid] = 7
			else
				npcHandler:say('This player does not exist.', cid)
				Topic[cid] = nil
			end
		else
			npcHandler:say('There is not enough gold on your account.', cid)
			Topic[cid] = nil
		end
	elseif Topic[cid] == 7 and msgcontains(msg, 'yes') then
		if getPlayerBalance(cid) >= count[cid] then
			local v = getPlayerByName(transfer[cid])
			if v then
				doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
				doPlayerSetBalance(v, getPlayerBalance(v) + count[cid])
				npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. getPlayerName(v) .. '.', cid)
			elseif findPlayer(transfer[cid]):lower() == transfer[cid]:lower() then
				doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
				db.executeQuery('UPDATE players SET balance=balance+' .. count[cid] .. ' WHERE name=' .. db.escapeString(transfer[cid]) .. ' LIMIT 1')
				npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. findPlayer(transfer[cid]) .. '.', cid)
			else
				npcHandler:say('This player does not exist.', cid)
			end
		else
			npcHandler:say('There is not enough gold on your account.', cid)
		end
		Topic[cid] = nil
	elseif Topic[cid] == 7 and msgcontains(msg, 'no') then
		npcHandler:say('Alright, is there something else I can do for you?', cid)
		Topic[cid] = nil
	elseif msgcontains(msg, 'change gold') then
		npcHandler:say('How many platinum coins would you like to get?', cid)
		Topic[cid] = 8
	elseif Topic[cid] == 8 then
		if getCount(msg) < 1 then
			npcHandler:say('Hmm, can I help you with something else?', cid)
			Topic[cid] = nil
		else
			count[cid] = math.min(500, getCount(msg))
			npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
			Topic[cid] = 9
		end
	elseif Topic[cid] == 9 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 2148, count[cid] * 100) then
				npcHandler:say('Here you are.', cid)
				doPlayerAddItem(cid, 2152, count[cid])
			else
				npcHandler:say('Sorry, you do not have enough gold coins.', cid)
			end
		else
			npcHandler:say('Well, can I help you with something else?', cid)
		end
		Topic[cid] = nil
	elseif msgcontains(msg, 'change platinum') then
		npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
		Topic[cid] = 10
	elseif Topic[cid] == 10 then
		if msgcontains(msg, 'gold') then
			npcHandler:say('How many platinum coins would you like to change into gold?', cid)
			Topic[cid] = 11
		elseif msgcontains(msg, 'crystal') then
			npcHandler:say('How many crystal coins would you like to get?', cid)
			Topic[cid] = 13
		else
			npcHandler:say('Well, can I help you with something else?', cid)
			Topic[cid] = nil
		end
	elseif Topic[cid] == 11 then
		if getCount(msg) < 1 then
			npcHandler:say('Hmm, can I help you with something else?', cid)
			Topic[cid] = nil
		else
			count[cid] = math.min(500, getCount(msg))
			npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
			Topic[cid] = 12
		end
	elseif Topic[cid] == 12 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 2152, count[cid]) then
				npcHandler:say('Here you are.', cid)
				doPlayerAddItem(cid, 2148, count[cid] * 100)
			else
				npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
			end
		else
			npcHandler:say('Well, can I help you with something else?', cid)
		end
		Topic[cid] = nil
	elseif Topic[cid] == 13 then
		if getCount(msg) < 1 then
			npcHandler:say('Hmm, can I help you with something else?', cid)
			Topic[cid] = nil
		else
			count[cid] = math.min(500, getCount(msg))
			npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
			Topic[cid] = 14
		end
	elseif Topic[cid] == 14 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 2152, count[cid] * 100) then
				npcHandler:say('Here you are.', cid)
				doPlayerAddItem(cid, 2160, count[cid])
			else
				npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
			end
		else
			npcHandler:say('Well, can I help you with something else?', cid)
		end
		Topic[cid] = nil
	elseif msgcontains(msg, 'change crystal') then
		npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
		Topic[cid] = 15
	elseif Topic[cid] == 15 then
		if getCount(msg) == -1 or getCount(msg) == 0 then
			npcHandler:say('Hmm, can I help you with something else?', cid)
			Topic[cid] = nil
		else
			count[cid] = math.min(500, getCount(msg))
			npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
			Topic[cid] = 16
		end
	elseif Topic[cid] == 16 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 2160, count[cid]) then
				npcHandler:say('Here you are.', cid)
				doPlayerAddItem(cid, 2152, count[cid] * 100)
			else
				npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
			end
		else
			npcHandler:say('Well, can I help you with something else?', cid)
		end
		Topic[cid] = nil
	elseif msgcontains(msg, 'change') then
		npcHandler:say('There are three different coin types in Tibia: 100 gold coins equal 1 platinum coin, 100 platinum coins equal 1 crystal coin. So if you\'d like to change 100 gold into 1 platinum, simply say \'{change gold}\' and then \'1 platinum\'.', cid)
		Topic[cid] = nil
	elseif msgcontains(msg, 'bank') then
		npcHandler:say('We can change money for you. You can also access your bank account.', cid)
		Topic[cid] = nil
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

When I ask for deposit, npc takes my money and I have an error:

Code:
[14/12/2011 00:13:49] Lua Script Error: [Npc interface] 
[14/12/2011 00:13:49] data/npc/scripts/bank.lua:onCreatureSay
[14/12/2011 00:13:49] data/npc/scripts/bank.lua:81: attempt to call global 'getPlayerBalance' (a nil value)
[14/12/2011 00:13:49] stack traceback:
[14/12/2011 00:13:49] 	[C]: in function 'getPlayerBalance'
[14/12/2011 00:13:50] 	data/npc/scripts/bank.lua:81: in function 'callback'
[14/12/2011 00:13:50] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[14/12/2011 00:13:50] 	data/npc/scripts/bank.lua:9: in function <data/npc/scripts/bank.lua:9>

And this when I ask for balance or withdraw :

Code:
[14/12/2011 00:14:30] Lua Script Error: [Npc interface] 
[14/12/2011 00:14:30] data/npc/scripts/bank.lua:onCreatureSay
[14/12/2011 00:14:30] data/npc/scripts/bank.lua:36: attempt to call global 'getPlayerBalance' (a nil value)
[14/12/2011 00:14:30] stack traceback:
[14/12/2011 00:14:30] 	[C]: in function 'getPlayerBalance'
[14/12/2011 00:14:30] 	data/npc/scripts/bank.lua:36: in function 'callback'
[14/12/2011 00:14:30] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[14/12/2011 00:14:31] 	data/npc/scripts/bank.lua:9: in function <data/npc/scripts/bank.lua:9>

When I ask for deposit, npc takes my money but on my player DB, it shows my 'balance' as 0.

I'm using 9.31 - The Forgotten Server - Version 0.2.11.2 (Mystic Spirit) - R4.

Many thanks in advance for any help!
 
Last edited:
This is because getPlayerBalance is a non-existent function.
Keep in mind, there are multiple functions that 0.3 has that 0.2 does not have.

I haven't tried, but you could just take the function from 0.3 and add it into 0.2.

Try adding these functions into global.lua:
Lua:
function doPlayerWithdrawMoney(cid, amount)
	if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
		return false
	end

	local balance = getPlayerBalance(cid)
	if(amount > balance or not doPlayerAddMoney(cid, amount)) then
		return false
	end

	doPlayerSetBalance(cid, balance - amount)
	return true
end

function doPlayerDepositMoney(cid, amount)
	if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
		return false
	end

	if(not doPlayerRemoveMoney(cid, amount)) then
		return false
	end

	doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
	return true
end

Again, I can't be sure if it will work, just try it out.
 
Thanks for your quickyl reply, but it wasn't sucessful.

This version I'm using isnt new? Shouldn't have all functions already? Or it is a new and actual, but have all different functions?

Or just an old release compiled to work with actual client system?

All DB schema is different and it gaveme a pain head to make an ACC maker =X

---
This 0.3 version you had mentioned is a donate release only?

I got this old "The Forgotten Server, version 0.3.6 (Crying Damson)" it is a release from 2009 that work with 8.31 clients. Is it the one you talk about sir?

Thanks in advance!
 
Last edited:
if you need a new banker.lua i got one i used on [8.7] The Forgotten Server v0.2.9 (Mystic Spirit)

Lua:
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 doPlayerAddCash(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)
	dofile("./config.lua")
	env = assert(luasql.mysql())
	con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	local cursor = assert(con:execute("SELECT `name` FROM `players` WHERE `name` = '".. name .."';"))
 
  local gotChar = numRows(cursor)
  if gotChar >= 1 then
    local value = TRUE
	return value
  else
   local value = FALSE
   return value
  end
end
 
function isBankPlayerOnline(name) --only used as a backup
	dofile("./config.lua")
	env = assert(luasql.mysql())
	con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	local cursor = assert(con:execute("SELECT `name` FROM `players` WHERE `name` = '".. name .."' AND `online` = '1';"))
 
  local gotChar = numRows(cursor)
  if gotChar == 1 then
    local value = TRUE
	return value
  else
   local value = FALSE
   return value
  end
end
 
function getPlayerBalance(cid)
   if getPlayerStorageValue(cid, 50505) == -1 then
	setPlayerStorageValue(cid, 50505, 0)
   end
 local result = getPlayerStorageValue(cid, 50505)
  getbalance = result
 return getbalance
end
 
function setTransferStorageValue(name, amount)
local player = getPlayerByName(name)
local playerGUID = getPlayerGUIDByName(name)
local bankKey = 50505
local bankStartValue = 0
print(name)
print(playerGUID)
 if isBankPlayerOnline(name) == TRUE then
  local transferBalance = getPlayerStorageValue(player, 50505)
    if transferBalance == -1 then
      setPlayerStorageValue(player, 50505, 0)
      print('Bank account created.')
	  setPlayerStorageValue(player, 50505, transferBalance+amount)
	  print('Money transfered.')	
    else
      setPlayerStorageValue(player, 50505, transferBalance+amount)
	  print('Money transfered.')	
	end
 else
	dofile("./config.lua")
	env = assert(luasql.mysql())
	con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	local charBankSelect = assert(con:execute("SELECT * FROM `player_storage` WHERE `player_id` = '".. playerGUID .."' AND `key` = '50505';"))
	local gotBankChar = numRows(charBankSelect)
	if gotBankChar <= 0 then
	  assert(con:execute("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" .. playerGUID .. ", " .. bankKey .. ", " .. bankStartValue .. ")"))
	  print('Bank account created to offline player.')
	  assert(con:execute("UPDATE `player_storage` SET `value` = `value` + " .. amount .. " WHERE `player_id` = '" .. playerGUID .. "' AND `key` = '50505';"))
	  print('Money transfered to offline player.')
	end
	if gotBankChar == 1 then
	  assert(con:execute("UPDATE `player_storage` SET `value` = `value` + " .. amount .. " WHERE `player_id` = '" .. playerGUID .. "' AND `key` = '50505';"))
	  print('Money transfered to offline player.')
	end
  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)
    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, '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 and balance < 100000 then
            sayText = 'You\'ve made a pretty peny haven\'t you! Your account balance is ' .. balance .. ' gold coins.'
        elseif balance >= 1000000 then
            sayText = 'You must be one of the richest people in the all of the Starfire lands! 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)
                    doPlayerAddCash(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])
                    doPlayerAddCash(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])
                    doPlayerAddCash(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)
                    doPlayerAddCash(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
		 local balance = getPlayerBalance(cid)
            if doPlayerRemoveMoney(cid,last_count[cid]) == TRUE then
			    setPlayerStorageValue(cid, 50505, balance+last_count[cid])
                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
		  local balance = getPlayerBalance(cid)
			if balance >= last_count[cid] then
				setPlayerStorageValue(cid, 50505, balance-last_count[cid])
				doPlayerAddMoney(cid,last_count[cid])
                sayText = 'You withdrew ' .. 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. Your 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
	   playerTo = doPlayerExist(msg)
        if playerTo == TRUE then
            last_name[cid] = msg
            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 = 'The player ' .. orginal_msg .. ' does not exsist.'
        end
    elseif talk_state[cid] == 42 then
        if msgcontains(msg, 'yes') then
		 local balance = getPlayerBalance(cid)
            if balance >= last_count[cid] then
				setTransferStorageValue(last_name[cid], last_count[cid])
				setPlayerStorageValue(cid, 50505, balance-last_count[cid])
                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.'
                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())
if you need the npc file just ask
 
Last edited:
Works 100%

Got only a little question about the script, does it have that protection againt bugging the money? like to have infitiy money or to crash server?
 
Back
Top