Jump to content

Cancel vehicle explosion


AMARANT

Recommended Posts

client.lua

addEventHandler("onClientVehicleExplode", getRootElement(), function() 
    cancelEvent() 
end) 

or

server.lua

addEventHandler("onVehicleExplode", getRootElement(), function() 
    cancelEvent() 
end) 

other example

addEventHandler ( "onClientVehicleExplode", getRootElement(), cancelEvent ) --  predefined variable "cancelEvent" 

Link to comment
client.lua
addEventHandler("onClientVehicleExplode", getRootElement(), function() 
    cancelEvent() 
end) 

or

server.lua

addEventHandler("onVehicleExplode", getRootElement(), function() 
    cancelEvent() 
end) 

other example

addEventHandler ( "onClientVehicleExplode", getRootElement(), cancelEvent ) --  predefined variable "cancelEvent" 

[b]Note:[/b] Remember, this event can not be canceled.  

Link to comment

Try this:

  
addEventHandler ( "onClientVehicleDamage", root, function ( ) 
      -- If you want it to take damage, but not explode -- 
      -- if getElementHealth ( source ) < 300 then         -- dunno if 300 is good, test it 
            local rx,ry = getElementRotation ( source ) 
            if rx > 90 and rx < 270 or ry > 90 and ry < 270 then  
                  cancelEvent() 
                  -- If it was burning before -- 
                  if getElementHealth ( source ) < 300 then 
                        setElementHealth ( source, 300 )       -- dunno if 300 is good, test it 
                  end 
            end    
      --end 
end ) 

I think onClientVehicleDamage should be triggered when the vehicle gets damage when its on the roof.

Link to comment
  • 2 weeks later...

I can spawn a vehicle after blowing up at the right coordinates and make it damage proof. But before that the vehicle needs to be blow up anyway. And I'd like to completely remove blowing up. Is this possible? Here is my code what I've got:

function onVehiclesExplode() 
local model = getElementModel(source) 
local x, y, z = getElementPosition(source) 
local rx,ry,rz = getElementRotation(source) 
destroyElement(source) 
setTimer(spawnAfterExplode,50,1,model,x,y,z,rx,ry,rz) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehiclesExplode) 
  
function spawnAfterExplode(model,x,y,z,rx,ry,rz) 
local newvehicle = createVehicle(model,x,y,z,rx,ry,rz) 
setVehicleDamageProof(newvehicle,true) 
end 

Link to comment
onClientVehicleDamage

fixVehicle ( vehicleValue )

As soon as it gets damaged use fixVehicle, it will stop it from blowing up and what not.

--- This --- When missiles hit vehicle the vehicle does not explode that instant, instead there is a small delay, if you use fix vehicle as soon as the vehicle gets damaged, then the vehicle won't go boom.

Link to comment
onClientVehicleDamage

fixVehicle ( vehicleValue )

As soon as it gets damaged use fixVehicle, it will stop it from blowing up and what not.

--- This --- When missiles hit vehicle the vehicle does not explode that instant, instead there is a small delay, if you use fix vehicle as soon as the vehicle gets damaged, then the vehicle won't go boom.

If you're not running an RP server, sure. If it's a RP script, good luck saving all the panel states, door states, wheel states, current damage and set it all back when someone hits the vehicle with their fists, an AK or something like that.

Even by saying that, in an RPG server players are most likely going to ram each other, f*ck up their friends with guns and sh*t. You're going to use fixVehicle every single bullet? That's going to be insanely CPU killing.

I can spawn a vehicle after blowing up at the right coordinates and make it damage proof. But before that the vehicle needs to be blow up anyway. And I'd like to completely remove blowing up. Is this possible? Here is my code what I've got:
function onVehiclesExplode() 
local model = getElementModel(source) 
local x, y, z = getElementPosition(source) 
local rx,ry,rz = getElementRotation(source) 
destroyElement(source) 
setTimer(spawnAfterExplode,50,1,model,x,y,z,rx,ry,rz) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehiclesExplode) 
  
function spawnAfterExplode(model,x,y,z,rx,ry,rz) 
local newvehicle = createVehicle(model,x,y,z,rx,ry,rz) 
setVehicleDamageProof(newvehicle,true) 
end 

It should be removed by destroyElement. Maybe add a timer for that one too, or first set the dimension to something random, and delete it after 1 second.

Link to comment
Oh yes, forgot about that "posted both of those at 1 am wasn't exactly thinking about that atm, when the vehicle health drops below a certain point, use repair vehicle, as to prevent it from exploding, yet still allowing it to be hit, rammed etc without repairing every time.

As an easier thing; just make the vehicle damage proof when the health drops below 400. :lol:

Link to comment
Oh yes, forgot about that "posted both of those at 1 am wasn't exactly thinking about that atm, when the vehicle health drops below a certain point, use repair vehicle, as to prevent it from exploding, yet still allowing it to be hit, rammed etc without repairing every time.

As an easier thing; just make the vehicle damage proof when the health drops below 400. :lol:

Yes it really works but how about server CPU if I use it server-side with "onVehicleDamage"?

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...