forked from esx-framework/esx_banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
261 lines (230 loc) · 8.46 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
local BANK = {
Data = {}
}
local activeBlips, bankPoints, atmPoints, markerPoints = {}, {}, {}, {}
local playerLoaded, uiActive, inMenu = false, false, false
--Functions
-- General data collecting thread
function BANK:Thread()
self:CreateBlips()
local data = self.Data
data.ped = PlayerPedId()
data.coord = GetEntityCoords(data.Ped)
playerLoaded = true
CreateThread(function ()
while playerLoaded do
data.coord = GetEntityCoords(data.ped)
data.ped = PlayerPedId()
bankPoints, atmPoints, markerPoints = {}, {}, {}
if (IsPedOnFoot(data.ped) and not ESX.PlayerData.dead) and not inMenu then
for i = 1, #Config.AtmModels do
local atm = GetClosestObjectOfType(data.coord.x, data.coord.y, data.coord.z, 0.7, Config.AtmModels[i], false, false, false)
if atm ~= 0 then
atmPoints[#atmPoints+1] = GetEntityCoords(atm)
end
end
for i = 1, #Config.Banks do
local bankDistance = #(data.coord - Config.Banks[i].Position.xyz)
if bankDistance <= 0.7 then
bankPoints[#bankPoints+1] = Config.Banks[i].Position.xyz
end
if Config.ShowMarker and bankDistance <= (Config.DrawMarker or 10) then
markerPoints[#markerPoints+1] = Config.Banks[i].Position.xyz
end
end
end
if next(bankPoints) and not uiActive then
self:TextUi(true)
end
if next(atmPoints) and not uiActive then
self:TextUi(true, true)
end
if not next(bankPoints) and not next(atmPoints) and uiActive then
self:TextUi(false)
end
Wait(1000)
end
end)
if not Config.ShowMarker then return end
CreateThread(function()
local wait = 1000
while playerLoaded do
if next(markerPoints) then
for i = 1, #markerPoints do
DrawMarker(20, markerPoints[i].x, markerPoints[i].y, markerPoints[i].z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.2, 187, 255, 0, 255, false, true, 2, false, nil, nil, false)
end
wait = 0
end
Wait(wait)
end
end)
end
-- Handle text ui / Keypress
function BANK:TextUi(state, atm)
uiActive = state
if not state then
return ESX.HideUI()
end
ESX.TextUI(TranslateCap('press_e_banking'))
CreateThread(function()
while uiActive do
if IsControlJustReleased(0, 38) then
self:HandleUi(true, atm)
self:TextUi(false)
end
Wait(0)
end
end)
end
-- Create Blips
function BANK:CreateBlips()
local tmpActiveBlips = {}
for i = 1, #Config.Banks do
if type(Config.Banks[i].Blip) == 'table' and Config.Banks[i].Blip.Enabled then
local position = Config.Banks[i].Position
local bInfo = Config.Banks[i].Blip
local blip = AddBlipForCoord(position.x, position.y, position.z)
SetBlipSprite(blip, bInfo.Sprite)
SetBlipScale(blip, bInfo.Scale)
SetBlipColour(blip, bInfo.Color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(bInfo.Label)
EndTextCommandSetBlipName(blip)
tmpActiveBlips[#tmpActiveBlips + 1] = blip
end
end
activeBlips = tmpActiveBlips
end
-- Remove blips
function BANK:RemoveBlips()
for i = 1, #activeBlips do
if DoesBlipExist(activeBlips[i]) then
RemoveBlip(activeBlips[i])
end
end
activeBlips = {}
end
-- Open / Close ui
function BANK:HandleUi(state, atm)
atm = atm or false
SetNuiFocus(state, state)
inMenu = state
ClearPedTasks(PlayerPedId())
if not state then
SendNUIMessage({
showMenu = false
})
return
end
ESX.TriggerServerCallback('esx_banking:getPlayerData', function(data)
SendNUIMessage({
showMenu = true,
openATM = atm,
datas = {
your_money_panel = {
accountsData = {{
name = "cash",
amount = data.money
}, {
name = "bank",
amount = data.bankMoney
}}
},
bankCardData = {
bankName = TranslateCap('bank_name'),
cardNumber = "2232 2222 2222 2222",
createdDate = "08/08",
name = data.playerName
},
transactionsData = data.transactionHistory
}
})
end)
end
function BANK:LoadNpc(index, netID)
CreateThread(function()
while not NetworkDoesEntityExistWithNetworkId(netID) do
Wait(200)
end
local npc = NetworkGetEntityFromNetworkId(netID)
TaskStartScenarioInPlace(npc, Config.Peds[index].Scenario, 0, true)
SetEntityProofs(npc, true, true, true, true, true, true, true, true)
SetBlockingOfNonTemporaryEvents(npc, true)
FreezeEntityPosition(npc, true)
SetPedCanRagdollFromPlayerImpact(npc, false)
SetPedCanRagdoll(npc, false)
SetEntityAsMissionEntity(npc, true, true)
SetEntityDynamic(npc, false)
end)
end
-- Events
RegisterNetEvent('esx_banking:closebanking', function()
BANK:HandleUi(false)
end)
RegisterNetEvent('esx_banking:PedHandler', function(netIdTable)
for i = 1, #netIdTable do
BANK:LoadNpc(i, netIdTable[i])
end
end)
RegisterNetEvent('esx_banking:updateMoneyInUI', function(doingType, bankMoney, money)
SendNUIMessage({
updateData = true,
data = {
type = doingType,
bankMoney = bankMoney,
money = money
}
})
end)
-- Handlers
-- Resource starting
AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
BANK:Thread()
end)
-- Enable the script on player loaded
RegisterNetEvent('esx:playerLoaded', function()
BANK:Thread()
end)
-- Disable the script on player logout
RegisterNetEvent('esx:onPlayerLogout', function()
playerLoaded = false
end)
-- Resource stopping
AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
BANK:RemoveBlips()
if uiActive then BANK:TextUi(false) end
end)
RegisterNetEvent('esx:onPlayerDeath', function() BANK:TextUi(false) end)
-- Nui Callbacks
RegisterNUICallback('close', function(data, cb)
BANK:HandleUi(false)
cb('ok')
end)
RegisterNUICallback('clickButton', function(data, cb)
if not data or not inMenu then
return cb('ok')
end
TriggerServerEvent("esx_banking:doingType", data)
cb('ok')
end)
RegisterNUICallback('checkPincode', function(data, cb)
if not data or not inMenu then
return cb('ok')
end
ESX.TriggerServerCallback("esx_banking:checkPincode", function(pincode)
if pincode then
cb({
success = true
})
ESX.ShowNotification(TranslateCap('pincode_found'), "success")
else
cb({
error = true
})
ESX.ShowNotification(TranslateCap('pincode_not_found'), "error")
end
end, data)
end)