[Release] Vehicle Clean Up (UPDATED v2)


#1

This was requested here, so I made it quickly. This script cleans up all unused vehicles automatically

Download is here

Thanks to @MarkViolla, I could improve this script alot, both in functionality and size. Now instead of having to enter a command in the console, the cars will automatically dissapear when the game thinks it doesn’t need it anymore. Also players can noclip into spawned cars to remove them too.

Installation is as usual, put it into the resources folder, then edit the AutoStartResources in your server-config.

client.lua

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1)
        car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
        
        if car then
            Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(car))
        end
    end
end)

[Release] Scammer's Script Collection (09/03/17)
Vehicle Cleanup
[Release] Vehicle shop by Arturs
Cleaning the dusts on the cars
#2

removing vehicles “works”, see my recent post here.

A fix for this that doesnt require modification of the natives.lua, is calling the function by its hash.

instead of

DeleteVehicle(vehicleID)

use

Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(vehicleID))

#3

Oh, I’ll try it out soon. Thanks!


#4

np gl :slight_smile:


#5

This does actually not work


#6

except… it does?

it’s kind of pathetic that a project ‘administrator’ claims things that do work ‘do not work’ if someone posts it as a solution.

if the client the code runs on owns said entity, this function will work fine.


#7

It does work :stuck_out_tongue: its the same call that it makes in natives.lua


#8

Also, chill out, no need to get spiteful


#9

We’ve come to a semi-conclusion it only works if the vehicle you are trying to delete was created in the same resource instance.


#10

The way he’s doing it adds any vehicle the player is in to a list and stores the vehicle ID, so it should work. The only issue as your talking about is keeping track of the vehicle IDs that have been spawned. The only issue that could arrise here is if two players get in the same vehicle, itll try to delete the vehicle from both clients and may cause errors


#11

why are you not using SetEntityAsNoLongerNeeded after car spawn?
It is easy and simple instead this long script…Look at my Taxi Work script in release section for example.


#12

Is it implemented in 5R? I read that this wasn’t implemented so I wasn’t sure if I could just do it that way.

Edit: Well if it’s apparently implemented I’ll do it that way then lol. Thanks!


#13

Are you talking about SetEntityAsNoLongerNeeded?


#14

Yeah I was talking about the SetEntityAsNoLongerNeeded


#15

find in my taxi script line with hash of this native, to see how it works. Hash is : 0xB736A491E64A32CF


#16

Alright, I’ll take a look at it once I’m on my PC again. Thanks!


#17

Doesn’t want to seem to work when I add it to some of my servers get a error about a recourse or something when attempting to join the server.


#18

Could you PM me the error you’re getting and your console log?


#19

Script updated. Thanks to @MarkViolla for pointing out a nice native that already does this job. :smiley:


#21

This works perfectly on cars spawned by my scripts, but when I do it on cars spawned from a trainer it don’t work.