Jump to content

What is wrong? (onVehicleEnter,onVehicleExit)


h1ama3d

Recommended Posts

Hello ..

I want help please ..

I found this code .. In Wikipedia ..

function addHelmetOnEnter ( thePlayer, seat, jacked ) 
    if ( getElementModel ( source ) == 522 ) then -- if its a nrg 
        addPedClothes ( thePlayer, "moto", "moto", 16 ) -- add the helmet 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter ) 
  
function removeHelmetOnExit ( thePlayer, seat, jacked ) 
    if ( getElementModel ( source ) == 522 ) then -- if its a nrg 
        removePedClothes ( thePlayer, 16 ) -- remove the helmet 
    end 
end 
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit ) 
  

But I want add a variable .. To be code on all bikes

But it did not work ..

This is the code :

  
bikes = { 
    "522" , 
    "481" , 
    "581" , 
    "462" , 
    "521" , 
    "463" , 
    "523" , 
    "461" , 
    "448" , 
    "468" , 
    "586" , 
    "471" , 
    "509" , 
    "510" 
} 
function addHelmetOnEnter ( thePlayer, seat, jacked ) 
    if ( getElementModel ( source ) == bikes ) then -- if its a Bike 
        addPedClothes ( thePlayer, "moto", "moto", 16 ) -- add the helmet 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter ) 
  
function removeHelmetOnExit ( thePlayer, seat, jacked ) 
    if ( getElementModel ( source ) == bikes ) then -- if its a Bike 
        removePedClothes ( thePlayer, 16 ) -- remove the helmet 
    end 
end 
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit ) 
  

Sorry I am a noob ><

Please I want help ..

Link to comment

Well, when you have this code you can do something like this with your table:

  
 bikes = { 
     "522" , 
     "481" , 
     "581" , 
     "462" , 
     "521" , 
     "463" , 
     "523" , 
     "461" , 
     "448" , 
     "468" , 
     "586" , 
     "471" , 
     "509" , 
     "510" 
 } 
function isABike( modelID ) 
     for k,i in ipairs( bikes )do -- go through the table 
          if( tonumber( modelID ) == tonumber( i ) )then -- if the modelID is equal to the table value 
               return true 
          end 
     end 
     return false 
end 
  
function addHelmetOnEnter ( thePlayer, seat, jacked ) 
    if ( isABike( getElementModel ( source ) ) ) then -- if its a bike 
        addPedClothes ( thePlayer, "moto", "moto", 16 ) -- add the helmet 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter ) 
  
function removeHelmetOnExit ( thePlayer, seat, jacked ) 
    if (  isABike( getElementModel ( source ) ) ) then -- if its a bike 
        removePedClothes ( thePlayer, 16 ) -- remove the helmet 
    end 
end 
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit ) 
  

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