Sign in to follow this  
Lynch

A problem with script.

Recommended Posts

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.

Share this post


Link to post

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) 

Share this post


Link to post
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.

Share this post


Link to post

Dude it's common sense. The vehicleJump is not defined and not is a function. Replace it with myPlayer + remember to trigger Player!

Share this post


Link to post

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) 

Share this post


Link to post
function myPlayer(Player) 
    bindKey(Player, "z", "down", jumpFunction) 
end 
  
function jumpFunction() 
   --Stuff 
end 

Share this post


Link to post
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?

Share this post


Link to post

I hoped you would look into bindKey to atleast know you have to pass the player.

function jumpFunction(thePlayer) 
    local vehicle = getPedOccupiedVehicle(thePlayer) 

Share this post


Link to post
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.

Share this post


Link to post

You din't define source. See bindKey for more information. See the argument's it passes!

Share this post


Link to post

??? 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) 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.