[Command] Give a player's ID from a command
#1

Helo, I am making a command that works like that :

- There are 2 players : Gamer1 and Gamer2
- Gamer1 type /id Gamer2 to have Gamer2's ID
- The server returns "Gamer2's ID is [ID]" => [ID] is Gamer2's ID.

I maked this command :

Код:
dcmd_id(playerid, params[])
{
    new id, playername[24] ,string[256];
	if (sscanf(params, "d", id, GetName(id)))
	return SendClientMessage(playerid, 0xFF0000AA, "Utilisation: \"/id <nom du joueur>\"");
	else if (!IsPlayerConnected(id))
	return SendClientMessage(playerid, 0xFF0000AA, "Joueur non trouve");
	else
	{
	GetPlayerID(playerid);
	format(string, sizeof(string), "%s 's IDis %d.", playername, id);
	SendClientMessage(playerid, 0xFFFF00AA, string);
	}
	return 1;
}
With this stock :

Код:
stock GetPlayerID(const name[])
{
    new pName[MAX_PLAYER_NAME];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        GetPlayerName(i, pName, MAX_PLAYER_NAME);
        if(!strcmp(pName, name))
            return i;
    }
    return INVALID_PLAYER_ID;
}
But in game, the server returns my ID, not Gamer2's ID ... I think in the command, the code

Код:
GetPlayerID(playerid);
returns my ID but not Gamer2's ID.

How can I make the server returns the goos ID please ?


Thanks a lot =)
Reply
#2

Up ...
Reply
#3

Код:
dcmd_id(playerid, params[])
{
	new id, playername[24] ,string[256];
	if (sscanf(params, "s", playername))
	return SendClientMessage(playerid, 0xFF0000AA, "Utilisation: \"/id <nom du joueur>\"");
	else
	{
		id=GetPlayerID(playername);
		format(string, sizeof(string), "%s 's ID is %d.", playername, id);
		SendClientMessage(playerid, 0xFFFF00AA, string);
	}
	return 1;
}
i hope i didnt screw that up completedly now...
Reply
#4

Thank you ! I'll try this =)
Reply
#5

I have these errors with the compiler :

Код:
C:\Documents and Settings\Ludovic\Bureau\GTA\samp03csvr_R2-2_win32\pawno>.\pawnc
c .\Area51.pwn
Pawn compiler 3.2.3664                  Copyright © 1997-2006, ITB CompuPhase

.\Area51.pwn(990) : error 035: argument type mismatch (argument 1)
.\Area51.pwn(996) : error 017: undefined symbol "playername"
.\Area51.pwn(984) : warning 204: symbol is assigned a value that is never used:
"pName"

2 Errors.
Appuyez sur une touche pour continuer...
Reply
#6

Better use strfind, so you can search for parts of names:
pawn Код:
dcmd_id( playerid, params[ ] ) {
    if( !strlen( params ) ) {
        SendClientMessage( playerid, -1, "Utilisation: '/id <nom du joueur>'" );
        return 1;
    }
    for( new i = 0; i < MAX_PLAYERS; i++ ) {
        new
            pName[ 24 ],
            string[ 128 ]
        ;
        GetPlayerName( i, pName, 24 );
        if( strfind( params, pName, true ) ) {
            format( string, sizeof string, "%s's ID is %d", pName, i );
            SendClientMessage( playerid, -1, string );
        }
    }
    return 1;
}
Untested.
Reply
#7

Hem ... Lol ! The server returns a message like that :

Quote:

's id is 1
's id is 2
's id is 3
...
's id is 499
's id is 500

So it work, but it don't send me the ID that I want ^^
Reply
#8

Up ...
Reply
#9

Just use sscanf.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
Just use sscanf.
How must I use it ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)