Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 7cd9ea9

Browse files
authored
feat: Rewrite (#1)
More details in #1
2 parents beeec29 + 26df111 commit 7cd9ea9

File tree

7 files changed

+264
-209
lines changed

7 files changed

+264
-209
lines changed

client.lua

Lines changed: 89 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,128 @@
1-
local isATM = false
1+
-- TODO: Multiple UI colors (Fleeca, Lombank, Maze bank)
2+
3+
local uiOpened = false
4+
local isInBank = false
5+
6+
local OpenBank = function(bank)
7+
ESX.TriggerServerCallback('orp_banking:getBalance', function(balance)
8+
uiOpened = true
9+
isInBank = bank == true
10+
11+
SetNuiFocus(true, true)
12+
SendNUIMessage({
13+
type = 'openBank',
14+
balance = balance,
15+
isInBank = isInBank
16+
})
17+
18+
if not isInBank then
19+
SendNotify('Please note that you can only deposit money at bank', 'inform')
20+
end
21+
end)
22+
end
23+
24+
local CloseBank = function()
25+
uiOpened = false
26+
SetNuiFocus(false, false)
27+
end
28+
29+
local currentResource = GetCurrentResourceName()
30+
AddEventHandler('onResourceStop', function(resource)
31+
if resource == currentResource then CloseBank() end
32+
end)
33+
34+
35+
36+
-- NUI callbacks
37+
RegisterNUICallback('closeMenu', CloseBank)
38+
39+
RegisterNetEvent('orp_banking:update', function(balance)
40+
if uiOpened then
41+
SendNUIMessage({
42+
type = 'updateBalance',
43+
balance = balance
44+
})
45+
end
46+
end)
47+
48+
RegisterNUICallback('deposit', function(data)
49+
if isInBank then
50+
TriggerServerEvent('orp_banking:deposit', data)
51+
else
52+
SendNotify('You cannot deposit money at an ATM', 'error')
53+
end
54+
end)
55+
56+
RegisterNUICallback('withdraw', function(data)
57+
TriggerServerEvent('orp_banking:withdraw', data)
58+
end)
59+
60+
RegisterNUICallback('transfer', function(data)
61+
TriggerServerEvent('orp_banking:transfer', data)
62+
end)
63+
64+
265

66+
-- qtarget stuff
367
exports.qtarget:AddTargetModel(Config.ATMProps, {
468
options = {{
569
icon = 'fas fa-credit-card',
670
label = 'Use ATM',
7-
event = 'orp_banking:showMoney'
71+
action = OpenBank
872
}},
973
distance = 1.5
1074
})
1175

12-
exports.qtarget:AddBoxZone('LegionSquare_Fleeca1', vector3(145.84, -1035.6, 29.33), 0.5, 1.0,
76+
exports.qtarget:AddBoxZone('ATM_L', vec3(147.49, -1036.18, 29.34), 0.4, 1.3,
1377
{
14-
name = 'LegionSquare_Fleeca1',
15-
heading = 160.0,
16-
minZ = 29.0,
17-
maxZ = 30.5
78+
name = 'ATM_L',
79+
heading = 340.0,
80+
minZ = 28.69,
81+
maxZ = 30.64
1882
},
1983
{
2084
options = {{
21-
event = 'orp_banking:showMoney',
2285
icon = 'fas fa-credit-card',
23-
label = 'Use ATM'
86+
label = 'Use ATM',
87+
action = OpenBank
2488
}},
2589
distance = 1.5
2690
}
2791
)
2892

29-
exports.qtarget:AddBoxZone('LegionSquare_Fleeca2', vector3(147.5, -1036.2, 29.33), 0.5, 1.0,
93+
exports.qtarget:AddBoxZone('ATM_R', vec3(145.85, -1035.61, 29.34), 0.4, 1.3,
3094
{
31-
name = 'LegionSquare_Fleeca2',
32-
heading = 160.0,
33-
minZ = 29.0,
34-
maxZ = 30.5
95+
name = 'ATM_R',
96+
heading = 340.0,
97+
minZ = 28.69,
98+
maxZ = 30.64
3599
}, {
36100
options = {{
37-
event = 'orp_banking:showMoney',
38101
icon = 'fas fa-credit-card',
39-
label = 'Use ATM'
102+
label = 'Use ATM',
103+
action = OpenBank
40104
}},
41105
distance = 1.5
42106
}
43107
)
44108

45109
for k,v in pairs(Config.BankZones) do
46-
local pos = GetObjectOffsetFromCoords(v[1], v[2], 0.0, 0.7, 0.0)
47-
exports.qtarget:AddBoxZone('Bank_Zone'..k, pos, 1.0, 4.5,
110+
local name = ('Bank_%s'):format(k)
111+
exports.qtarget:AddBoxZone(name, v.pos, v.length, v.width,
48112
{
49-
name = 'Bank_Zone'..k,
50-
heading = v[2],
51-
minZ = pos.z - 1.0,
52-
maxZ = pos.z + 1.5
113+
name = name,
114+
heading = v.h,
115+
minZ = v.minZ,
116+
maxZ = v.maxZ
53117
}, {
54118
options = {{
55119
icon = 'fas fa-money-bill-wave',
56120
label = 'Access bank account',
57-
event = 'orp_banking:showBankMoney',
58-
121+
action = function()
122+
OpenBank(true)
123+
end
59124
}},
60125
distance = 2.0
61126
}
62127
)
63128
end
64-
65-
66-
67-
68-
69-
RegisterNetEvent('orp_banking:showMoney')
70-
AddEventHandler('orp_banking:showMoney', function()
71-
isATM = true
72-
SetNuiFocus(true, true)
73-
SendNUIMessage({ type = 'openBank' })
74-
TriggerServerEvent('orp_banking:balance')
75-
SendNotify('Please note that you can only deposit money at bank', 'inform')
76-
end)
77-
78-
RegisterNetEvent('orp_banking:showBankMoney')
79-
AddEventHandler('orp_banking:showBankMoney', function()
80-
isATM = false
81-
SetNuiFocus(true, true)
82-
SendNUIMessage({ type = 'openBank' })
83-
TriggerServerEvent('orp_banking:balance')
84-
end)
85-
86-
RegisterNetEvent('orp_banking:info')
87-
AddEventHandler('orp_banking:info', function(balance)
88-
SendNUIMessage({
89-
type = 'updateBalance',
90-
balance = balance
91-
})
92-
end)
93-
94-
RegisterNetEvent('orp_banking:back')
95-
AddEventHandler('orp_banking:back', function(balance)
96-
SendNUIMessage({
97-
type = 'balanceReturn',
98-
bal = balance
99-
})
100-
end)
101-
102-
RegisterNetEvent('orp_bank:notify')
103-
AddEventHandler('orp_bank:notify', function(msg, type)
104-
SendNotify(msg, type)
105-
end)
106-
107-
108-
109-
110-
111-
RegisterNUICallback('balance', function()
112-
TriggerServerEvent('orp_banking:balance')
113-
end)
114-
115-
RegisterNUICallback('transfer', function(data)
116-
TriggerServerEvent('orp_banking:transfer', data.to, data.amount)
117-
TriggerServerEvent('orp_banking:balance')
118-
end)
119-
120-
RegisterNUICallback('deposit', function(data)
121-
if not isATM then
122-
TriggerServerEvent('orp_banking:deposit', tonumber(data.amount))
123-
TriggerServerEvent('orp_banking:balance')
124-
else
125-
SendNotify('You cannot deposit money at an ATM', 'error')
126-
end
127-
end)
128-
129-
RegisterNUICallback('withdraw', function(data)
130-
TriggerServerEvent('orp_banking:withdraw', tonumber(data.amount))
131-
TriggerServerEvent('orp_banking:balance')
132-
end)
133-
134-
RegisterNUICallback('closeMenu', function()
135-
SetNuiFocus(false, false)
136-
SendNUIMessage({ type = 'closeAll' })
137-
end)
138-
139-
140-
141-
AddEventHandler('onResourceStop', function(res)
142-
if res ~= GetCurrentResourceName() then return end
143-
144-
SetNuiFocus(false, false)
145-
SendNUIMessage({ type = 'closeAll' })
146-
end)

config.lua

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,81 @@ Config.ATMProps = {
1010
}
1111

1212
Config.BankZones = {
13-
{ vec3(149.24, -1040.58, 29.36), 160.0 }, -- Legion Square
14-
{ vec3(-1213.25, -331.12, 37.77), 207.0 }, -- Del Perro
15-
{ vec3(-351.6, -49.77, 49.03), 160.0 }, -- Burton
16-
{ vec3(313.58, -278.94, 54.17), 160.0 }, -- Hawick
17-
{ vec3(-2962.52, 482.24, 15.7), 268.0 }, -- Highway
18-
{ vec3(1175.71, 2706.87, 38.09), 0.0 }, -- Sandy Shores
19-
{ vec3(-112.02, 6469.17, 31.62), 315.0 }, -- Paleto Bay
13+
{ -- Legion Square
14+
pos = vec3(149.02, -1041.17, 29.37),
15+
h = 340.0,
16+
length = 0.8,
17+
width = 6.0,
18+
minZ = 28.37,
19+
maxZ = 31.07
20+
},
21+
22+
{ -- Del Perro
23+
pos = vec3(-1212.92, -331.6, 37.79),
24+
h = 27.0,
25+
length = 0.8,
26+
width = 6.0,
27+
minZ = 36.79,
28+
maxZ = 39.49
29+
},
30+
31+
{ -- Burton
32+
pos = vec3(-351.78, -50.36, 49.04),
33+
h = 341.0,
34+
length = 0.8,
35+
width = 6.0,
36+
minZ = 48.04,
37+
maxZ = 50.74
38+
},
39+
40+
{ -- Hawick
41+
pos = vec3(313.37, -279.53, 54.17),
42+
h = 340.0,
43+
length = 0.8,
44+
width = 6.0,
45+
minZ = 53.17,
46+
maxZ = 55.87
47+
},
48+
49+
{ -- Highway
50+
pos = vec3(-2961.91, 482.27, 15.7),
51+
h = 87.0,
52+
length = 0.8,
53+
width = 6.0,
54+
minZ = 14.7,
55+
maxZ = 17.4
56+
},
57+
58+
{ -- Sandy Shores
59+
pos = vec3(1175.7, 2707.51, 38.09),
60+
h = 0.0,
61+
length = 0.8,
62+
width = 6.0,
63+
minZ = 37.09,
64+
maxZ = 39.79
65+
},
66+
67+
{ -- Paleto Bay
68+
pos = vec3(-111.54, 6469.59, 31.62),
69+
h = 315.0,
70+
length = 0.8,
71+
width = 4.4,
72+
minZ = 30.62,
73+
maxZ = 33.12
74+
}
2075
}
2176

2277
SendNotify = function(msg, type)
2378

24-
TriggerEvent('mythic_notify:client:SendAlert', { -- https://github.com/antond15/mythic_notify
79+
TriggerEvent('mythic_notify:client:SendAlert', { -- https://github.com/thelindat/mythic_notify
2580
type = type,
2681
text = msg,
2782
length = 7500
2883
})
2984

30-
-- TriggerEvent('esx:showNotification', msg) -- Default GTA V notification.
31-
-- TriggerEvent('t-notify:client:Alert', { style = type, message = msg }) -- https://github.com/TasoOneAsia/t-notify
32-
-- TriggerEvent('b1g_notify:client:Notify', { type = type, text = msg }) -- https://github.com/CarlosVergikosk/B1G_NOTIFY
85+
-- ESX.ShowNotification(msg) -- Default ESX notification
86+
-- exports['t-notify']:Alert({ style = type, message = msg }) -- https://github.com/TasoOneAsia/t-notify
3387

3488
end
89+
90+
RegisterNetEvent('orp_banking:notify', SendNotify)

fxmanifest.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
fx_version 'cerulean'
22
game 'gta5'
3+
lua54 'yes'
34

45
author 'HiHowdy & ANTOND.#8507'
56
description 'Banking script with qtarget support.'
67
version '2.0.0'
78

89

9-
server_scripts {
10-
'@es_extended/imports.lua',
11-
'server.lua'
12-
}
10+
shared_script '@es_extended/imports.lua'
11+
server_script 'server.lua'
1312

1413
client_scripts {
1514
'config.lua',
1615
'client.lua'
1716
}
1817

18+
1919
ui_page 'html/index.html'
2020

2121
files {

html/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
<meta charset='UTF-8'>
66
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
77
<link rel='stylesheet' href='style.css'>
8+
<link rel='stylesheet' href='https://pro.fontawesome.com/releases/v6.0.0-beta3/css/all.css' crossorigin='anonymous'>
89
</head>
910

1011
<body>
1112

1213
<div class='container' id='bankui'>
13-
<button class='close'>X</button>
14+
<button class='close'><i class='fa-solid fa-xmark fa-lg'></i></button>
1415
<div class='row'>
1516
<div class='column left'>
1617
<img src='logo.png' class='logo'>
1718
<div class='account-info'>
1819
<div class='welcome'>Welcome back,</div>
19-
<div class='info-label'><i class='fas fa-dollar-sign'></i>
20+
<div class='info-label'><i class='fa-solid fa-dollar-sign'></i>
2021
<div class='balance'></div>
2122
</div>
2223

@@ -64,11 +65,8 @@
6465
</div>
6566
</div>
6667

67-
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
6868
<script src='nui://game/ui/jquery.js' type='text/javascript'></script>
6969
<script src='script.js'></script>
70-
<link rel='stylesheet' href='https://pro.fontawesome.com/releases/v5.15.4/css/all.css' crossorigin='anonymous'/>
71-
7270
</body>
7371

7472
</html>

0 commit comments

Comments
 (0)