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

TalkAction Bank System via TalkActions

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
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:
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:
Mmm... i don't know how use math.abs() xD!!

Can you tell me how use? and how fix the script?
 
Code:
local m = math.abs(tonumber(t[2]))

xD if a stupid guy tries !transfer -1000,XPlayer he will loose the money too xD
 
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)
 
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:
: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:
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 !!!
 
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:
-Bump-
This should be at the top always :) This is if not 'the' most important part of the server ;)
 
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?
 
Back
Top