Jump to content

Warp CMD problem


adithegman

Recommended Posts

hello! i am trying to make a cmd for the editor mode in race si that when you type /sw it saves your pos and then if yo type /lw it will warp you to the same pos and the same speed but it doesn't work :?: please help me

function saveWarp (playerSource) 
    if(playerSource) then 
    vehicle = getPedOccupiedVehicle(playerSource) 
    local curposx, curposy, curposz = getElementPosition(vehicle) 
    local currotx, curroty, currotz = getElementRotation(vehicle) 
    local speedx, speedy, speedz = getElementVelocity(vehicle) 
    outputChatBox("The Warp has been saved!", playerSource) 
    end 
end 
  
addCommandHandler("sw", saveWarp) 
  
function loadWarp (playerSource) 
    if(playerSource) then 
    vehicle = getPedOccupiedVehicle(playerSource) 
    setVehicleFrozen(vehicle, true) 
    setElementPosition(vehicle, curposx, curposy, curposz) 
    setElementRotation(vehicle, currotx, curroty, currotz) 
    setTimer(setFreeze, 3000, 1) 
    outputChatBox("The Warp has been loaded!", playerSource) 
    end 
end 
  
addCommandHandler("lw", loadWarp) 
  
function setFreeze (playerSource) 
    if(playerSource) then 
    vehicle = getPedOccupiedVehicle(playerSource) 
    setVehicleFrozen(vehicle, false) 
    setElementVelocity(vehicle, speedx, speedy, speedz) 
    end 
end 
     

Edited by Guest
Link to comment
local playerData = { } -- Define a table 
  
function saveWarp ( playerSource ) 
    local vehicle = getPedOccupiedVehicle ( playerSource ) 
    playerData [ playerSource ] = -- Add the player who used the command to the table, and insert the position, rotation, speed 
        { 
            position = { getElementPosition ( vehicle ) }, 
            rotation = { getElementRotation ( vehicle ) }, 
            speed = { getElementVelocity ( vehicle ) } 
        } 
    outputChatBox ( "The Warp has been saved!", playerSource ) 
end 
addCommandHandler ( "sw", saveWarp ) 
  
function loadWarp ( playerSource ) 
    local data = playerData [ playerSource ] -- Check if the player is on the table. 
    if ( data ) then -- If he/she is... 
        local vehicle = getPedOccupiedVehicle ( playerSource ) 
        setElementFrozen ( vehicle, true ) 
        setElementPosition ( vehicle, unpack ( data.position ) ) -- Set the position to the value stored on the table. 
        setElementRotation ( vehicle, unpack ( data.rotation ) ) -- Set the rotation to the value stored on the table. 
        setTimer ( setFreeze, 3000, 1, vehicle, data.speed ) -- Pass the speed data to the "setFreeze" function. 
        outputChatBox ( "The Warp has been loaded!", playerSource ) 
    end 
end 
addCommandHandler ( "lw", loadWarp ) 
  
function setFreeze ( vehicle, speed ) 
    if ( vehicle ) then 
        setElementFrozen ( vehicle, false ) 
        setElementVelocity ( vehicle, unpack ( speed ) ) 
    end 
end 

Read the comments.

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