GTA Connected

Scripting => Scripting Help => Topic started by: tucson913 on December 21, 2024, 11:05:50 AM

Title: client.player.position
Post by: tucson913 on December 21, 2024, 11:05:50 AM
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;
      }
});

Title: Re: client.player.position
Post by: Vortrex on January 08, 2025, 10:00:33 PM
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.