From 433d7655c1875187f04f5677176107d33a100fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Tue, 12 Sep 2017 12:12:41 +0200 Subject: [PATCH] Add health check --- client/main.lua | 180 +++++++++++++++++++++++++----------------------- config.lua | 19 ++--- 2 files changed, 104 insertions(+), 95 deletions(-) diff --git a/client/main.lua b/client/main.lua index e594e2cb..ab2e88f4 100644 --- a/client/main.lua +++ b/client/main.lua @@ -31,114 +31,122 @@ AddEventHandler('esx_property:hasEnteredMarker', function(name, part, parking) if IsPedInAnyVehicle(playerPed, false) then - local vehicle = GetVehiclePedIsIn(playerPed, false) - - if GetPedInVehicleSeat(vehicle, -1) == playerPed then - - local vehicleProps = ESX.Game.GetVehicleProperties(vehicle) - - local spawnCoords = { - x = garage.InteriorSpawnPoint.Pos.x, - y = garage.InteriorSpawnPoint.Pos.y, - z = garage.InteriorSpawnPoint.Pos.z + Config.ZDiff - } - - ESX.Game.DeleteVehicle(vehicle) - - ESX.Game.Teleport(playerPed, spawnCoords, function() - - TriggerEvent('instance:create', 'garage') - - ESX.Game.SpawnLocalVehicle(vehicleProps.model, spawnCoords, garage.InteriorSpawnPoint.Heading, function(vehicle) - TaskWarpPedIntoVehicle(playerPed, vehicle, -1) - ESX.Game.SetVehicleProperties(vehicle, vehicleProps) - end) - - ESX.TriggerServerCallback('esx_vehicleshop:getVehiclesInGarage', function(vehicles) - - for i=1, #garage.Parkings, 1 do - for j=1, #vehicles, 1 do - - if i == vehicles[j].zone then - - local spawn = function(j) - - local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71) - - if DoesEntityExist(vehicle) then - ESX.Game.DeleteVehicle(vehicle) - end - - ESX.Game.SpawnLocalVehicle(vehicles[j].vehicle.model, { - x = garage.Parkings[i].Pos.x, - y = garage.Parkings[i].Pos.y, - z = garage.Parkings[i].Pos.z + Config.ZDiff - }, garage.Parkings[i].Heading, function(vehicle) - ESX.Game.SetVehicleProperties(vehicle, vehicles[j].vehicle) - end) - - end - - spawn(j) - - end - - end - end - - end, name) - - end) + local vehicle = GetVehiclePedIsIn(playerPed, false) + local maxHealth = GetEntityMaxHealth(vehicle) + local health = GetEntityHealth(vehicle) + local healthPercent = (health / maxHealth) * 100 + if healthPercent < Config.MinimumHealthPercent then + ESX.ShowNotification('Vous devez d\'abord réparer votre véhicule') else - ESX.Game.Teleport(playerPed, { - x = garage.InteriorSpawnPoint.Pos.x, - y = garage.InteriorSpawnPoint.Pos.y, - z = garage.InteriorSpawnPoint.Pos.z + Config.ZDiff - }, function() + if GetPedInVehicleSeat(vehicle, -1) == playerPed then - TriggerEvent('instance:create', 'garage') + local vehicleProps = ESX.Game.GetVehicleProperties(vehicle) - ESX.TriggerServerCallback('esx_vehicleshop:getVehiclesInGarage', function(vehicles) + local spawnCoords = { + x = garage.InteriorSpawnPoint.Pos.x, + y = garage.InteriorSpawnPoint.Pos.y, + z = garage.InteriorSpawnPoint.Pos.z + Config.ZDiff + } - for i=1, #garage.Parkings, 1 do - for j=1, #vehicles, 1 do + ESX.Game.DeleteVehicle(vehicle) - if i == vehicles[j].zone then - - local spawn = function(j) + ESX.Game.Teleport(playerPed, spawnCoords, function() - local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71) + TriggerEvent('instance:create', 'garage') + + ESX.Game.SpawnLocalVehicle(vehicleProps.model, spawnCoords, garage.InteriorSpawnPoint.Heading, function(vehicle) + TaskWarpPedIntoVehicle(playerPed, vehicle, -1) + ESX.Game.SetVehicleProperties(vehicle, vehicleProps) + end) + + ESX.TriggerServerCallback('esx_vehicleshop:getVehiclesInGarage', function(vehicles) + + for i=1, #garage.Parkings, 1 do + for j=1, #vehicles, 1 do + + if i == vehicles[j].zone then + + local spawn = function(j) + + local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71) + + if DoesEntityExist(vehicle) then + ESX.Game.DeleteVehicle(vehicle) + end + + ESX.Game.SpawnLocalVehicle(vehicles[j].vehicle.model, { + x = garage.Parkings[i].Pos.x, + y = garage.Parkings[i].Pos.y, + z = garage.Parkings[i].Pos.z + Config.ZDiff + }, garage.Parkings[i].Heading, function(vehicle) + ESX.Game.SetVehicleProperties(vehicle, vehicles[j].vehicle) + end) - if DoesEntityExist(vehicle) then - ESX.Game.DeleteVehicle(vehicle) end - ESX.Game.SpawnLocalVehicle(vehicles[j].vehicle.model, { - x = garage.Parkings[i].Pos.x, - y = garage.Parkings[i].Pos.y, - z = garage.Parkings[i].Pos.z + Config.ZDiff - }, garage.Parkings[i].Heading, function(vehicle) - ESX.Game.SetVehicleProperties(vehicle, vehicles[j].vehicle) - end) + spawn(j) end - spawn(j) + end + end + + end, name) + + end) + + else + + ESX.Game.Teleport(playerPed, { + x = garage.InteriorSpawnPoint.Pos.x, + y = garage.InteriorSpawnPoint.Pos.y, + z = garage.InteriorSpawnPoint.Pos.z + Config.ZDiff + }, function() + + TriggerEvent('instance:create', 'garage') + + ESX.TriggerServerCallback('esx_vehicleshop:getVehiclesInGarage', function(vehicles) + + for i=1, #garage.Parkings, 1 do + for j=1, #vehicles, 1 do + + if i == vehicles[j].zone then + + local spawn = function(j) + + local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71) + + if DoesEntityExist(vehicle) then + ESX.Game.DeleteVehicle(vehicle) + end + + ESX.Game.SpawnLocalVehicle(vehicles[j].vehicle.model, { + x = garage.Parkings[i].Pos.x, + y = garage.Parkings[i].Pos.y, + z = garage.Parkings[i].Pos.z + Config.ZDiff + }, garage.Parkings[i].Heading, function(vehicle) + ESX.Game.SetVehicleProperties(vehicle, vehicles[j].vehicle) + end) + + end + + spawn(j) + + end end - end - end - end, name) + end, name) - end) + end) + + end end - else ESX.Game.Teleport(playerPed, { diff --git a/config.lua b/config.lua index 6bce9fc5..15cb02a5 100644 --- a/config.lua +++ b/config.lua @@ -1,12 +1,13 @@ -Config = {} -Config.DrawDistance = 100.0 -Config.MarkerType = 1 -Config.MarkerSize = {x = 2.0, y = 2.0, z = 1.0} -Config.MarkerColor = {r = 204, g = 204, b = 0} -Config.ParkingMarkerSize = {x = 3.0, y = 3.0, z = 2.0} -Config.ParkingMarkerColor = {r = 102, g = 102, b = 204} -Config.ZDiff = 0.5 -Config.EnableOwnedVehicles = true +Config = {} +Config.DrawDistance = 100.0 +Config.MarkerType = 1 +Config.MarkerSize = {x = 2.0, y = 2.0, z = 1.0} +Config.MarkerColor = {r = 204, g = 204, b = 0} +Config.ParkingMarkerSize = {x = 3.0, y = 3.0, z = 2.0} +Config.ParkingMarkerColor = {r = 102, g = 102, b = 204} +Config.ZDiff = 0.5 +Config.EnableOwnedVehicles = true +Config.MinimumHealthPercent = 0 Config.Locale = 'fr'