Skip to content

Commit

Permalink
bank: $2 fee for withdrawing from ATMs
Browse files Browse the repository at this point in the history
  • Loading branch information
mabako committed May 10, 2010
1 parent d207aec commit 29964ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions resources/bank/bank.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ local function loadBank( id, x, y, z, rotation, interior, dimension, skin )
setElementInterior( bank, interior )
setElementDimension( bank, dimension )

banks[ id ] = { bank = bank, canDeposit = skin ~= -1 }
banks[ id ] = { bank = bank, canDeposit = skin ~= -1, withdrawFee = skin == -1 and 2 or 0 }
banks[ bank ] = id
end

Expand Down Expand Up @@ -408,7 +408,7 @@ addEventHandler( "bank:select", root,
if balance then
p[ source ].enteredPin = true
p[ source ].ignoreUpdate = true
triggerClientEvent( source, "bank:single", bank.bank, balance, bank.canDeposit )
triggerClientEvent( source, "bank:single", bank.bank, balance, bank.canDeposit, bank.withdrawFee )
else
outputChatBox( "This service is currently not available.", source, 255, 0, 0 )
end
Expand Down Expand Up @@ -522,10 +522,12 @@ addEventHandler( "bank:updateaccount", root,
-- ignore if the amount is too large to be withdrawn
if -amount > getAccountBalance( card[2] ) then
return
elseif -amount + bank.withdrawFee > getAccountBalance( card[2] ) then
return
end
end

if modifyAccountBalance( card[2] , amount ) then
if modifyAccountBalance( card[2] , amount - ( amount < 0 and bank.withdrawFee or 0 ) ) then
if amount < 0 then
exports.players:giveMoney( source, -amount )
end
Expand Down
4 changes: 2 additions & 2 deletions resources/bank/bank_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ addEventHandler( "bank:promptPIN", resourceRoot,

addEvent( "bank:single", true )
addEventHandler( "bank:single", resourceRoot,
function( balance, canDeposit )
function( balance, canDeposit, withdrawFee )
exports.gui:hide( )
exports.gui:updateBankSingle( balance, canDeposit )
exports.gui:updateBankSingle( balance, canDeposit, withdrawFee )
exports.gui:show( 'bank_single', true )
end
)
12 changes: 8 additions & 4 deletions resources/gui/windows/bank.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ windows.bank_prompt_pin =
--

local _balance = 0
local _withdrawFee = 0

local function deposit( key )
if key ~= 2 and destroy and destroy['g:bank:amount'] then
Expand Down Expand Up @@ -180,18 +181,21 @@ local function withdraw( key )
if amount <= 0 then
outputChatBox( "Please enter an amount greater than 0.", 255, 0, 0 )
elseif amount > _balance then
outputChatBox( "You do not have so much money on your account.", 255, 0, 0 )
outputChatBox( "You do not enough money on your account.", 255, 0, 0 )
elseif amount + _withdrawFee > _balance then
outputChatBox( "You do not enough money on your account to pay the fee as well.", 255, 0, 0 )
else
triggerServerEvent( "bank:updateaccount", getLocalPlayer( ), -amount )
_balance = _balance - amount
_balance = _balance - amount - _withdrawFee
windows.bank_single[2].text = "Your account balance: $" .. _balance .. "."
end
end
end
end

function updateBankSingle( balance, canDeposit )
function updateBankSingle( balance, canDeposit, withdrawFee )
_balance = balance
_withdrawFee = withdrawFee or 0

windows.bank_single = {
onClose = function( )
Expand All @@ -216,7 +220,7 @@ function updateBankSingle( balance, canDeposit )
},
{
type = "button",
text = "Withdraw",
text = "Withdraw" .. ( _withdrawFee > 0 and ( " (Fee: $" .. withdrawFee .. ")" ) or "" ),
onClick = withdraw,
}
}
Expand Down

0 comments on commit 29964ee

Please sign in to comment.