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

Problem with Bank <TFS>

Sylither

New Member
Joined
Aug 4, 2007
Messages
48
Reaction score
0
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

local talkState = 0
local transaction_count = 0
local transaction_type = 0 --1-withdraw 2-store 3 -transfer
local transfer_name = ""
local transfer_cid = 0

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

function clearCrap()
	talkState = 0
	transaction_count = 0
	transfer_name = ""
	transfer_cid = 0
end
function createBankAccount(_cid)
	if getPlayerStorageValue(_cid,STORAGE_BANK) < 0 then
		setPlayerStorageValue(_cid,STORAGE_BANK,0)
	end
end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
	end
	
	if msgcontains(msg, 'balance') then
		local balance = getPlayerStorageValue(cid, STORAGE_BANK )
		if  balance >= 0 then
			selfSay("Your account balance is " .. tostring(balance) .. " gold.")
		else
			selfSay("You haven't stored anything in your account yet.")
		end

	elseif msgcontains(msg, 'withdraw') then
		selfSay("How much do you want to withdraw?")
		talkState = 1
		transaction_count = 0

	elseif msgcontains(msg, 'store') or msgcontains(msg,'deposit') then
		selfSay("How much do you want to store? <oink!>")
		talkState = 2
		transaction_count = 0

	elseif msgcontains(msg, 'transfer') then
		selfSay("To whom do you want to transfer money to?")
		talkState = 3
		transfer_name = ""
		transfer_cid = 0
		transaction_count = 0

	elseif msgcontains(msg, 'help') then
		selfSay("I am Florencia, the piggy bank. <oink!> You can store or withdraw money from me or check your balance.")

	--confirm to withdraw money
	elseif talkState == 1 then
		local num = tonumber(msg)
		if(num ~= nil) then
			transaction_count = num
                                    if num >= 1 and num < 800001 then
			selfSay("Do you want to withdraw " .. msg .. " gold coins?")
			talkState = 10
			transaction_type = 1
		else
			selfSay("How much?")
		end
end

	--confirm to store money
	elseif talkState == 2 then
		local num = tonumber(msg)
		if(num ~= nil) then
			transaction_count = num
                                    if num >= 1 and num < 800001 then
			selfSay("Do you want to store " .. msg .. " gold coins?")
			talkState = 10
			transaction_type = 2
		else
			selfSay("How much?")
		end
end

	--ask how much to transfer
	elseif talkState == 3 then
		local _transid = getPlayerByName(msg)
		if _transid ~= nil and _transid > 0 then
			transfer_name = msg
			transfer_cid = _transid
                                    if num >= 1 and num < 800001 then
			selfSay("How much do you wish to transfer?")
			talkState = 4
		else
			selfSay("That player does not exist/is not online.")
			talkState = 0
		end
end

	--confirm transfer
	elseif talkState == 4 then
		local num = tonumber(msg)
		if(num ~= 0) then
			transaction_count = num
                                    if num >= 1 and num < 800001 then
			selfSay("Do you want to transfer " .. msg .. " gold coins to " .. transfer_name .. "?")
			talkState = 10
			transaction_type = 3
		else
			selfSay("How much?")
		end
end

	elseif talkState == 10 then
		if msgcontains(msg,'yes') then
			createBankAccount(cid)
			local balance = getPlayerStorageValue(cid, STORAGE_BANK )
			
			--withdraw
			if transaction_type == 1 then
				if balance >= transaction_count then
					setPlayerStorageValue(cid,STORAGE_BANK,balance-transaction_count)
					doPlayerAddMoney(cid,transaction_count)
					selfSay('Done.')
				else
					selfSay('Sorry, your bank account does not have that much money.')
				end

			--store
			elseif transaction_type == 2 then
				if doPlayerRemoveMoney(cid,transaction_count) then
					setPlayerStorageValue(cid,STORAGE_BANK,balance+transaction_count)
					selfSay('Done.')
				else
					selfSay("You do not have that much money!")
				end

			--transfer
			elseif transaction_type == 3 then
				if balance >= transaction_count then
					setPlayerStorageValue(cid,STORAGE_BANK,balance-transaction_count)
					createBankAccount(transfer_cid)
					setPlayerStorageValue(transfer_cid,STORAGE_BANK,getPlayerStorageValue(transfer_cid,STORAGE_BANK)+transaction_count)
					selfSay('Done.')
				else
					selfSay("Your bank account does not have that much money.")
				end
			end

			clearCrap()

		elseif msgcontains(msg,'no') then
			selfSay('Transaction canceled <oink!>')
			clearCrap()
		end
	end

	return TRUE
end

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

i have problem with this code,

18:50 Undead Sylither [29]: hi
18:50 Piggy Bank: Hello Undead Sylither. I am your personal bank.
18:50 Undead Sylither [29]: deposit
18:50 Piggy Bank: How much do you want to store? <oink!>
18:50 Undead Sylither [29]: 0323
18:50 Piggy Bank: Do you want to store 0323 gold coins?
18:51 Undead Sylither [29]: yes
18:51 Piggy Bank: Done.

i dont have any money and when i say 0323 for deposit, he put 323 in my bank, who know why? :(
 
Last edited:
1. You forgot to add an money check, the npc should check how mutch money the player has before it can deposit.

2. What the npc is doing is right, if you want to withdraw 0100 from your bank it will give u 100, since the first 0 dosen't count
 
1. You forgot to add an money check, the npc should check how mutch money the player has before it can deposit.

Code:
			--store
			elseif transaction_type == 2 then
				if doPlayerRemoveMoney(cid,transaction_count) then
					setPlayerStorageValue(cid,STORAGE_BANK,balance+transaction_count)
					selfSay('Done.')
				else
					selfSay("You do not have that much money!")
				end

You fail. It's there.
 
Last edited by a moderator:
Code:
...
NPC code
...

i have problem with this code,

18:50 Undead Sylither [29]: hi
18:50 Piggy Bank: Hello Undead Sylither. I am your personal bank.
18:50 Undead Sylither [29]: deposit
18:50 Piggy Bank: How much do you want to store? <oink!>
18:50 Undead Sylither [29]: 0323
18:50 Piggy Bank: Do you want to store 0323 gold coins?
18:51 Undead Sylither [29]: yes
18:51 Piggy Bank: Done.

i dont have any money and when i say 0323 for deposit, he put 323 in my bank, who know why? :(
Can I use your NPC code in my account maker page - lua scripts? :)
 
try this as money checker

Code:
			--store
			elseif transaction_type == 2 then
				if doPlayerRemoveMoney(cid,transaction_count) == TRUE then
					setPlayerStorageValue(cid,STORAGE_BANK,balance+transaction_count)
					selfSay('Done.')
				else
					selfSay("You do not have that much money!")
				end



Already released banker:
http://otland.net/showthread.php?t=819
 
Back
Top