Main Menu

client.player.position

Started by tucson913, December 21, 2024, 11:05:50 AM

Previous topic - Next topic

tucson913

Hi all!

I have problem with the player position.

I wrote a simple vehicle spawn command and I get this error message:
QuoteTypeError: client.player is null

The client.player exists only on client side? Or how can I get the player position?
Thank you!

Code:
addEventHandler('OnPlayerCommand', (event, client, command, parameters) => {

    console.log(`(Command) ${client.name} has used the command '/${command} ${parameters}'.`);
   
      switch(command){
        case "v":
            case "veh":
                case "vehicle":
                    var veh = gta.createVehicle(parseInt(parameters), client.player.position);
                    addToWorld(veh);
                    client.player.warpIntoVehicle(veh, 0);
        break;

        default:
            message("UNK CMD");
        break;
      }
});


Vortrex

For a server side script, use client.player.

For client-side, the easiest way to access your player is with localPlayer
For any other player (as long as they're streamed in), use client.player like you would in a server script.

tucson913

thank you,
but i'm using the client.player and it don't work.

Vortrex

Is this on GTA IV? If you're using native mode on GTA IV, then the server won't be aware of any game elements (including player peds).

You'll need to send the position to the client in a network event to make the client set the position itself, or put the command in a client-side script and process it all there without the server being involved.