Vehicle spawn protection

I want to make if player in the vehicle then vehicle have no collision so the players can’t block each other’s for 5 seconds after the vehicle spawned.

I’ve tried NetworkFadeOutEntity - NetworkFadeInEntity it’s working but I can’t see the car until the NetworkFadeInEntity is getting activated, it’s possible to keep the car visible or flashing while the NetworkFadeOutEntity is running?

RegisterCommand('protect', function(protect)
  local ped = GetPlayerPed(-1)
  local veh = GetVehiclePedIsUsing(ped)
  if veh then
	 NetworkFadeOutEntity(veh, true, false) 
     Citizen.Wait(5000)
     NetworkFadeInEntity(veh, 0)
  end
end, false)

hello bro
For collision : SetEntityCollision(ndh, true)

If I set the collision to false I just falling out of the world… if true then still just block the vehicles each other.

1 Like

hey, try using NetworkSetPlayerIsPassive or SetNetworkVehicleAsGhost, one of them might do what you want, i’ve never used them so i don’t know if they’ll actually do what you want

Ummm how can I use the SetNetworkVehicleAsGhost ? Is this a server-sided function or client-sided?

if I try it in client-side it’s says:

attempt to call a nil value global 'SetNetworkVehicleAsGhost

in server-side returns nothing but doesn’t works - see below.


Client side:

RegisterCommand('protect', function(veh)
  local ped = GetPlayerPed(-1)
  local veh = GetVehiclePedIsUsing(ped)
  if veh then
	 TriggerServerEvent("car:protect", veh)
  end
end, false)

Server side:

RegisterServerEvent('car:protect')
AddEventHandler('car:protect', function(veh)
	SetNetworkVehicleAsGhost(veh, true)
end)

it should be client-side
if you are still using __resource.lua, check if you have set the manifest version
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' <- that

Okay, now I get no errors. But I can’t make it work.

This is just spawning a car and that’s all. What do I do wrong?

local vehicle = GetHashKey('speedo')
local spawned_car = CreateVehicle(vehicle, spawncar.x,spawncar.y,spawncar.z, 431.436, - 996.786, 25.1887, true, false)
SetNetworkVehicleAsGhost(spawned_car, true)

i think you need to use VehToNet(spawned_car) insted of the normal vehicle handle, not completely sure about that tho, give it a try
SetNetworkVehicleAsGhost(VehToNet(spawned_car), true)

Thank you, but still the same. Just spawn a car and the car have collision so the vehicles block each others.

The only thing is working is the NetworkFadeOutEntity (this removes the vehicle collision while the vehicle is invisible) but that’s set the vehicle to invisible until the NetworkFadeInEntity is not executed. Can I do somehow the car still get flashing or visible (like ghost or smth) after the NetworkFadeOutEntity ?

NetworkFadeOutEntity(spawned_car, 1)
Citizen.Wait(5000)
NetworkFadeInEntity(spawned_car, 1)

you might be able to get the vehicle to show up by using SetEntityVisible or a similiar native

If I do that then the vehicle have collision after NetworkFadeOutEntity