Jump to content

onVehicleDemage not working


Xwad

Recommended Posts

Posted

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) 

Posted (edited)

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
Posted
      
    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 //

Posted
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) 

Posted

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) 
  

Posted
      
    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) 
      

Posted

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) 
          

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

Posted

Hmm interesting. I tested it on my local server, and it works. its only not working on he hoster server. But the way thanks!

Posted

You're welcome :P!

Probably it's a problem from your server (its scripts), because else it's so weird that it works in one server and doesn't work in the other.

Make sure you set this as server side in the meta.xml.

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