Jump to content

[HELP] Wheels


1LoL1

Recommended Posts

Posted

Hello, i creatd the script but not work why please? :( can anyone help me?

local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
  
addEventHandler("onVehicleEnter", getRootElement(), 
function (source) 
local vehicle = getPedOccupiedVehicle(source) 
local wheels = (getElementData(source, "wheel") or 0) 
if vehicle then 
if (wheels  == 9) then 
    addVehicleUpgrade(vehicle, w[9]) 
        end 
    end 
end) 

Posted

I would suggest you to rename your player element from source to thePlayer, like so;

local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        if ( wheels == 9 ) then 
            addVehicleUpgrade ( source, w [ 9 ] ); 
        end 
    end 
); 

but to avoid you from making 17 if-else-statements, you can also do this;

addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        addVehicleUpgrade ( source, w [ wheels ] ); 
    end 
); 

Which will automatically get the right upgrade for your vehicle.

Posted
I would suggest you to rename your player element from source to thePlayer, like so;
local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        if ( wheels == 9 ) then 
            addVehicleUpgrade ( source, w [ 9 ] ); 
        end 
    end 
); 

but to avoid you from making 17 if-else-statements, you can also do this;

addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        addVehicleUpgrade ( source, w [ wheels ] ); 
    end 
); 

Which will automatically get the right upgrade for your vehicle.

Not work vehicle is not defined.. i want change vehicle wheels.

Posted
I would suggest you to rename your player element from source to thePlayer, like so;
local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        if ( wheels == 9 ) then 
            addVehicleUpgrade ( source, w [ 9 ] ); 
        end 
    end 
); 

but to avoid you from making 17 if-else-statements, you can also do this;

addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        addVehicleUpgrade ( source, w [ wheels ] ); 
    end 
); 

Which will automatically get the right upgrade for your vehicle.

I'm wondering in his case, he assigned the name 'source' to the first parameter, which is thePlayer.

Would source then be overwriten and source actually be thePlayer instead of the vehicle?

Posted
I would suggest you to rename your player element from source to thePlayer, like so;
local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        if ( wheels == 9 ) then 
            addVehicleUpgrade ( source, w [ 9 ] ); 
        end 
    end 
); 

but to avoid you from making 17 if-else-statements, you can also do this;

addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        addVehicleUpgrade ( source, w [ wheels ] ); 
    end 
); 

Which will automatically get the right upgrade for your vehicle.

I'm wondering in his case, he assigned the name 'source' to the first parameter, which is thePlayer.

Would source then be overwriten and source actually be thePlayer instead of the vehicle?

Overwritting the actual vehicle to get the vehicle after that again? I'm sorry but that's just plain stupid and resource intensive.

@1LoL1; "vehicle" isn't defined because the source of the actual function is the vehicle.

Posted
I would suggest you to rename your player element from source to thePlayer, like so;
local w = {1025,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1096,1097,1098} -- all: 17 
  
addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        if ( wheels == 9 ) then 
            addVehicleUpgrade ( source, w [ 9 ] ); 
        end 
    end 
); 

but to avoid you from making 17 if-else-statements, you can also do this;

addEventHandler ( "onVehicleEnter", getRootElement(), 
    function ( thePlayer ) 
        local wheels = ( getElementData ( thePlayer, "wheel" ) or 0 ); 
        addVehicleUpgrade ( source, w [ wheels ] ); 
    end 
); 

Which will automatically get the right upgrade for your vehicle.

I'm wondering in his case, he assigned the name 'source' to the first parameter, which is thePlayer.

Would source then be overwriten and source actually be thePlayer instead of the vehicle?

Overwritting the actual vehicle to get the vehicle after that again? I'm sorry but that's just plain stupid and resource intensive.

@1LoL1; "vehicle" isn't defined because the source of the actual function is the vehicle.

That's not what I said, I asked if it was possible to overwrite the default given 'source'.

Because what he in the first place did was overwriting source with thePlayer (if that is indeed possible)

I know that double overwriting would be dumb.

Posted
overwriting it is possible, yes. That's the basics of programming, you're just assigning a new value to the variable.

Yeah I know that too, I was just wondering if it was also possible to overwrite the 'source' variable, but I understand that it is appearantly possible.

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