Jump to content

Checking for vehicle and setting


Bohemian_Bear

Recommended Posts

Posted

Well, i am new here, and please sry for the bad english. :D

I am trying to make an hud that changes one "state of damage" pic related to the vehicle types

  
function enterVehicle(theVehicle, seat, jacked) 
    if (getVehicleType(theVehicle) == "Automobile") then 
        local vehicle = "textures/car.png" 
    end 
    if (getVehicleType(theVehicle) == "Plane") then 
        local vehicle = "textures/plane.png" 
    end 
    if (getVehicleType(theVehicle) == "Bike") then 
        local vehicle = "textures/bike.png" 
    end 
    if (getVehicleType(theVehicle) == "Helicopter") then 
        local vehicle = "textures/heli.png" 
    end 
    if (getVehicleType(theVehicle) == "Boat") then 
        local vehicle = "textures/boat.png" 
    end 
end 

2 questions, this is right?

And this is will return me "textures/....png" with the "vehicle" variable?

Also, if there anyway to make this code better, will help. TY!

Posted

That code will make the 'vehicle' variable local, which means it only exists inside that 'if'. You could also use 'elseif' instead of using separated 'if'.

Or you can also do it this way:

function enterVehicle ( theVehicle, seat, jacked ) 
    local vType = getVehicleType ( source ) 
    local vehicle = "textures/".. ( vType == "Automobile" and "car" or vType == "Plane" and "plane" or vType == "Bike" and "bike" or vType == "Helicopter" and "heli" or vType == "Boat" and "boat" ) ..".png" 
end 

Posted

Nice, this will work...

When i ask for vehicle, it will returns to me textures/vehicleType.png, right?

I am still learning with some scripts open source and reading;

I can set things like, global variables, session variables or things like session variables?

Posted

By session variables you mean data that only exists until you quit the server? if so, then yes, you can set element data.

getElementData 
setElementData 

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