i want to remove player money if they dont make the delivery.
How can i do that? What are the code for that?
client.lua
ESX = nil
local PlayerData, startBlip, working = {}, nil, false
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId,xPlayer)
PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
end)
Citizen.CreateThread(function()
while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Wait(0) end
while ESX.GetPlayerData().job == nil do Wait(0) end
PlayerData = ESX.GetPlayerData()
while true do
local me, sleep, hasjob = PlayerPedId(), 250, true
if Config.Job['jobRequired'] then
if PlayerData.job.name ~= Config.Job['jobName'] then
hasjob = false
end
end
if working then hasjob = false end
if hasjob then
if not DoesBlipExist(startBlip) then
startBlip = addBlip(Config.JobCenter, 632, 44, Strings['start_job'])
end
else
if DoesBlipExist(startBlip) then
RemoveBlip(startBlip)
end
end
local distance = GetDistanceBetweenCoords(GetEntityCoords(me), Config.JobCenter, true)
if distance <= 25.0 and hasjob then
sleep = 0
DrawMarker(39, Config.JobCenter, vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 100, 0, 150, false, false, 2, false, false, false)
if distance <= 1.5 then
helpText(Strings['e_browse_jobs'])
if IsControlJustReleased(0, 38) then
TriggerServerEvent('esx_ets:jobMenu')
end
end
end
Wait(sleep)
end
end)
local van = true
RegisterNetEvent('esx_ets:start')
AddEventHandler('esx_ets:start', function(data, jobid)
working = true
local truck, trailer = loadVehicle(data.vehicles[1], data.start[1], data.start[2]), loadVehicle(data.vehicles[2], data.trailer[1], data.trailer[2])
local destinationBlip, truckBlip, trailerBlip = addBlip(data.arrive, 38, 3, Strings['destination'])
while true do
local sleep, distance = 250, GetDistanceBetweenCoords(data.arrive, GetEntityCoords(trailer), true)
if not IsPedInVehicle(PlayerPedId(), truck, false) then
text(Strings['get_to_truck'], 250)
if not DoesBlipExist(truckBlip) then
truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck'])
SetBlipRoute(truckBlip, true)
end
van =true
if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end
if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
else
gametime = GetGameTimer()
seconds = 15 -- max time (seconds) you want to set
printtime = seconds
Citizen.CreateThread(function()
while van do
Citizen.Wait(0)
if printtime > 0 then
diftime = GetGameTimer() - gametime
printtime = math.floor(seconds - (diftime/1000))
if printtime >= 10 then
drawTxt(" ")
else
drawTxt("SZĂLLJ VISSZA A KAMINODBA! MĂ©g van: " .. printtime .. " mĂĄsodperced! kĂŒlönben levonunk: ~r~-1000$")
end
else
RemoveBlip(truckBlip)
DeleteVehicle(trailer)
RemoveBlip(destinationBlip)
RemoveBlip(trailerBlip)
DeleteVehicle(truck)
working = false
TriggerServerEvent('esx_ets:PayBill60Zone');
end
end
end)
if not IsVehicleAttachedToTrailer(truck, trailer) then
text(Strings['get_to_trailer'], 250)
if not DoesBlipExist(trailerBlip) then
trailerBlip = addBlip(GetEntityCoords(trailer), 479, 5, Strings['trailer'])
SetBlipRoute(trailerBlip, true)
end
if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
else
if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end
if not DoesBlipExist(destinationBlip) then
destinationBlip = addBlip(data.arrive, 38, 3, Strings['destination'])
SetBlipRoute(destinationBlip, true)
end
end
if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
end
if distance <= 45.0 and IsPedInVehicle(PlayerPedId(), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then
sleep = 0
DrawMarker(1, data.arrive, vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false)
if distance <= 10.0 then
while IsVehicleAttachedToTrailer(truck, trailer) do
text(Strings['detach'], 250)
Wait(250)
end
break
else
text(Strings['park'])
end
else
if IsPedInVehicle(PlayerPedId(), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then
text(Strings['drive_destination'], 250)
end
end
Wait(sleep)
end
DeleteVehicle(trailer)
RemoveBlip(destinationBlip)
RemoveBlip(trailerBlip)
RemoveBlip(truckBlip)
TriggerServerEvent('esx_ets:jobFinished', jobid, damages)
while true do
local sleep, distance = 250, GetDistanceBetweenCoords(GetEntityCoords(truck), data.start[1], true)
if not IsPedInVehicle(PlayerPedId(), truck, false) and distance >= 10.0 then
text(Strings['get_to_truck'], 250)
van=true
if not DoesBlipExist(truckBlip) then
truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck'])
SetBlipRoute(truckBlip, true)
end
van=true
if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
else
gametime = GetGameTimer()
seconds = 65 -- max time (seconds) you want to set
printtime = seconds
Citizen.CreateThread(function()
while van do
Citizen.Wait(0)
if printtime > 0 then
diftime = GetGameTimer() - gametime
printtime = math.floor(seconds - (diftime/1000))
if printtime >= 60 then
drawTxt(" ")
else
drawTxt("SZĂLLJ VISSZA A KAMINODBA! MĂ©g van: " .. printtime .. " mĂĄsodperced! kĂŒlönben levonunk: ~r~-1000$")
end
else
DeleteVehicle(trailer)
RemoveBlip(destinationBlip)
RemoveBlip(trailerBlip)
RemoveBlip(truckBlip)
DeleteVehicle(truck)
working = false
text(Strings['failed'])
end
end
end)
if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
if not DoesBlipExist(destinationBlip) then
destinationBlip = addBlip(data.start[1], 38, 3, Strings['destination'])
SetBlipRoute(destinationBlip, true)
end
if distance <= 30.0 then
sleep = 0
DrawMarker(1, data.start[1], vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false)
if distance <= 10.0 then
if IsPedInVehicle(PlayerPedId(), truck, false) then
text(Strings['get_out'])
else
if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
break
end
else
text(Strings['park_truck'])
end
else
text(Strings['drive_back'], 250)
end
end
Wait(sleep)
end
local damages = {['windows'] = {}, ['tires'] = {}, ['doors'] = {}, ['body_health'] = GetVehicleBodyHealth(truck), ['engine_health'] = GetVehicleEngineHealth(truck)}
for i = 0, GetVehicleNumberOfWheels(truck) do
if IsVehicleTyreBurst(truck, i, false) then table.insert(damages['tires'], i) end
end
for i = 0, 13 do
if not IsVehicleWindowIntact(truck, i) then table.insert(damages['windows'], i) end
end
for i = 0, GetNumberOfVehicleDoors(truck) do
if IsVehicleDoorDamaged(truck, i) then table.insert(damages['doors'], i) end
end
van =false
DeleteVehicle(truck)
working = false
TriggerServerEvent('esx_ets:jobFinished', jobid, damages)
end)
RegisterNetEvent('esx_ets:menu')
AddEventHandler('esx_ets:menu', function(data)
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'choose_job',
{
title = Strings['menu_title'],
align = 'center',
elements = data
},
function(data, menu)
TriggerServerEvent('esx_ets:startJob', data.current.value)
menu.close()
end,
function(data, menu)
menu.close()
end)
end)
text = function(text, duration)
ClearPrints()
BeginTextCommandPrint('STRING')
AddTextComponentSubstringPlayerName(text)
EndTextCommandPrint(duration, 2)
end
loadVehicle = function(vehicle, coords, heading)
local model
if type(vehicle) == 'number' then model = vehicle else model = GetHashKey(vehicle) end
while not HasModelLoaded(model) do Wait(0) RequestModel(model) end
local car = CreateVehicle(model, coords, heading, true, false)
SetEntityAsMissionEntity(car, true, true)
return car
end
helpText = function(msg)
BeginTextCommandDisplayHelp('STRING')
AddTextComponentSubstringPlayerName(msg)
EndTextCommandDisplayHelp(0, false, true, 1)
end
addBlip = function(coords, sprite, colour, text)
local blip = AddBlipForCoord(coords)
SetBlipSprite(blip, sprite)
SetBlipColour(blip, colour)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(text)
EndTextCommandSetBlipName(blip)
return blip
end
function drawTxt(content)
SetTextFont(4)
SetTextScale(0.6, 0.6)
SetTextColour(255,255,255, 255)
SetTextEntry("STRING")
SetTextDropShadow(0, 0, 0, 0,255)
SetTextDropShadow()
SetTextEdge(4, 0, 0, 0, 255)
SetTextOutline()
AddTextComponentString(content)
DrawText(0.17,0.02 )
end
server.lua
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
for k, v in pairs(Config.Jobs) do
v['taken'] = false
end
RegisterServerEvent('esx_ets:startJob')
AddEventHandler('esx_ets:startJob', function(id)
local xPlayer, hasJob = ESX.GetPlayerFromId(source), true
if Config.Job['jobRequired'] then
if xPlayer.job.name == Config.Job['jobName'] then
hasJob = true
else
hasJob = false
end
end
if hasJob then
if not Config.Jobs[id]['taken'] then
Config.Jobs[id]['taken'] = true
TriggerClientEvent('esx_ets:start', xPlayer.source, Config.Jobs[id], id)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, Strings['somebody_doing'])
end
else
TriggerClientEvent('esx:showNotification', xPlayer.source, Strings['not_job'])
end
end)
RegisterServerEvent('esx_ets:jobMenu')
AddEventHandler('esx_ets:jobMenu', function()
local elements, xPlayer = {}, ESX.GetPlayerFromId(source)
for k, v in pairs(Config.Jobs) do
if not v['taken'] then
table.insert(elements, {label = v.title, value = k})
end
end
TriggerClientEvent('esx_ets:menu', xPlayer.source, elements)
end)
RegisterServerEvent('esx_ets:jobFinished')
AddEventHandler('esx_ets:jobFinished', function(id, damages)
local xPlayer = ESX.GetPlayerFromId(source)
if Config.Jobs[id]['taken'] then
local price, health = Config.Jobs[id].payment, (damages['body_health'] + damages['engine_health']) / 2
for k, v in pairs(damages['windows']) do health = health - 30 end
for k, v in pairs(damages['tires']) do health = health - 35 end
for k, v in pairs(damages['doors']) do health = health - 40 end
if health <= 900 and health > 800 then price = price - 50 elseif health <= 800 and health > 700 then price = price - 75 elseif health <= 700 and health > 600 then price = price - 100 elseif health <= 600 and health > 300 then price = price - 150 elseif health <= 300 then price = price - 350 end
if price >= 0 then
xPlayer.addMoney(price)
TriggerClientEvent('esx:showNotification', xPlayer.source, (Strings['reward']):format(price))
else
xPlayer.removeMoney(price)
TriggerClientEvent('esx:showNotification', xPlayer.source, (Strings['paid_damages']):format(price))
end
Wait(Config.ReAdd * 1000)
Config.Jobs[id]['taken'] = false
end
end)
RegisterServerEvent('esx_ets:PayBill60Zone')
AddEventHandler('esx_ets:PayBill60Zone', function()
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeMoney(100)
end)