Jump to content

What's wrong ramp


Gameraap

Recommended Posts

Hello,

I'm creating a script when i press 1 there comes a ramp

But what's wrong?

function ramp(command) 
local x,y,z = getElementPosition(source) 
local xx,yy,zz = getElementRotation(source) 
createObject ( 1632, x, y, z + 10, xx, yy, zz +10 ) 
end 
  
addCommandHandler("ramp",ramp) 
bindKey( "1", "down", ramp) 

Link to comment

read this:

https://wiki.multitheftauto.com/wiki/BindKey

and this:

https://wiki.multitheftauto.com/wiki/AddCommandHandler

In both you should use first argument in hander function to get position and rotation - becouse its the element that caused to fire that function.

There is no "source" in both.

Just replace "command" with something more suitable like: playerElement

and replace all "source" with playerElement also

Link to comment
  
function ramp1(player,command) 
    local x,y,z = getElementPosition(player) 
    local xx,yy,zz = getElementRotation(player) 
    createObject ( 1632, x, y, z + 10, xx, yy, zz +10 ) 
end 
addCommandHandler("ramp",ramp1) 
  
function ramp2(key,state) 
    local x,y,z = getElementPosition(source) 
    local xx,yy,zz = getElementRotation(source) 
    createObject ( 1632, x, y, z + 10, xx, yy, zz +10 ) 
end 
bindKey( "1", "down", ramp2) 
  

Link to comment
  
function ramp1(player,command) 
    local x,y,z = getElementPosition(player) 
    local xx,yy,zz = getElementRotation(player) 
    createObject ( 1632, x, y, z + 10, xx, yy, zz +10 ) 
end 
addCommandHandler("ramp",ramp1) 
  
function ramp2(key,state) 
    local x,y,z = getElementPosition(source) 
    local xx,yy,zz = getElementRotation(source) 
    createObject ( 1632, x, y, z + 10, xx, yy, zz +10 ) 
end 
bindKey( "1", "down", ramp2) 
  

Dont work

Link to comment

A player only has a Z-rotation, since it can't be rotated along the Z- or Y-axis. Since it's a ramp, I assume that the player is in a vehicle.

You gotta check if the player is in a vehicle and if he is, you get the position and rotation of that vehicle:

function ramp1(p) -- open a function with "p" defined as the player 
    local v = getPedOccupiedVehicle ( p ) -- get the player's vehicle 
    if v then -- does the player's vehicle exist (is he in a vehicle?) 
        local x, y, z = getElementPosition ( v ) -- get the vehicle's position 
        local rx, ry, rz = getVehicleRotation ( v ) -- get the vehicle's rotation 
        createObject ( 1632, x, y, z+10, rx, ry, rz ) -- create the object using the vehicle's position and rotation 
    end  
end 
bindKey( "1", "down", ramp2) 

I don't know why you want to create a ramp 10 meter above the player's vehicle, but that's your side of the story.

Link to comment
A player only has a Z-rotation, since it can't be rotated along the Z- or Y-axis. Since it's a ramp, I assume that the player is in a vehicle.

You gotta check if the player is in a vehicle and if he is, you get the position and rotation of that vehicle:

function ramp1(p) -- open a function with "p" defined as the player 
    local v = getPedOccupiedVehicle ( p ) -- get the player's vehicle 
    if v then -- does the player's vehicle exist (is he in a vehicle?) 
        local x, y, z = getElementPosition ( v ) -- get the vehicle's position 
        local rx, ry, rz = getVehicleRotation ( v ) -- get the vehicle's rotation 
        createObject ( 1632, x, y, z+10, rx, ry, rz ) -- create the object using the vehicle's position and rotation 
    end  
end 
bindKey( "1", "down", ramp2) 

I don't know why you want to create a ramp 10 meter above the player's vehicle, but that's your side of the story.

Dont work "WARNING: Bad argument @ bindkey tring-defined-function" I want the ramp not above me xD

Link to comment

Ah, the "p" shouldn't be there in the parameters of the ramp1 function: since the script is clientside (no keypresser defined in "bindKey") the keypresser can only be the local player:

p = getLocalPlayer() 
function ramp1() 
    local v = getPedOccupiedVehicle ( p ) -- get the player's vehicle 
    if v then -- does the player's vehicle exist (is he in a vehicle?) 
        local x, y, z = getElementPosition ( v ) -- get the vehicle's position 
        local rx, ry, rz = getVehicleRotation ( v ) -- get the vehicle's rotation 
        createObject ( 1632, x, y, z+10, rx, ry, rz ) -- create the object using the vehicle's position and rotation 
    end 
end 
bindKey( "1", "down", ramp1) 

Also, the function in "bindKey" wasn't present in the script (it was "ramp2" and that should have been "ramp1").

As for creating an object in front of something, you should check out "getElementMatrix":

https://wiki.multitheftauto.com/wiki/GetElementMatrix

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