So far I have only come across scripts that lock ALL AI vehicles. Does anyone know if there is one for say 50% of AI vehicles chance to be locked? Both parked and driving? This would make car jacking a lot more risky (say someone is on the run) and just more immersive since most cars IRL lock when you go above a certain speed anyways.
Looking for non-esx - standalone.
I’m aware there are some lockpick scripts. But that is silly. If you are car jacking a moving vehicle sitting there trying to hotwire or lockpick it makes no sense when someone was… just driving it lol.
There was this but its super old and apparently broken. Plus its a lock pick script which isnt the same thing. It also uses .net .dll file which cant be edited easily. Sigh.
--- server
-- if not using lua5.4, you may need this
math.randomseed(os.time())
AddEventHandler('entityCreated', function(entity)
local entityType = GetEntityType(entity)
-- not a vehicle? bail out
if entityType ~= 2 then return end
-- only for 'random' population cars
if GetEntityPopulationType(entity) > 5 then return end
-- if >0.5 (50% chance of locking), bail out
if math.random() > 0.5 then return end
-- lock!
SetVehicleDoorsLocked(entity, 2)
end)
would i just put this into a server.lua in a directory and ensure the resource (sorry im new to scripting resources) or was this an addition to the above script
One question, if you guys know… is it possible to create an if statement where say if the window is broken (such as someone shoots the driver and breaks the window) that you can reach in and unlock (just like the animation when you break a window while stealing a parked car and then reach in - minus the breaking of the window with your elbow part) or is that not possible?
b1db08d is GetEntityType - Natives @ Cfx.re Docs. The error means that by the time GetEntityType() ran, the entity was not valid anymore (maybe deleted?)
We can try to check if the vehicle exists first, before running the event code, like this:
--- server
-- if not using lua5.4, you may need this
math.randomseed(os.time())
AddEventHandler('entityCreated', function(entity)
--not valid anymore? skedaddle
if not DoesEntityExist(entity) then return end
--[[ rest of core remains the same ]]
local entityType = GetEntityType(entity)
-- not a vehicle? bail out
if entityType ~= 2 then return end
-- only for 'random' population cars
if GetEntityPopulationType(entity) > 5 then return end
-- if >0.5 (50% chance of locking), bail out
if math.random() > 0.5 then return end
-- lock!
SetVehicleDoorsLocked(entity, 2)
end)
If you mean adjust as in another native that would work server side, then none. There are only a few natives that work server sided most don’t really interact with players, more for external data fetching. Take a look here: Native Reference - Cfx.re Docs
Hahaha, I didn’t test anything but when I typed here it was like 5 am about 30 seconds before I fell asleep. Yeah probably should have checked but the general point I was trying to get at was most natives only work on the client side with a select few that work on the server side as well (again check docs like I should have hahaha)