Hey man, I wanted to make something just like this and took apart your script to use as the base. I made a few optimizations I can send you if you’d like to see. I noticed you update this script a lot and had comments for some nice features so I added those. For example, your VehiclePartsRemoval() can basically be done with
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn( ped, false )
local doors = GetNumberOfVehicleDoors(vehicle)
for i = 0,doors do
if DoesVehicleHaveDoor(vehicle, i) then
SetVehicleDoorShut(vehicle, i, false )
Wait(2000)
SetVehicleDoorOpen(vehicle, i, false, false)
Wait(5000)
SetVehicleDoorBroken(vehicle, i, true)
end
end
That just checks any vehicle for its max doors and checks if the door is attached, if so then close it then open it fully, wait and then delete.
I was able to remove the functions you used to check for passengers and used this function
function butts(vehicle)
local meh = GetVehicleNumberOfPassengers(vehicle)
return meh
end
local seats = butts(vehicle)
if seats ~= 0 then
TriggerEvent('chat:addMessage', { args = { '[^1Chopshop^0]: Cannot chop with passengers' } })
end
I did that cause I don’t care if they are actually the driver, I just don’t want more than one person in the car to be able to start a 2nd chop process while this one is active. I also use that function again before I reward the player to make sure they are still a lone in the car at the end of the chop process. The cooldown callback prevents this as well.
For the cooldown you can take a look at esx_advancedrobbery and see how that resource uses os.timer() to make a cooldown. I made this callback to make the chopshop usable once every hour. This way its just a 1 time check instead of using your cooldown manager.
local TimeBeforeNewRob = 3600
local lastrobbed = 0
ESX.RegisterServerCallback('Lenzh_chopshop:isCooldown',function(source, cb)
if lastrobbed ~= 0 and (os.time() - lastrobbed) < TimeBeforeNewRob then
--local timerNewRob = TimeBeforeNewRob - (os.time() - lastrobbed)
--print('timeleft is '..timerNewRob)
cb(true)
else
cb(false)
end
end)
The cooldown is triggered when the client begins the actual chop process with
client:
TriggerServerEvent('Lenzh_chopshop:BerryTime')
which is this on the server side
server:
RegisterServerEvent('Lenzh_chopshop:BerryTime')
AddEventHandler('Lenzh_chopshop:BerryTime', function()
lastrobbed = os.time()
end)
Instead of copying esx_outlawalert into your script, if you look at the newest releast of it you can see an update for isPlayerWhitelisted. You can most likely make a function within that resource which returns true if whitelisted and then export that function into your chopshop for a cop check and trigger a blip to them with that.
Some other stuff I had is moving your markers and blips off to a separate markers.lua, adding a vehicle class check to only allow certain vehicle types, and some other fluff. Keep in mind, if you spawn an NPC like that and people use a default esx_drugstonpc or a mugging script, they can sell and mug that NPC again and again. You are also going to want to change the way you prevent players from driving the vehicle after starting the chop process.
I wouldn’t use
SetVehicleUndriveable(vehicle, false)
If someone disconnects, crashes or drops while chopping I am pretty sure this leaves the vehicle stuck in the marker and a normal client wont be able to start or move it.
Try something like this instead, I think this should work. You can probably slim this function down even more.
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
if turnEngineOff then
local nowVehicle = GetVehiclePedIsIn(PlayerPedId())
if nowVehicle then
SetVehicleEngineOn(nowVehicle, false, false, true)
end
if (not IsPedInAnyVehicle(PlayerPedId(), false) and turnEngineOff) then
currentlyChopping = false
turnEngineOff = false
end
end
end
end)
I used currentlyChopping as my global variable and you can just set turnEngineOff = true/false if you wanna toggle the engine. We can prevent players from manually turning the engine on and driving off with that. This also checks if a player leaves the vehicle after starting the job and cancels it if they did.
Thanks for releasing this, hopefully this helps you out for the next update. I’ll send you the full resource just message me.