I changed up the GoPostal script to do this.
This code could defintely be more optimized. It was something I learned from.
This is client side
--Default Vars
local visits = 1
local l = 0
local area = 0
local onjob = false
local lastjob = false
local missionvan = GetHashKey('burrito')
local missionplate = math.random(1, 99)
local carspawned = false
function LocalPed()
return GetPlayerPed(-1)
end
function deleteCar(entity)
Citizen.InvokeNative( 0xEA386986E786A54F, Citizen.PointerValueIntInitialized(entity) )
end
-- test
-- end test
function missionSpawnVan()
if (IsOnFoot()) and carspawned == false then
Citizen.Wait(0)
RequestModel(missionvan)
while not HasModelLoaded(missionvan) do
Wait(1)
end
Poolvan = CreateVehicle(missionvan, 168.942, -1515.798, 29.142, 134.971, true, false)
SetVehicleOnGroundProperly(Poolvan)
SetVehicleNumberPlateText(Poolvan, "OBPS " ..missionplate)
SetVehicleColours(Poolvan, 255,255,255,255,255,255)
SetVehicleLivery(Poolvan, 4)
SetVehRadioStation(Poolvan, "OFF")
SetPedIntoVehicle(LocalPed(), Poolvan, - 1)
SetVehicleEngineOn(Poolvan, true, false, false)
-- Car Blip Name
local mvanb = "Pool Service Vehicle"
maintvanblip = (AddBlipForEntity(Poolvan))
SetBlipSprite(maintvanblip, 225)
SetBlipColour(maintvanblip, 38)
SetBlipAsShortRange(maintvanblip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(mvanb)
EndTextCommandSetBlipName(maintvanblip)
--
carspawned = true
elseif carspawned == true then
deleteCar(Poolvan)
carspawned = false
end
end
function DisplayHelpText(str)
SetTextComponentFormat("STRING")
AddTextComponentString(str)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
function poolnotify(str)
SetNotificationTextEntry("STRING");
AddTextComponentString(str);
DrawNotification(false, true);
end
--Destinations and payouts
local spool = 95
local mpool = 100
local bpool = 125
local xpool = 200
local destination = {
-- Debug Destinations
{ x = 871.696, y = -3203.44, z = 5.90074, money = 420},
{ x = 874.072, y = -3225.93, z = 5.89348, money = 420},
-- Pool Destinations
{ x = 302.823, y = 454.267, z = 142.859, money = spool },
{ x = 291.208, y = 499.652, z = 148.180, money = xpool },
{ x = 290.015, y = 527.417, z = 152.618, money = mpool },
{ x = 221.487, y = 486.659, z = 140.682, money = mpool },
{ x = 162.679, y = 481.095, z = 142.267, money = bpool },
{ x = 107.425, y = 439.796, z = 142.215, money = spool },
{ x = 29.885, y = 433.686, z = 142.920, money = mpool },
{ x = -16.148, y = 453.061, z = 146.095, money = spool },
{ x = -67.307, y = 466.557, z = 137.594, money = spool },
{ x = -114.294, y = 477.699, z = 137.031, money = mpool },
{ x = -181.978, y = 479.701, z = 133.749, money = spool },
{ x = -231.701, y = 464.534, z = 126.822, money = spool },
{ x = -282.626, y = 460.363, z = 110.963, money = spool },
{ x = -318.944, y = 518.422, z = 121.426, money = spool },
{ x = -352.294, y = 552.465, z = 126.981, money = spool },
{ x = -453.066, y = 570.658, z = 125.879, money = spool },
{ x = -471.085, y = 511.821, z = 121.462, money = spool },
{ x = -441.966, y = 509.942, z = 119.910, money = spool },
{ x = -404.004, y = 479.914, z = 120.300, money = mpool },
{ x = -375.030, y = 447.959, z = 113.711, money = spool },
{ x = -425.023, y = 435.320, z = 113.102, money = mpool },
{ x = -470.616, y = 429.321, z = 103.161, money = spool },
{ x = -1132.272, y = 605.823, z = 104.395, money = mpool },
{ x = -1301.145, y = 496.388, z = 97.655, money = mpool },
{ x = -1323.354, y = 517.052, z = 104.617, money = spool },
{ x = -1384.086, y = 511.442, z = 121.027, money = mpool },
{ x = -1523.551, y = 394.236, z = 107.483, money = mpool },
{ x = -1674.331, y = 365.414, z = 84.586, money = mpool },
{ x = -1712.687, y = 371.631, z = 89.825, money = bpool },
{ x = -2043.716, y = 515.758, z = 106.818, money = mpool },
{ x = -2020.979, y = 599.263, z = 117.615, money = mpool },
{ x = -1999.168, y = 652.423, z = 122.307, money = mpool },
{ x = -1875.973, y = 658.372, z = 130.000, money = mpool },
{ x = -1606.677, y = 776.107, z = 189.243, money = bpool },
{ x = -1158.153, y = 369.877, z = 69.397, money = mpool },
{ x = -1186.350, y = 317.267, z = 69.449, money = mpool },
{ x = -1318.897, y = 356.693, z = 64.078, money = bpool },
{ x = -1474.263, y = 168.039, z = 55.890, money = xpool },
{ x = -1483.017, y = 15.410, z = 54.024, money = mpool },
{ x = -1495.101, y = -49.506, z = 54.618, money = bpool },
{ x = -102.249, y = -337.190, z = 42.152, money = bpool },
{ x = -789.044, y = 183.153, z = 72.835, money = mpool },
{ x = -889.376, y = 172.257, z = 69.441, money = bpool },
{ x = -885.164, y = 99.287, z = 54.716, money = mpool }, -- 43
-- Maintenance Office
}
RegisterNetEvent("nomaint")
AddEventHandler("nomaint", function()
poolnotify("~r~You are not allowed!" );
end)
function yesmaint()
missionSpawnVan()
startjob()
poolnotify("~g~Be safe with the heavy equipment!" );
end
RegisterNetEvent("yesmaint")
AddEventHandler("yesmaint", function()
missionSpawnVan()
startjob()
poolnotify("~g~Be safe with the heavy equipment!" );
end)
RegisterNetEvent("animnow")
AddEventHandler('animnow', function()
Citizen.CreateThread(function()
local pid = PlayerPedId()
RequestAnimDict("amb@world_human_gardener_plant@male@idle_a")
while (not HasAnimDictLoaded("amb@world_human_gardener_plant@male@idle_a")) do Citizen.Wait(1000) end
ClearPedTasks(pid)
TaskPlayAnim(pid,"amb@world_human_gardener_plant@male@idle_a","idle_a",1.0,-1.0, 15000, 0, 1, true, true, true)
end)
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if GetDistanceBetweenCoords(167.921, -1506.714, 29.253, GetEntityCoords(GetPlayerPed(-1))) < 50.0 then
DrawMarker(1, 167.921, -1506.714, 29.253 - 1, 0, 0, 0, 0, 0, 0, 2.0001, 2.0001, 1.0001, 255, 165, 0,165, 0, 0, 0,0) --- The Maintenance Location
if GetDistanceBetweenCoords(167.921, -1506.714, 29.253, GetEntityCoords(LocalPed())) < 0.999 then
basiccheck()
end
end
-- Check if player is in correct vehicle
if carspawned == true then
if IsPedSittingInAnyVehicle(LocalPed()) then
if not IsPedSittingInVehicle(LocalPed(), Poolvan) then
jobcancelled()
end
end
end
-- end Check
if onjob == true then
DrawMarker(1, destination[l].x,destination[l].y,destination[l].z - 1, 0, 0, 0, 0, 0, 0, 1.0001, 1.0001, 0.5001, 0, 97, 255,165, 0, 0, 0,0)
if GetDistanceBetweenCoords(destination[l].x,destination[l].y,destination[l].z, GetEntityCoords(GetPlayerPed(-1))) < 1.0 then
DisplayHelpText("Press ~INPUT_PICKUP~ to maintain the ~b~pool~w~.")
if (IsControlJustReleased(1, 38)) then
TriggerServerEvent('startanim')
Wait(17000)
maintsuccess()
end
end
local xrect = 0.5000
local yrect = 0.0500
function drawTxt(x,y ,width,height,scale, text, r,g,b,a)
SetTextFont(0)
SetTextProportional(0)
SetTextScale(scale, scale)
SetTextColour(r, g, b, a)
SetTextDropShadow(0, 0, 0, 0,255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x - width/2, y - height/2 + 0.005)
end
drawTxt(0.517,0.0500,0.2,0.04,0.4,"Press ~g~[ ~w~to skip current pool!",255,255,255,255)
DrawRect(xrect, yrect, 0.19, 0.04, 0, 0, 0, 155)
if (IsControlJustReleased(1, 39)) then
maintskip()
end
end
end
end)
function basiccheck()
if onjob == false and lastjob == false then
if (IsOnFoot()) then
DisplayHelpText("Press ~INPUT_PICKUP~ to start ~b~pool maintenance.")
if (IsControlJustReleased(1, 38)) then
TriggerServerEvent('maintain:startjob')
end
else
DisplayHelpText("You must be ~g~on foot~s~ to start this job")
end
elseif onjob == false and lastjob == true then
if (IsOnFoot()) then
maintfinish()
else
DisplayHelpText("You must be ~g~on foot~s~ to finish this job")
end
else
if (IsOnFoot()) then
DisplayHelpText("Press ~INPUT_PICKUP~ to cancel ~b~pool maintenance~w~ at a ~b~cost~w~!")
if (IsControlJustReleased(1, 38)) then
--print("DESTINATION MONEY = "..destination[l].money) --Debug
TriggerServerEvent('maintain:rmoney', destination[l].money)
--TriggerServerEvent('bank:withdraw', destination[l].money)
onjob = false
RemoveBlip(maintblip)
SetWaypointOff()
visits = 1
poolnotify("~r~You have cancelled the job. You are currently being charged for incomplete work." );
jobcancelled()
end
else
DisplayHelpText("You must be ~g~on foot~s~ to cancel this job")
end
end
end
function jobcancelled()
--print("DESTINATION MONEY = "..destination[l].money) --Debug
TriggerServerEvent('maintain:rmoney', destination[l].money)
--TriggerServerEvent('bank:withdraw', destination[l].money)
onjob = false
lastjob = false
RemoveBlip(maintblip)
SetWaypointOff()
visits = 1
poolnotify("~r~You have cancelled the job. You are currently being charged for incomplete work." );
missionSpawnVan()
end
function IsOnFoot()
local ply = GetPlayerPed(-1)
if IsPedOnFoot(ply) then
return true
else
return false
end
end
function startjob()
DisplayHelpText("Go to the marked ~g~area~w~ to maintain the pool.")
onjob = true
--[[ Multiple Maintenance Jobs
if pooljob == true then
area = math.random(1,10)
elseif maintjob == true then
area1 = math.random(1,10)
end
]]--
--Debug--
area = 1
---------
if area == 1 then
l = math.random(3,44)
end
maintblip = (AddBlipForCoord(destination[l].x,destination[l].y,destination[l].z))
SetBlipSprite(maintblip, 280)
SetNewWaypoint(destination[l].x,destination[l].y)
end
function maintsuccess()
TriggerServerEvent('maintain:success',destination[l].money)
if visits == 5 then --change 5 to however many runs you want a person to be able to make before having to return to the depot
RemoveBlip(maintblip)
onjob = false
lastjob = true
basiccheck()
DisplayHelpText("Return to the ~g~depot~w~ to finish your job.")
else
RemoveBlip(maintblip)
startjob()
visits = visits + 1
DisplayHelpText("You have finished this ~g~pool~w~! Go to the next marked ~g~pool~w~!")
end
end
function maintskip()
if visits == 5 then --change 5 to however many runs you want a person to be able to make before having to return to the depot
onjob = false
lastjob = false
RemoveBlip(maintblip)
SetWaypointOff()
visits = 1
missionSpawnVan()
DisplayHelpText("You have skipped the job.")
else
RemoveBlip(maintblip)
startjob()
visits = visits + 1
DisplayHelpText("You have skipped this pool!")
end
end
function maintfinish()
if lastjob == true then
if GetDistanceBetweenCoords(167.921, -1506.714, 29.253, GetEntityCoords(GetPlayerPed(-1))) < 50.0 then
if GetDistanceBetweenCoords(167.921, -1506.714, 29.253, GetEntityCoords(GetPlayerPed(-1))) < 0.999 then
DisplayHelpText("Press ~INPUT_PICKUP~ to finish the ~b~pool~w~ job.")
if (IsControlJustReleased(1, 38)) then
maintstop()
missionSpawnVan()
poolnotify("~g~You have completed this job!" );
Wait(1000)
poolnotify("~g~$500 has been added to your bank account!" );
end
end
end
end
end
function maintstop()
RemoveBlip(maintblip)
visits = 1
lastjob = false
onjob = false
end
local blips = {
{title="O.B. Pool Services", colour=38, id=446, x=167.921, y= -1506.714, z=0},
}
Citizen.CreateThread(function()
for _, info in pairs(blips) do
info.blip = AddBlipForCoord(info.x, info.y, info.z)
SetBlipSprite(info.blip, info.id)
SetBlipDisplay(info.blip, 4)
SetBlipScale(info.blip, 0.9)
SetBlipColour(info.blip, info.colour)
SetBlipAsShortRange(info.blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(info.title)
EndTextCommandSetBlipName(info.blip)
end
end)
This is Server side
RegisterServerEvent('maintain:startjob')
AddEventHandler('maintain:startjob', function()
TriggerClientEvent('yesmaint', source)
end)
RegisterServerEvent('maintain:rmoney')
AddEventHandler('maintain:rmoney', function(price)
print("Money has been withdrawn from your account!")
end)
--Essential payment functions
RegisterServerEvent('maintain:success')
AddEventHandler('maintain:success', function(price)
print("Money has been added to your wallet!")
end)
RegisterServerEvent('startanim')
AddEventHandler('startanim', function()
TriggerClientEvent('animnow', source)
end)