Jump to content

[HELP] Fix Destroy Vehicles


Sr.black

Recommended Posts

Please Help me to fix the script dont working 

the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please?

client:

function onVehicleStuckInWater(vehicle)
  local delay = 4 -- in seconds
  timer.start(delay, function()
    destroyVehicle(vehicle)
  end)
end

 

server:

local vehiclesInWater = {}

function onVehicleEnterWater(vehicle)
  vehiclesInWater[vehicle] = true
end

function onVehicleLeaveWater(vehicle)
  vehiclesInWater[vehicle] = nil
end

function onTick()
  for vehicle, _ in ipairs(vehiclesInWater) do
    local z = getVehicleZ(vehicle)
    if z < -1.5 then
      triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle)
    end
  end
end

 

Edited by Sr.black
Link to comment
2 hours ago, Sr.black said:

Please Help me to fix the script dont working 

the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please?

client:

function onVehicleStuckInWater(vehicle)
  local delay = 4 -- in seconds
  timer.start(delay, function()
    destroyVehicle(vehicle)
  end)
end

 

server:

local vehiclesInWater = {}

function onVehicleEnterWater(vehicle)
  vehiclesInWater[vehicle] = true
end

function onVehicleLeaveWater(vehicle)
  vehiclesInWater[vehicle] = nil
end

function onTick()
  for vehicle, _ in ipairs(vehiclesInWater) do
    local z = getVehicleZ(vehicle)
    if z < -1.5 then
      triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle)
    end
  end
end

 

but I created a piece of code for you, maybe it will help you,
 

local vehicleChecker

function checkVehiclesInWater()
   for _,vehicle in ipairs(getElementsByType("vehicle")) do
         if isElementInWater(vehicle) then
         destroyElement(vehicle)
         end
   end
end
vehicleChecker = setTimer(checkVehiclesInWater, 4000, 0)

I don't understand exactly what you are trying to do, I didn't understand anything when I examined your code

Link to comment
On 16/09/2023 at 12:27, Sr.black said:

Please Help me to fix the script dont working 

the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please?

client:

function onVehicleStuckInWater(vehicle)
  local delay = 4 -- in seconds
  timer.start(delay, function()
    destroyVehicle(vehicle)
  end)
end

 

server:

local vehiclesInWater = {}

function onVehicleEnterWater(vehicle)
  vehiclesInWater[vehicle] = true
end

function onVehicleLeaveWater(vehicle)
  vehiclesInWater[vehicle] = nil
end

function onTick()
  for vehicle, _ in ipairs(vehiclesInWater) do
    local z = getVehicleZ(vehicle)
    if z < -1.5 then
      triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle)
    end
  end
end

 

you forgot to use addEvent for your function to work when you want to trigger it
 

Client
 

function onVehicleStuckInWater(vehicle)
  local delay = 4 -- in seconds
  timer.start(delay, function()
    destroyVehicle(vehicle)
  end)
end
addEvent("onVehicleStuckInWater", true)
addEventHandler("onVehicleStuckInWater", root, onVehicleStuckInWater)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...