Jump to content

onVehicleDemage not working


Xwad

Recommended Posts

why is this code not working? thanks.

server side

  
  
vehicle = createVehicle(564, -2839.9,202,16.9) 
  
function vehicle_demage(source) 
if source == vehicle then    
outPutChatBox("vehicle demaged") 
end 
end 
addEventHandler("onVehicleDamage", root, vehicle_demage) 

Link to comment

First and only parameter onVehicleDamage is the hp loss not vehicle elemnt so

function vehicle_damage(loss) 
if source == vehicle then 
    outputChatBox("vehicle damaged (-"..loss.." HP)") 
end 
end 
addEventHandler("onVehicleDamage", root, vehicle_damage) 

Posted from mobile

Edited by Guest
Link to comment
      
    vehicle = createVehicle(564, -2839.9,202,16.9) 
      
    function vehicle_demage() 
    if source == vehicle then    
    outputChatBox("vehicle demaged") 
    end 
    end 
    addEventHandler("onVehicleDamage", root, vehicle_demage) 

-- Two things,

-- One; don't define source up top, it's predefined, all that will do is mess it up. On vehicle damage perimeters are - Source == The source vehicle, Loss == Loss (Which you have to define in the function)

-- Two you did outputChatBox wrong, it's not outPutChatBox. You need to make sure your caps are in the right locations.

-- Edit --

// Other guy posted while I was writing this //

Link to comment
works, thanks!

You don't need to use

if source == vehicle then 

just attach the handler to the vehicle like this

local vehicle = createVehicle(564, -2839.9,202,16.9) 
  
function vehicle_demage()   
    outputChatBox("vehicle demaged") 
end 
addEventHandler("onVehicleDamage", vehicle, vehicle_demage) 

Link to comment

one more question: i tried that with onVehicleExplode, but its not working. The plane is not respawning. It says its a bad argumentum

  
local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) 
  
function respawn_dodo() 
setTimer(respawnVehicle, 5000, 1, source) 
end 
addEventHandler("onVehicleExplode", dodo1, respawn_dodo) 
  

Link to comment
      
    local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) 
      
    function respawn_dodo() 
    setTimer(respawnVehicleA, 5000, 1, source) 
    end 
     
    function respawnVehicleA(vehicle) 
    respawnVehicle(vehicle) 
    end 
     
    addEventHandler("onVehicleExplode", dodo1, respawn_dodo) 
      

Link to comment

Try this then..

         
        local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) 
          
        function respawn_dodo() 
        setTimer(respawnVehicle, 5000, 1, dodo1 ) 
        end 
        
        addEventHandler("onVehicleExplode", dodo1, respawn_dodo) 
          

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