Jump to content

A problem with script.


Bilal135

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.

Link to comment

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

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

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

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