forked from esx-framework/esx_boat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
241 lines (207 loc) · 7.1 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
isInShopMenu = false
local spawnedVehicles = {}
function OpenBoatShop(shop)
isInShopMenu = true
local playerPed = PlayerPedId()
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('boat_shop')}
}
for k,v in ipairs(Config.Vehicles) do
elements[#elements+1] = {
icon = "fas fa-ship",
title = ('%s - <span style="color:green;">$%s</span>'):format(v.label, ESX.Math.GroupDigits(v.price)),
name = v.label,
model = v.model,
price = v.price,
props = v.props or nil
}
end
ESX.OpenContext("right", elements, function(menu,element)
local elements2 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-eye", title = "View", val = "view"}
}
ESX.OpenContext("right", elements2, function(menu2,element2)
if element2.val == "view" then
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(element.model, shop.Inside, shop.Inside.w, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
if element.props then
ESX.Game.SetVehicleProperties(vehicle, element.props)
end
local elements3 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-check-double", title = "Buy", value = "buy"},
{icon = "fas fa-eye", title = "Stop Viewing", value = "stop"}
}
ESX.OpenContext("right", elements3, function(menu3,element3)
if element3.value == "buy" then
local plate = exports['esx_vehicleshop']:GeneratePlate()
local vehicle = GetVehiclePedIsIn(playerPed, false)
local props = ESX.Game.GetVehicleProperties(vehicle)
props.plate = plate
ESX.TriggerServerCallback('esx_boat:buyBoat', function(bought)
if bought then
ESX.ShowNotification(TranslateCap('boat_shop_bought', element.name, ESX.Math.GroupDigits(element.price)))
DeleteSpawnedVehicles()
isInShopMenu = false
ESX.CloseContext()
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
else
ESX.ShowNotification(TranslateCap('boat_shop_nomoney'))
end
end, props)
elseif element3.value == "stop" then
reset(shop)
end
end, function ()
reset(shop)
end)
end)
end
end, function(menu)
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end, function(menu)
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end
function OpenBoatGarage(garage)
ESX.TriggerServerCallback('esx_boat:getGarage', function (ownedBoats)
if #ownedBoats == 0 then
ESX.ShowNotification(TranslateCap('garage_noboats'))
else
-- get all available boats
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('garage')}
}
for i=1, #ownedBoats, 1 do
ownedBoats[i] = json.decode(ownedBoats[i])
elements[#elements+1] = {
icon = "fas fa-ship",
title = getVehicleLabelFromHash(ownedBoats[i].model),
vehicleProps = ownedBoats[i]
}
end
ESX.OpenContext("right", elements, function(menu,element)
local playerPed = PlayerPedId()
local vehicleProps = element.vehicleProps
if ESX.Game.IsSpawnPointClear(garage.SpawnPoint, 4.0) then
TriggerServerEvent('esx_boat:takeOutVehicle', vehicleProps.plate)
ESX.ShowNotification(TranslateCap('garage_taken'))
ESX.Game.SpawnVehicle(vehicleProps.model, garage.SpawnPoint, garage.SpawnPoint.w, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
end)
ESX.CloseContext()
else
ESX.ShowNotification(TranslateCap('garage_blocked'))
end
end, function(menu)
CurrentAction = 'garage_out'
CurrentActionMsg = TranslateCap('garage_open')
end)
end
end)
end
function OpenLicenceMenu(shop)
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('license_menu')},
{icon = "fas fa-ship", title = "Purchase Boat License"}
}
ESX.OpenContext("right", elements, function(menu,element)
local elements2 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-check-double", title = TranslateCap('license_buy_yes', Config.LicensePrice), val = "yes"},
{icon = "fas fa-window-close", title = TranslateCap('license_buy_no'), val = "no"}
}
ESX.OpenContext("right", elements2, function(menu2,element2)
-- If the value is no, close the menu and stop the script.
if element2.val == "no" then
ESX.CloseContext()
return;
end
ESX.TriggerServerCallback('esx_boat:buyBoatLicense', function (boughtLicense)
if boughtLicense then
ESX.ShowNotification(TranslateCap('license_bought', ESX.Math.GroupDigits(Config.LicensePrice)))
ESX.CloseContext()
OpenBoatShop(shop) -- parse current shop
else
ESX.ShowNotification(TranslateCap('license_nomoney'))
end
end)
end, function(menu)
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end, function(menu)
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end
function StoreBoatInGarage(vehicle, teleportCoords)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('esx_boat:storeVehicle', function (rowsChanged)
if rowsChanged > 0 then
ESX.Game.DeleteVehicle(vehicle)
ESX.ShowNotification(TranslateCap('garage_stored'))
local playerPed = PlayerPedId()
ESX.Game.Teleport(playerPed, teleportCoords, function()
SetEntityHeading(playerPed, teleportCoords.w)
end)
else
ESX.ShowNotification(TranslateCap('garage_notowner'))
end
end, vehicleProps.plate)
end
-- Key controls
CreateThread(function()
while true do
Wait(0)
if isInShopMenu then
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
else
Wait(500)
end
end
end)
function DeleteSpawnedVehicles()
while #spawnedVehicles > 0 do
local vehicle = spawnedVehicles[1]
if DoesEntityExist(vehicle) then
ESX.Game.DeleteVehicle(vehicle)
end
table.remove(spawnedVehicles, 1)
end
end
function getVehicleLabelFromHash(hash)
local model = string.lower(GetDisplayNameFromVehicleModel(hash))
for i=1, #Config.Vehicles, 1 do
if Config.Vehicles[i].model == model then
return Config.Vehicles[i].label
end
end
return 'Unknown model [' .. model .. ']'
end
function reset(shop)
local playerPed = PlayerPedId()
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
DeleteSpawnedVehicles()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
ESX.CloseContext()
end