Why is GetPlayerName returning **Invalid**

RegisterCommand('vida2', async (source, args, raw) => {
    let playerName = GetPlayerName(-1);
    if (args[0] == null)
    {
        emit('chat:addMessage', {
            args: [`Teste!`]
          });
    }
    else
    {
        ped = GetPlayerPed(args[0]);
        emit('chat:addMessage', {
            args: [`The player name is ${playerName}!`]
          });
    }

}, false);

Hi. I made this code where if args[0] is not null I get sent a message with my player name (local). However it is returning Invalid. What is wrong?

GetPlayerName(PlayerId()), -1 is only a valid alias for GetPlayerPed.

1 Like

Thanks! How could I get the player name of other player??
I tried this but it isn’t working:

let playerIdentifier = GetPlayerIdentifier(args[0]);

GetPlayerIdentifier need 2 params.

  1. playerSrc and 2. the identifier that you want to request

And where can I see a list of those identifiers?

They don’t show up in here

Just use GetPlayerName as before

You just need the PlayersSource, and that sould be that what you got

local playerName = GetPlayerName(playerSrc);

And how can I get the player ped of another player?
I’ve tried this:
ped = GetPlayerPed(args[0]);
I’m supposed to type his name on chat

Yeah. OKay. But you dont need to get the ped for the chat? and yeah that should be right

I’m trying to do a command where I heal a player’s ped by typing /heal [playerName].
I think it’s working now.
Not I’ll try to check if the player is connected to the server

They’re dynamically indexed. Use Array.prototype.find on getPlayerIdentifiers to get the identifier you want.