-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.lua
212 lines (184 loc) · 7.74 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
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
QBCore = nil
local QBCore = exports['qb-core']:GetCoreObject()
RegisterCommand("mechanic", function(source, args) -- Modify the "mechanic" value to change activation command.
QBCore.Functions.TriggerCallback('knb:mechOnline', function(MechOnline, hasEnoughMoney)
if MechOnline <= Config.Mechanic and hasEnoughMoney then
TriggerServerEvent('knb:charge')
ShowNotification("Mechanic is arriving")
TriggerEvent("knb:mech")
else
if MechOnline > Config.Mechanic then
ShowNotification("There are too many mechanics online", "error")
elseif not hasEnoughMoney then
ShowNotification("Not Enough Money", "error")
else
ShowNotification("Call for a Mechanic", "primary")
end
end
end)
end)
AddEventHandler("knb:mech", function()
player = GetPlayerPed(-1)
playerPos = GetEntityCoords(player)
local inFrontOfPlayer = GetOffsetFromEntityInWorldCoords(player, 0.0, 5.0, 0.0)
local targetVeh = GetTargetVehicle(player, inFrontOfPlayer)
GetMechPed()
local driverhash = GetHashKey(mechPedPick.model)
RequestModel(driverhash)
local vehhash = GetHashKey(mechPedPick.vehicle)
RequestModel(vehhash)
loadAnimDict("cellphone@")
while not HasModelLoaded(driverhash) and RequestModel(driverhash) or not HasModelLoaded(vehhash) and RequestModel(vehhash) do
RequestModel(driverhash)
RequestModel(vehhash)
Citizen.Wait(0)
end
if DoesEntityExist(targetVeh) then
if DoesEntityExist(mechVeh) then
DeleteVeh(mechVeh, mechPed)
SpawnVehicle(playerPos.x, playerPos.y, playerPos.x, vehhash, driverhash)
else
SpawnVehicle(playerPos.x, playerPos.y, playerPos.x, vehhash, driverhash)
end
playRadioAnim(player)
GoToTarget(GetEntityCoords(targetVeh).x, GetEntityCoords(targetVeh).y, GetEntityCoords(targetVeh).z, mechVeh, mechPed, vehhash, targetVeh)
end
end)
function SpawnVehicle(x, y, z, vehhash, driverhash) --Spawning Function
local found, spawnPos, spawnHeading = GetClosestVehicleNodeWithHeading(x + math.random(-spawnRadius, spawnRadius), y + math.random(-spawnRadius, spawnRadius), z, 0, 3, 0)
if found and HasModelLoaded(vehhash) and HasModelLoaded(vehhash) then
mechVeh = CreateVehicle(vehhash, spawnPos, spawnHeading, true, false) --Car Spawning.
ClearAreaOfVehicles(GetEntityCoords(mechVeh), 5000, false, false, false, false, false);
SetVehicleOnGroundProperly(mechVeh)
SetVehicleColours(mechVeh, mechPedPick.colour, mechPedPick.colour)
mechPed = CreatePedInsideVehicle(mechVeh, 26, driverhash, -1, true, false) --Driver Spawning.
mechBlip = AddBlipForEntity(mechVeh) --Blip Spawning.
SetBlipFlashes(mechBlip, true)
SetBlipColour(mechBlip, 5)
end
end
function DeleteVeh(vehicle, driver)
SetEntityAsMissionEntity(vehicle, false, false) --Car Removal
DeleteEntity(vehicle)
SetEntityAsMissionEntity(driver, false, false) --Driver Removal
DeleteEntity(driver)
RemoveBlip(mechBlip) --Blip Removal
end
function GoToTarget(x, y, z, vehicle, driver, vehhash, target)
TaskVehicleDriveToCoord(driver, vehicle, x, y, z, 17.0, 0, vehhash, drivingStyle, 1, true)
ShowAdvancedNotification(companyIcon, companyName, "Mechanic Dispatched", "A mechanic has been dispatched to your location. Thanks for using ~y~" .. companyName)
enroute = true
while enroute do
Citizen.Wait(500)
distanceToTarget = GetDistanceBetweenCoords(GetEntityCoords(target), GetEntityCoords(vehicle).x, GetEntityCoords(vehicle).y, GetEntityCoords(vehicle).z, true)
if simplerRepair then
if distanceToTarget < 20 then
TaskVehicleTempAction(driver, vehicle, 27, 6000)
Citizen.Wait(3000)
RepairVehicle(target, vehicle, driver)
end
else
if distanceToTarget < 20 then
TaskVehicleTempAction(driver, vehicle, 27, 6000)
SetVehicleUndriveable(vehicle, true)
GoToTargetWalking(target, vehicle, driver)
end
end
end
end
function GoToTargetWalking(target, vehicle, driver)
while enroute do
Citizen.Wait(500)
engine = GetWorldPositionOfEntityBone(target, GetEntityBoneIndexByName(target, "engine"))
TaskGoToCoordAnyMeans(driver, engine, 2.0, 0, 0, 786603, 0xbf800000)
distanceToTarget = GetDistanceBetweenCoords(engine, GetEntityCoords(driver).x, GetEntityCoords(driver).y, GetEntityCoords(driver).z, true)
norunrange = false
if distanceToTarget <= 10 and not norunrange then -- stops ai from sprinting when close
TaskGoToCoordAnyMeans(driver, engine, 1.0, 0, 0, 786603, 0xbf800000)
norunrange = true
end
if distanceToTarget <= 2 then
SetVehicleUndriveable(target, true)
TaskTurnPedToFaceCoord(driver, GetEntityCoords(target), -1)
Citizen.Wait(1000)
TaskStartScenarioInPlace(driver, "PROP_HUMAN_BUM_BIN", 0, 1)
SetVehicleDoorOpen(target, 4, false, false)
Citizen.Wait(10000)
ClearPedTasks(driver)
RepairVehicle(target, vehicle, driver)
end
end
end
function RepairVehicle(target, vehicle, driver)
enroute = false
norunrange = false
FreezeEntityPosition(driver, false)
SetVehicleDoorShut(target, 4, false, false)
Citizen.Wait(500)
ShowAdvancedNotification(mechPedPick.icon, mechPedPick.name, "Vehicle Repaired" , mechPedPick.lines[math.random(#mechPedPick.lines)])
if repairComsticDamage then
SetVehicleFixed(target)
else
SetVehicleEngineHealth(target, 1000.0)
end
if flipVehicle then
SetVehicleOnGroundProperly(target)
end
SetVehicleUndriveable(target, false)
Citizen.Wait(5000)
LeaveTarget(vehicle, driver)
end
function LeaveTarget(vehicle, driver)
TaskVehicleDriveWander(driver, vehicle, 17.0, drivingStyle)
SetEntityAsNoLongerNeeded(vehicle)
SetPedAsNoLongerNeeded(driver)
RemoveBlip(mechBlip)
mechVeh = nil
mechPed = nil
targetVeh = nil
end
function GetTargetVehicle(player, dir)
if IsPedSittingInAnyVehicle(player) then
dmgVeh = GetVehiclePedIsIn(player, false)
else
dmgVeh = GetVehicleInDirection(GetEntityCoords(player), dir)
end
if DoesEntityExist(dmgVeh) then
return dmgVeh
else
ShowNotification("Failed to find a vehicle.")
end
end
function GetMechPed()
mechPedPick = mechPeds[math.random(#mechPeds)]
end
function GetVehicleInDirection(coordFrom, coordTo)
local rayHandle = CastRayPointToPoint( coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed(-1), 0)
local _, _, _, _, vehicle = GetRaycastResult(rayHandle)
return vehicle
end
function playRadioAnim(player)
Citizen.CreateThread(function()
RequestAnimDict(arrests)
TaskPlayAnim(player, "cellphone@", "cellphone_call_in", 1.5, 2.0, -1, 50, 2.0, 0, 0, 0 )
Citizen.Wait(6000)
ClearPedTasks(player)
end)
end
function loadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(0)
end
end
function ShowAdvancedNotification(icon, sender, title, text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
SetNotificationMessage(icon, icon, true, 4, sender, title, text)
DrawNotification(false, true)
end
function ShowNotification(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end