-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
151 lines (138 loc) · 4.59 KB
/
client.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
NDCore = exports["ND_Core"]:GetCoreObject()
local selectedBike
local ped
local pedCoords
local rentedBikes = {}
-- Functions
function distanceFromPed(coords)
return #(pedCoords - coords)
end
CreateThread(function()
for _, location in pairs(Config.locations) do
local blip = AddBlipForCoord(location)
SetBlipSprite(blip, 494)
SetBlipColour(blip, 26)
SetBlipScale(blip, 0.6)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Bike Rental")
EndTextCommandSetBlipName(blip)
end
while true do
Wait(500)
ped = PlayerPedId()
pedCoords = GetEntityCoords(ped)
vehicle = GetVehiclePedIsIn(ped)
end
end)
function getBikes()
local bikes = {}
for id, bike in pairs(Config.cycles) do
bikes[#bikes + 1] = {
title = bike.name,
onSelect = function(args)
selectedBike = id
TriggerServerEvent("bikeRental:pay", id)
end,
metadata = {
{label = 'Price', value = bike.price},
}
}
end
return bikes
end
RegisterNetEvent("bikeRental:confirm")
AddEventHandler("bikeRental:confirm", function()
if not selectedBike then return end
local bike = Config.cycles[selectedBike]
RequestModel(bike.hash)
while not HasModelLoaded(bike.hash) do
Wait(10)
end
local veh = CreateVehicle(bike.hash, pedCoords.x, pedCoords.y, pedCoords.z, GetEntityHeading(ped), true, true)
SetPedIntoVehicle(ped, veh, -1)
lib.hideTextUI()
selectedBike = nil
lib.notify({
title = 'Purchase Successful',
description = 'You purchased ' .. bike.name .. ". - $" .. bike.price,
position = 'bottom',
type = "success"
})
rentedBikes[veh] = veh
end)
RegisterNetEvent("bikeRental:deny")
AddEventHandler("bikeRental:deny", function()
if not selectedBike then return end
selectedBike = nil
lib.notify({
title = 'Purchase Error',
description = 'Not enough cash. - $' .. bike.price .. " needed.",
position = 'bottom',
style = {
backgroundColor = '#141517',
color = '#909296'
},
icon = 'ban',
iconColor = '#C53030'
})
end)
-- Rentals
lib.registerContext({ -- Rentals select menu
id = 'cycles_menu',
title = 'Choose your bike',
options = getBikes(),
})
local checked = false
local notified = false
Citizen.CreateThread(function()
local wait = 500
while true do
Wait(wait)
if not IsPlayerDead(player) then
for _, locations in pairs(Config.locations) do
local dist = distanceFromPed(locations)
if dist < 1.0 then
wait = 0
if not notified then
if rentedBikes[vehicle] then
lib.showTextUI('[E] - Return Bike')
elseif vehicle == 0 then
lib.showTextUI('[E] - Open Rentals')
end
notified = true
end
if IsControlJustPressed(0, 51) then
if rentedBikes[vehicle] then
DeleteEntity(vehicle)
lib.notify({
title = 'Bike Returned',
description = "Thank you for returning the bike!",
position = 'bottom',
type = "success"
})
elseif vehicle == 0 then
lib.showContext('cycles_menu')
end
wait = 500
end
break
elseif dist < 6.5 then
wait = 0
DrawMarker(38, locations.x, locations.y, locations.z - 0.2, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 46, 121, 242, 255, false, true, false, false)
if notified then
lib.hideTextUI()
notified = false
end
break
else
if notified then
lib.hideTextUI()
notified = false
end
wait = 500
end
end
end
end
end)