1LoL1 Posted January 23, 2016 Share Posted January 23, 2016 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) Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 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. Link to comment
1LoL1 Posted January 23, 2016 Author Share Posted January 23, 2016 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. Link to comment
ViRuZGamiing Posted January 23, 2016 Share Posted January 23, 2016 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? Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 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. Link to comment
ViRuZGamiing Posted January 23, 2016 Share Posted January 23, 2016 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. Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 overwriting it is possible, yes. That's the basics of programming, you're just assigning a new value to the variable. Link to comment
ViRuZGamiing Posted January 23, 2016 Share Posted January 23, 2016 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now