TalkAction Bank System via TalkActions

Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Hello, here is other of my script.. a bank system. (tested in TFS v0.3.1 and v0.3.3)

Features
  • You can see your account balance.
  • Deposit money on your account balance.
  • Deposit all money that you have in your backpack.
  • Withdraw money from your account balance.
  • Withdraw all your money from your account balance.
  • Possibility to transfer money.
  • Possibility to transfer all your money.
Words
  • !balance
  • !deposit [money]
  • !depositall
  • !withdraw [money]
  • !withdrawall
  • !transfer [player], [money]
  • !transferall [player]
Changelog
  • [04/04/09] - Fixed bug with negative values (Thanks Slawkens)
  • [05/04/09] - Fixed text showed in screen (Ex: Darkhaos[100]: !balance)
  • [07/04/09] - Bank System only can be used if this one confirmed in config.lua (bankSystem = "yes")
  • [07/04/09] - If is player have battle, can't use the bank (CONDITION_INFIGHT)

- Balance -
Create a file called balance.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your account balance is " .. getPlayerBalance(cid) .. ".")
    return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Deposit -
Create a file called deposit.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

if(param == "") then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
    return TRUE
end

local m = tonumber(param)

if(not m) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires numeric param.")
    return TRUE
end

m = math.abs(m)
if m <= getPlayerMoney(cid) then
    doPlayerDepositMoney(cid, m)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Alright, you have added the amount of " .. m .. " gold to your balance. You can withdraw your money anytime you want to. Your account balance is " .. getPlayerBalance(cid) .. ".")

else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You do not have enough money.")
    end
    return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Deposit All -
Create a file called deposit_all.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Alright, you have added the amount of " .. getPlayerMoney(cid) .. " gold to your balance. You can withdraw your money anytime you want to.")
doPlayerDepositAllMoney(cid)
return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Withdraw -
Create a file called withdraw.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

local m = tonumber(param)

if(param == "") then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
    return TRUE
end

if(not m) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires numeric param.")
    return TRUE
end

m = math.abs(m)
if m <= getPlayerBalance(cid) then
    doPlayerWithdrawMoney(cid, m)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Here you are, " .. m .. " gold. Your account balance is " .. getPlayerBalance(cid) .. ".")

else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There is not enough gold on your account.")
    end
    return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Withdraw All -
Create a file called withdraw_all.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Here you are, " .. getPlayerBalance(cid) .. " gold.")
doPlayerWithdrawAllMoney(cid)
return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Transfer -
Create a file called transfer.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == FALSE then

if(param == "") then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
    return TRUE
end

local t = string.explode(param, ",")
local m = tonumber(t[2])
local tmp = string.explode(t[2], ",")

if(not m) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "No money specified.")
    return TRUE
end

m = math.abs(m)
if m <= getPlayerBalance(cid) then
    if playerExists(t[1]) then
    doPlayerTransferMoneyTo(cid, t[1], m)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have transferred " .. m .. " gold to " .. t[1] .. ". Your account balance is " .. getPlayerBalance(cid) .. " gold.")

else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Player " .. t[1] .. " does not exist.")
    end
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There is not enough gold on your account. Your account balance is " .. getPlayerBalance(cid) .. ". Please tell the amount of gold coins you would like to transfer.")
    end
    return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
- Transfer All -
Create a file called transfer_all.lua and put there:

Lua:
function onSay(cid, words, param)

local config = {
    bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
    playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}

if config.bankSystemEnabled == TRUE then
    if config.playerIsFighting == TRUE then

if(param == "") then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
    return TRUE
end

local t = string.explode(param, ",")

if playerExists(param) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have transferred " .. getPlayerBalance(cid) .. " gold to " .. param .. ".")
    doPlayerTransferAllMoneyTo(cid, param)
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Player " .. param .. " does not exist.")
    end
    return TRUE
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
    return TRUE
end
else
    return FALSE
    end
end
Now, put this in your talkaction.xml:

XML:
<talkaction log="yes" words="!balance" script="balance.lua" />
<talkaction log="yes" words="!deposit" script="deposit.lua" />
<talkaction log="yes" words="!withdraw" script="withdraw.lua" />
<talkaction log="yes" words="!transfer" script="transfer.lua" />
<talkaction log="yes" words="!depositall" script="deposit_all.lua" />
<talkaction log="yes" words="!withdrawall" script="withdraw_all.lua" />
<talkaction log="yes" words="!transferall" script="transfer_all.lua" />
 
Last edited by a moderator:

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
add return true to all so the command will not appear on screen xD (like: X[X]: !balance)


and if the deposit number is negative and you withdraw it you will get a lot of money =D

example:

!deposit -10000000000000000000000 = your account balance is -10000000000000000000000

!withdraw -10000000000000000000000 = YOU GOT A LOT OF MONEY =d

answer=

Code:
math.abs(X)
 
Last edited:
OP
Darkhaos
Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Mmm... i don't know how use math.abs() xD!!

Can you tell me how use? and how fix the script?
 

Bintzer

One Love
Joined
Dec 19, 2007
Messages
1,763
Best answers
0
Reaction score
29
Location
Orlando
You should combine it all into one script also..
 

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
Code:
local m = math.abs(tonumber(t[2]))
xD if a stupid guy tries !transfer -1000,XPlayer he will loose the money too xD
 

slawkens

Developer
Premium User
Joined
Aug 27, 2007
Messages
2,873
Best answers
60
Reaction score
389
Location
Germany
NOT
local m = math.abs(tonumber(param))

because it will occur lua script error if player will put not numeric value.

BUT

before:
if m <= getPlayerMoney(cid) then

add
m = math.abs(m)
 
OP
Darkhaos
Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
NOT
local m = math.abs(tonumber(param))

because it will occur lua script error if player will put not numeric value.

BUT

before:
if m <= getPlayerMoney(cid) then

add
m = math.abs(m)
You're right!! thanks!!

Look the scripts again.. they're fixed :)
 
Last edited:

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
:O! i didnt know that XD

Code:
[05/04/2009 08:29:26] Lua Script Error: [TalkAction Interface] 
[05/04/2009 08:29:26] data/talkactions/scripts/otf/bank/deposit.lua:onSay

[05/04/2009 08:29:26] data/talkactions/scripts/otf/bank/deposit.lua:8: bad argument #1 to 'abs' (number expected, got nil)
[05/04/2009 08:29:26] stack traceback:
[05/04/2009 08:29:26]     [C]: in function 'abs'
[05/04/2009 08:29:26]     data/talkactions/scripts/otf/bank/deposit.lua:8: in function <data/talkactions/scripts/otf/bank/deposit.lua:1>
if you put non numeric value with

Code:
local m = math.abs(tonumber(t[2]))
and with

Code:
m = math.abs(m)
no error (Y) nice

i fixed that on bounty hunters now too, thanks to slawkens
 
Last edited:

Nottinghster

Tibia World RPG Developer
Joined
Oct 24, 2007
Messages
1,470
Best answers
3
Reaction score
330
Location
Brazil - Rio de Janeiro
Only to remember, if you don't have some functions, the script will not work!!

These are the functions to work:
Code:
function getPlayerMoney(cid)
	return ((getPlayerItemCount(cid, ITEM_CRYSTAL_COIN) * 10000) + (getPlayerItemCount(cid, ITEM_PLATINUM_COIN) * 100) + getPlayerItemCount(cid, ITEM_GOLD_COIN))
end

function doPlayerWithdrawAllMoney(cid)
	return doPlayerWithdrawMoney(cid, getPlayerBalance(cid))
end

function doPlayerDepositAllMoney(cid)
	return doPlayerDepositMoney(cid, getPlayerMoney(cid))
end

function doPlayerTransferAllMoneyTo(cid, target)
	return doPlayerTransferMoneyTo(cid, target, getPlayerBalance(cid))
end

function playerExists(name)
	return (getPlayerGUIDByName(name) ~= 0)
end
Great Script Darkhaos !!!
 

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
what did you add (you edited the main post o_O)

OMFG YOU ARE A GENIUS... ._. (you added some thing to the script!)
 
Last edited:

artofwork

Well-Known Member
Joined
Dec 3, 2008
Messages
420
Best answers
0
Reaction score
58
-Bump-
This should be at the top always :) This is if not 'the' most important part of the server ;)
 

Chewy

New Member
Joined
Jun 30, 2008
Messages
9
Best answers
0
Reaction score
0
hey im getting this error:
Code:
[02/05/2009  20:23:58] Lua Script Error: [TalkAction Interface] 
[02/05/2009  20:23:58] data/talkactions/scripts/balance.lua:onSay

[02/05/2009  20:23:58] data/talkactions/scripts/balance.lua:11: attempt to call global 'getPlayerBalance' (a nil value)
[02/05/2009  20:23:58] stack traceback:
[02/05/2009  20:23:58] 	data/talkactions/scripts/balance.lua:11: in function <data/talkactions/scripts/balance.lua:1>
what server are you using?
 
Top