[DarkRP 2.5] Remove vehicle on job change (TDM/SGM Cars)

Hi,

Been trying to work out how to remove cars from a player if they change jobs.

So far I have TEAM_POLICE, TEAM_SWAT, TEAM_CHIEF and TEAM_MEDIC with some TDM/SGM cars each to buy in F4 menu, that works fine but if you change job the vehicles stay there. As these are cop/ambulance vehicles I want to have them removed.

I tried this in a .lua loaded in darkrp’s addon modules but didn’t do anything


hook.Add("OnPlayerChangedTeam", "asdf", function(ply)
        for k,v in pairs(ents.FindByClass("07sgmcrownviccvpi", "07sgmcrownvicuc", "c5500ambulance")) do
            if v.allowed and type(v.allowed) == "table" and table.HasValue(v.allowed, t) then continue end
            if v.SID == ply.SID then v:Remove() end
        end

end)

Ok tried it again by adding individual code for each car but that doesn’t work too.

I’m putting this in lua autorun so assume that’s right?

Did you found a fix yet ?

Not yet :slight_smile:

Hello nzkfc, the fix is simple and easy.

I had the same Problem and found a fix after 6 hours searching and trying new Codes.

The Fix is just make a New .lua in the autorun/server


hook.Add("OnPlayerChangedTeam", "asdf", function(ply)
        for k,v in pairs(ents.FindByClass("prop_vehicle_jeep")) do
            if v.allowed and type(v.allowed) == "table" and table.HasValue(v.allowed, t) then continue end
            if v.SID == ply.SID then v:Remove() end
        end

end)

In every .lua your Cars is a class defined like that


Class = "prop_vehicle_jeep"

The Problem is, the entity can’t be found because it’s a vehicle, just remove the prop like i posted the Code :slight_smile:
Works on my Server fine!
I hope i could help you ! :smiley:

Thanks,

So that “asdf” would be “TEAM_POLICE, TEAM_SWAT, TEAM_CHIEF, TEAM_PARAMEDIC” ?

Cheers

No the asdf ist just the Name of that Code, lol you can type everything in it !

the prop_vehicle_jeep removes all TDM Cars on job change, TDM Cars are based on the prop_vehicle_jeep

Ah right,

However I want it for specific jobs, how can I do that.

e.g. if you change from: TEAM_SWAT, TEAM_POLICE, TEAM_CHIEF, TEAM_PARAMEDIC it removes any of their vehicles.

I have some cars via the F4 menu for these jobs, normal players spawn their cars via the NPC

Another question would be, can I then only target specific cars from the TDM pack to remove if they have them spawned.