Jump to content

problem with getting models


Tete omar

Recommended Posts

Posted

Hello ,

i made this script taking money from the passengers who entered and exited the specific vehicle models.

addEventHandler("onPlayerVehicleExit", getRootElement(), 
function(veh,sea) 
randomMoney = math.random( 50,200 ) 
    if ( getElementModel( veh ) == 420 or 428 ) then 
        if ( sea == 1 or 2 or 3 ) then 
            if ( getPlayerMoney( source ) >= tonumber( randomMoney ) ) then 
                takePlayerMoney( source, tonumber( randomMoney ) ) 
            end 
        end 
    end 
end) 

but unfortunately it takes the money from every vehicle model and every seat i enter and exit .. what's wrong ?.

Posted
    if ( getElementModel( veh ) == 420 or 428 ) then 
        if ( sea == 1 or 2 or 3 ) then 

should be:

if (getElementModel(veh) == 420 or getElementModel(veh) == 428) then 
if (sea == 1 or sea == 2 or sea == 3) then 

Guest Guest4401
Posted
yeah thx , i think tonumber is not needed becuase randomMoney is already a number right ?

Yes, it's number.

Posted

You should put randomMoney below this, so it won't make a random number every time you exit from vehicle, you only need it for 420 and 428.

if (sea == 1 or sea == 2 or sea == 3) then 

Posted
You should put randomMoney below this, so it won't make a random number every time you exit from vehicle, you only need it for 420 and 428.
if (sea == 1 or sea == 2 or sea == 3) then 

you mean like that ?

addEventHandler("onPlayerVehicleExit", getRootElement(), 
function(veh,sea) 
    if (getElementModel(veh) == 420 or getElementModel(veh) == 428) then 
        if (sea == 1 or sea == 2 or sea == 3) then 
            randomMoney = math.random( 50,200 ) 
            if ( getPlayerMoney( source ) >= randomMoney ) then 
                takePlayerMoney( source, randomMoney ) 
            end 
        end 
    end 
end) 

No i also think it's the same meaning than the other one, and thanks for the attention.

Posted

it's will work in both way

but it's about performance (less CPU usage), also you should make it local anyway.

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