2026-04-14 17:41:39 +02:00

79 lines
2.7 KiB
Lua

RegisterNetEvent("advancedgarages:client:repairVehicle")
AddEventHandler("advancedgarages:client:repairVehicle", function()
local pedCoords = GetEntityCoords(cache.ped)
local currentVehicle = GetVehiclePedIsIn(cache.ped, false)
if currentVehicle ~= 0 then
RepairVehicleEntity(currentVehicle)
return
end
local foundNearby = false
for _, vehicle in pairs(GetGamePool("CVehicle")) do
if vehicle ~= currentVehicle then
local dist = #(pedCoords - GetEntityCoords(vehicle))
if dist <= 5.0 then
foundNearby = true
RepairVehicleEntity(vehicle)
break
end
end
end
if not foundNearby then
Notification(i18n.t("no_vehicle_nearby"), "error")
end
end)
function RepairVehicleEntity(vehicle)
local plate = GetVehicleNumberPlateText(vehicle)
SetVehicleFixed(vehicle)
SetVehicleDeformationFixed(vehicle)
SetVehicleUndriveable(vehicle, false)
TriggerServerEvent("VehicleDeformation:fix_sv", NetworkGetNetworkIdFromEntity(vehicle))
Notification(i18n.t("repair.repaired", { plate = plate }), "success")
Debug("The vehicle with registration number [" .. plate .. "] was repaired")
end
function RepairSpecificVehicle(targetPlate)
for _, vehicle in ipairs(GetGamePool("CVehicle")) do
local plate = GetVehicleNumberPlateText(vehicle)
if plate == targetPlate then
RepairVehicleEntity(vehicle)
return
end
end
Warning("You did not specify the plate correctly, check the value of plate")
end
exports("RepairSpecificVehicle", RepairSpecificVehicle)
local function RepairNearestVehicle()
TriggerEvent("advancedgarages:client:repairVehicle")
end
exports("RepairNearestVehicle", RepairNearestVehicle)
RegisterNetEvent("advancedgarages:client:onUse")
AddEventHandler("advancedgarages:client:onUse", function()
local pedCoords = GetEntityCoords(cache.ped)
if IsPedInAnyVehicle(cache.ped, false) then return end
local nearestVehicle = lib.getClosestVehicle(pedCoords, 5.0)
if nearestVehicle and DoesEntityExist(nearestVehicle) then
RepairAnimation(nearestVehicle)
RepairVehicleEntity(nearestVehicle)
else
Notification(i18n.t("no_vehicle_nearby"), "error")
end
end)
function RepairAnimation(vehicle)
TriggerServerEvent("advancedgarages:server:removeKit")
lib.requestAnimDict("mini@repair")
TaskPlayAnim(cache.ped, "mini@repair", "fixing_a_player", 8.0001, -8.0001, -1, 0, 0, 0, 0, 0)
SetVehicleDoorOpen(vehicle, 4, false, false)
Wait(15000)
ClearPedTasksImmediately(cache.ped)
RemoveAnimDict("mini@repair")
SetVehicleDoorShut(vehicle, 4, false)
end