Skip to content

Commit

Permalink
banks, gui, items: added a debit card item, show a list of accounts t…
Browse files Browse the repository at this point in the history
…o withdraw money from or deposit it to when you click on an ATM or Employee
  • Loading branch information
mabako committed May 10, 2010
1 parent 0677ebf commit 3b37fea
Showing 6 changed files with 190 additions and 0 deletions.
65 changes: 65 additions & 0 deletions resources/bank/bank.lua
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]

local maxAccountsPerCharacter = get( 'max_accounts_per_character' ) or 3

--

local p = { }
local banks = { }

--
@@ -59,6 +64,12 @@ addEventHandler( "onResourceStart", resourceRoot,
{ name = 'balance', type = 'bigint(20) unsigned', default = 0 },
} ) then cancelEvent( ) return end

if not exports.sql:create_table( 'bank_cards',
{
{ name = 'cardID', type = 'int(10) unsigned', primary_key = true, auto_increment = 200000 },
{ name = 'bankAccountID', type = 'int(10) unsigned' },
} ) then cancelEvent( ) return end

--

local result = exports.sql:query_assoc( "SELECT * FROM banks ORDER BY bankID ASC" )
@@ -108,3 +119,57 @@ addCommandHandler( "createbank",
)

--

addEventHandler( "onElementClicked", resourceRoot,
function( button, state, player )
if button == "left" and state == "up" then
local bankID = banks[ source ]
if bankID then
local bank = banks[ bankID ]
if bank then
local x, y, z = getElementPosition( player )
if getDistanceBetweenPoints3D( x, y, z, getElementPosition( source ) ) < ( getElementType( bank.bank ) == "object" and 1 or 5 ) and getElementDimension( player ) == getElementDimension( source ) then
-- no data set yet
if not p[ player ] then
p[ player ] = { }

-- check how many accounts a player has
local result = exports.sql:query_assoc_single( "SELECT COUNT(*) AS number FROM bank_accounts WHERE characterID = " .. exports.players:getCharacterID( player ) )
if result then
p[ player ].accounts = result.number
end
end

p[ player ].bankID = bankID

local cards = { }
for key, value in ipairs( exports.items:get( player ) ) do
if value.item == 6 then
table.insert( cards, value.value ) -- this should actually find out the associated card's account
end
end
if getElementType( bank.bank ) == "object" then
-- for an ATM: show all of the accounts a player has a credit card for.
triggerClientEvent( player, "banks:open", source, cards, nil, false )
else
-- show all accounts a player has a credit card for or which belongs to him.
triggerClientEvent( player, "banks:open", source, cards, p[ player ].accounts < maxAccountsPerCharacter, true )
end
end
end
end
end
end
)

addEventHandler( "onCharacterLogout", root,
function( )
p[ source ] = nil
end
)

addEventHandler( "onPlayerQuit", root,
function( )
p[ source ] = nil
end
)
10 changes: 10 additions & 0 deletions resources/bank/bank_c.lua
Original file line number Diff line number Diff line change
@@ -17,3 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

-- we don't want our shops to die, do we?
addEventHandler( "onClientPedDamage", resourceRoot, cancelEvent )

--

addEvent( "banks:open", true )
addEventHandler( "banks:open", resourceRoot,
function( accounts, canOpenAccount, canDeposit )
exports.gui:updateBankSelection( accounts, canOpenAccount, canDeposit )
exports.gui:show( 'bank_selection' )
end
)
1 change: 1 addition & 0 deletions resources/bank/meta.xml
Original file line number Diff line number Diff line change
@@ -22,4 +22,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<include resource="sql"/>
<include resource="players"/>
<include resource="items"/>
</meta>
7 changes: 7 additions & 0 deletions resources/gui/meta.xml
Original file line number Diff line number Diff line change
@@ -46,6 +46,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Updates the inventory. -->
<export function="updateInventory" type="client"/>

<script src="windows/bank.lua" type="client"/>
<!-- Updates the bank account selection
parameters:
(table) all available accounts
-->
<export function="updateBankSelection" type="client"/>

<script src="gui_c.lua" type="client"/>

<!-- Shows a GUI window.
106 changes: 106 additions & 0 deletions resources/gui/windows/bank.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
--[[
Copyright (c) 2010 MTA: Paradise
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]

local closeButton =
{
type = "button",
text = "Close",
onClick = function( key )
if key == 1 then
hide( )

windows.bank_selection = { closeButton }
end
end,
}

windows.bank_selection = { closeButton }

function updateBankSelection( accounts, canOpenAccount, canDeposit )
-- scrap what we had before
windows.bank_selection = {
onClose = function( )
triggerServerEvent( "banks:close", getLocalPlayer( ) )
windows.bank_selection = { closeButton }
end,
{
type = "label",
text = "Bank of San Andreas",
font = "bankgothic",
alignX = "center",
},
{
type = "pane",
panes = { }
}
}

-- let's add all items
if #accounts == 0 then
if canOpenAccount == nil then -- this is an ATM
table.insert( windows.bank_selection[2].panes,
{
image = ":players/images/skins/-1.png",
title = "No account.",
text = "You do not have any account.\nHead over to the bank to set one up.",
wordBreak = true,
}
)
end
else
for k, value in ipairs( accounts ) do
table.insert( windows.bank_selection[2].panes,
{
image = ":players/images/skins/-1.png",
title = "Credit Card",
text = "You can withdraw " .. ( canDeposit and "and deposit from/to" or "from" ) .. " account " .. value .. ".",
onHover = function( cursor, pos )
dxDrawRectangle( pos[1], pos[2], pos[3] - pos[1], pos[4] - pos[2], tocolor( unpack( { 0, 255, 0, 31 } ) ) )
end,
onClick = function( key )
if key == 1 then
triggerServerEvent( "banks:select", getLocalPlayer( ), k )
end
end,
wordBreak = true,
}
)
end
if canOpenAccount == true then -- at the bank, can open another account
table.insert( windows.bank_selection[2].panes,
{
image = ":players/images/skins/-1.png",
title = "New account.",
text = "Set up a new bank account.",
onHover = function( cursor, pos )
dxDrawRectangle( pos[1], pos[2], pos[3] - pos[1], pos[4] - pos[2], tocolor( unpack( { 255, 255, 0, 31 } ) ) )
end,
onClick = function( key )
if key == 1 then
triggerServerEvent( "banks:select", getLocalPlayer( ), -1 )
end
end,
wordBreak = true,
}
)
end
end

-- add a close button as well
table.insert( windows.bank_selection, closeButton )
end

1 change: 1 addition & 0 deletions resources/items/items_list.lua
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ item_list =
{ name = "Food", image = getFoodImage },
{ name = "Drink", image = getDrinkImage },
{ name = "Clothes", image = function( value, name ) if value then return ":players/images/skins/" .. value .. ".png" end end },
{ name = "Debit Card" },
}

--

0 comments on commit 3b37fea

Please sign in to comment.