get playerid form name dosn't work
#1

Hello i have one problem when i make command /id and playername he tell just my self dont work for other player here its code
pawn Код:
dcmd_id(playerid, params[])
{
    new pid,PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,COLOR_RED, "Player not found.");
    if(sscanf(params, "u", pid)) return SendClientMessage(playerid,COLOR_WHITE, "USAGE: /id <part of name>");
    SendClientMessage(playerid, 0xE89B5BBB, "Players found:");
    format(str, sizeof(str), "> %s (ID:%d) ",PlayerName[pid] ,pid );
    SendClientMessage(playerid, COLOR_WHITE, str);
    return 1;
}
Thanks
Reply
#2

any help guys?
Reply
#3

pawn Код:
dcmd_id(playerid, params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /id [Part of name]");
    new players, string[128], name[MAX_PLAYER_NAME];
    format(string,sizeof(string),"Searched for: %s",params);
    SendClientMessage(playerid,0xFFFFFFFF,string);
    for(new i=0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, name, MAX_PLAYER_NAME);
            new len = strlen(name);
            new bool:searched=false;
            for(new pos=0; pos <= len; pos++)
            {
                if(searched != true)
                {
                    if(strfind(name,params,true) == pos)
                    {
                        players++;
                        format(string,sizeof(string),"%d. %s (ID: %d)",players,name,i);
                        SendClientMessage(playerid, 0x00FF00FF ,string);
                        searched = true;
                    }
                }
            }
        }
    }
    if(players == 0)
    SendClientMessage(playerid, 0xFF0000FF, "No Players Localized!");
    return 1;
}
Reply
#4

pawn Код:
dcmd_id(playerid, params[])
{
    new pid, PlayerName[MAX_PLAYER_NAME+1];    
    if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,COLOR_RED, "Player not found.");
    if(sscanf(params, "u", pid)) return SendClientMessage(playerid,COLOR_WHITE, "USAGE: /id <part of name>");
    GetPlayerName(pid, PlayerName, sizeof(PlayerName));
    SendClientMessage(playerid, 0xE89B5BBB, "Players found:");
    format(str, sizeof(str), "> %s (ID:%d) ", PlayerName, pid );
    SendClientMessage(playerid, COLOR_WHITE, str);
    return 1;
}
Reply
#5

pid is always 0 so if ID 0 is not connected cmd doesnt work
Reply
#6

thanks all
Reply
#7

You want it like this

pawn Код:
dcmd_id(playerid, params[])
{
    new pid, PlayerName[MAX_PLAYER_NAME+1];
    if(sscanf(params, "u", pid)) return SendClientMessage(playerid,COLOR_WHITE, "USAGE: /id <part of name>");
    if(pid == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED, "Player not found.");
    GetPlayerName(pid, PlayerName, sizeof(PlayerName));
    SendClientMessage(playerid, 0xE89B5BBB, "Players found:");
    format(str, sizeof(str), "> %s (ID:%d) ", PlayerName, pid );
    SendClientMessage(playerid, COLOR_WHITE, str);
    return 1;
}
You only need to check for INVALID_PLAYER_ID
Reply
#8

Already fixed it but anyway thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)