-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
108 lines (92 loc) · 4.36 KB
/
Copy pathclient.lua
File metadata and controls
108 lines (92 loc) · 4.36 KB
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
local isProcessing = false
-- Client-side Debugger
local function DebugLog(msg)
if Config.Debug then print("^4[DEBUG - CLIENT]^7 " .. msg) end
end
-- Anim Dictionary Loader
local function loadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(5)
end
end
-- Create Blips
Citizen.CreateThread(function()
for _, loc in pairs(Config.Locations) do
local blip = AddBlipForCoord(loc.coords)
SetBlipSprite(blip, loc.blip.sprite)
SetBlipColour(blip, loc.blip.color)
SetBlipScale(blip, loc.blip.scale)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(loc.label)
EndTextCommandSetBlipName(blip)
end
end)
-- Main Thread (Highly Optimized)
Citizen.CreateThread(function()
while true do
local sleep = 1000
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, false)
if vehicle ~= 0 and GetPedInVehicleSeat(vehicle, -1) == playerPed and not isProcessing then
local coords = GetEntityCoords(playerPed)
for i, loc in pairs(Config.Locations) do
local dist = #(coords - loc.coords)
if dist < 15.0 then
sleep = 0
DrawMarker(1, loc.coords.x, loc.coords.y, loc.coords.z - 1.0, 0,0,0,0,0,0, 3.5, 3.5, 1.0, 45, 110, 200, 100, false, false, 2)
if dist < 3.5 then
local helpTxt = (loc.canRepair and loc.canWash) and Config.Messages['both_help'] or (loc.canRepair and Config.Messages['help_repair'] or Config.Messages['help_wash'])
ESX.ShowHelpNotification(string.format(helpTxt, "Calculated", Config.Economy.washPrice))
if IsControlJustReleased(0, Config.Keys.repair) and loc.canRepair then
TriggerServerEvent('autorepair:requestService', NetworkGetNetworkIdFromEntity(vehicle), i, "repair", GetVehicleEngineHealth(vehicle))
elseif IsControlJustReleased(0, Config.Keys.wash) and loc.canWash then
TriggerServerEvent('autorepair:requestService', NetworkGetNetworkIdFromEntity(vehicle), i, "wash")
end
end
end
end
end
Citizen.Wait(sleep)
end
end)
RegisterNetEvent('autorepair:startAction')
AddEventHandler('autorepair:startAction', function(sType, time, netId)
local veh = NetToVeh(netId)
local playerPed = PlayerPedId()
isProcessing = true
DebugLog("Action Started: " .. sType .. " Duration: " .. time)
if sType == "repair" and Config.Effects.exitVehicle then
TaskLeaveVehicle(playerPed, veh, 0)
Citizen.Wait(2000)
if Config.Effects.openHood then SetVehicleDoorOpen(veh, 4, false, false) end
local hoodCoords = GetOffsetFromEntityInWorldCoords(veh, 0.0, 2.5, 0.0)
TaskGoToCoordAnyMeans(playerPed, hoodCoords.x, hoodCoords.y, hoodCoords.z, 1.0, 0, 0, 786603, 0xbf800000)
Citizen.Wait(2000)
loadAnimDict("mini@repair")
TaskPlayAnim(playerPed, "mini@repair", "fixing_a_ped", 8.0, -8.0, -1, 1, 0, false, false, false)
end
if Config.Effects.playSounds then
local soundName = (sType == "repair") and "WELDING_LOOP" or "Water_Splash_In_Tank"
local soundDict = (sType == "repair") and "WELDING_SOUNDS" or "METAL_PLANT_SOUNDS"
PlaySoundFromEntity(-1, soundName, veh, soundDict, 0, 0)
end
if Config.ProgressBar == "ox_lib" and GetResourceState('ox_lib') == 'started' then
exports.ox_lib:progressBar({duration = time, label = Config.Messages['working'], disable = { car = true, move = true }})
else
Citizen.Wait(time)
end
ClearPedTasks(playerPed)
if sType == "repair" then
SetVehicleFixed(veh)
SetVehicleEngineHealth(veh, 1000.0)
if Config.Effects.openHood then SetVehicleDoorShut(veh, 4, false) end
else
SetVehicleDirtLevel(veh, 0.0)
end
ESX.ShowNotification(Config.Messages['done'])
isProcessing = false
end)
RegisterNetEvent('autorepair:notify')
AddEventHandler('autorepair:notify', function(msg) ESX.ShowNotification(msg) end)