Jump to content

[SOLVED] Move a player


FatalTerror

Recommended Posts

getPedRotation 
setPedRotation 
setTimer 

This don't help me :oops:

  
addEventHandler("onClientClick", getRootElement(), 
        function( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
            if(button == "left")then 
                if(state == "down")then 
                    local x, y, z = worldX, worldY, worldZ 
                    if x and y and z then 
                     
                        -- Move the player to x, y and z 
                     
                    end 
                end 
        end) 
  

Link to comment
function findRotation ( posX , posY , _posX , _posY ) 
    return 360 - ( math.deg ( math.atan2 ( _posX - posX , _posY - posY ) ) % 360 ) 
end 

Will get you the rotation to x,y,z

  
addEventHandler("onClientClick", getRootElement(), 
        function( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
            if(button == "left")then 
                if(state == "down")then 
                    local x, y, z = worldX, worldY, worldZ 
                    if x and y and z then 
                        local posx , posy , posz = getElementPosition ( localPlayer ) 
                        local rot = findRotation ( posx , posy , x , y ) 
                         
                        setPedRotation ( localPlayer , rot ) 
                         
                        setControlState ( "forwards" , true ) 
                    
                    end 
                end 
        end 
    end) 
  
function findRotation ( startx , starty , endx , endy ) 
    return 360 - ( math.deg ( math.atan2 ( endx - startx , endy - starty ) ) % 360 ) 
end  

Now you need to work something out for stopping him when he arrive.

And prevent him from stopping due to obstacles.

Link to comment
function findRotation ( posX , posY , _posX , _posY ) 
    return 360 - ( math.deg ( math.atan2 ( _posX - posX , _posY - posY ) ) % 360 ) 
end 

Will get you the rotation to x,y,z

  
addEventHandler("onClientClick", getRootElement(), 
        function( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
            if(button == "left")then 
                if(state == "down")then 
                    local x, y, z = worldX, worldY, worldZ 
                    if x and y and z then 
                        local posx , posy , posz = getElementPosition ( localPlayer ) 
                        local rot = findRotation ( posx , posy , x , y ) 
                         
                        setPedRotation ( localPlayer , rot ) 
                         
                        setControlState ( "forwards" , true ) 
                    
                    end 
                end 
        end 
    end) 
  
function findRotation ( startx , starty , endx , endy ) 
    return 360 - ( math.deg ( math.atan2 ( endx - startx , endy - starty ) ) % 360 ) 
end  

Now you need to work something out for stopping him when he arrive.

And prevent him from stopping due to obstacles.

Big thanks ! :mrgreen:

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