Bilal135 Posted November 12, 2014 Share Posted November 12, 2014 Hi guys, I was making a script, that when we press button "z" our vehicle jumps. But I got one error. My code: function vehicleJump() bindKey(source, "z", "down", "jump", local vehicle = getPedOccupiedVehicle(source) if (isVehicleOnGround(vehicle) == true) then local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.4) end end ) addEvent("onSpecialEvent", true) addEventHandler("onSpecialEvent", root, vehicleJump) Error: vehiclejump\vehjump.lua:3: unexpected symbol near 'local' I can't understand what's the error, please tell me what wrong I did. Link to comment
SkatCh Posted November 12, 2014 Share Posted November 12, 2014 lol just add this ')' . function vehicleJump() bindKey(source, "z", "down", "jump", -- like this bindKey(source, "z", "down", jump) local vehicle = getPedOccupiedVehicle(source) if (isVehicleOnGround(vehicle) == true) then local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.4) end end ) addEvent("onSpecialEvent", true) addEventHandler("onSpecialEvent", root, vehicleJump) Link to comment
Bilal135 Posted November 13, 2014 Author Share Posted November 13, 2014 function myPlayer(Player) bindKey(source, "z", "down", "jump") local vehicle = getPedOccupiedVehicle(Player) if (isVehicleOnGround(vehicle) == true) then local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.4) end end addEvent("onSpecialEvent", true) addEventHandler("onSpecialEvent", root, vehicleJump) Error: Expected function at argument 3 got nil. Link to comment
Anubhav Posted November 13, 2014 Share Posted November 13, 2014 Dude it's common sense. The vehicleJump is not defined and not is a function. Replace it with myPlayer + remember to trigger Player! Link to comment
Bilal135 Posted November 13, 2014 Author Share Posted November 13, 2014 It doesn't show any error now, but still when I press "z", my car does not jump. function myPlayer(Player) bindKey(Player, "z", "down", "jump") local vehicle = getPedOccupiedVehicle(Player) if (isVehicleOnGround(vehicle) == true) then local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.4) end end addEvent("onSpecialEvent", true) addEventHandler("onSpecialEvent", root, myPlayer) Link to comment
Et-win Posted November 13, 2014 Share Posted November 13, 2014 function myPlayer(Player) bindKey(Player, "z", "down", jumpFunction) end function jumpFunction() --Stuff end Link to comment
Bilal135 Posted November 13, 2014 Author Share Posted November 13, 2014 function myPlayer(Player) bindKey(Player, "z", "down", jumpFunction) end function jumpFunction() local vehicle = getPedOccupiedVehicle(source) local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.7) end Doesn't give any errors, but when I press z, my car doesn't jump. I've tried the same with addCommandHandler which works perfectly. function jumpFunction(player) local vehicle = getPedOccupiedVehicle(player) local sx,sy,sz = getElementVelocity(vehicle) setElementVelocity(vehicle ,sx, sy, sz+0.7) end addCommandHandler("jump", jumpFunction) I think I'm doing something wrong with bindKey? Link to comment
Et-win Posted November 13, 2014 Share Posted November 13, 2014 I hoped you would look into bindKey to atleast know you have to pass the player. function jumpFunction(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) Link to comment
Bilal135 Posted November 13, 2014 Author Share Posted November 13, 2014 I hoped you would look into bindKey to atleast know you have to pass the player. function jumpFunction(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) Sorry, I didn't get what you wanted to say. Link to comment
Anubhav Posted November 13, 2014 Share Posted November 13, 2014 You din't define source. See bindKey for more information. See the argument's it passes! Link to comment
Et-win Posted November 13, 2014 Share Posted November 13, 2014 If you look what I changed in that two lines then you know.. Link to comment
SkatCh Posted November 13, 2014 Share Posted November 13, 2014 ??? all what you need is function jump() local vehicle = getPedOccupiedVehicle(localPlayer) local Controller = getVehicleController ( localPlayer ) if getVehicleController(getPedOccupiedVehicle(localPlayer)) == localPlayer then if ( isElement(vehicle) ) and (isVehicleOnGround( vehicle )) then local sx,sy,sz = getElementVelocity ( vehicle ) setElementVelocity( vehicle ,sx, sy, sz+0.7) end end end bindKey ( "z","down", jump) 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