Nearest players list
#1

So, I don't know how to check which player did I chosen on the list, cause list is working fine, but OnDialogResponse fails.

CMD:
pawn Код:
YCMD:nearby(playerid, params[], help)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);

    new string[128],
        count = 0;

    ForeachEx(i, MAX_PLAYERS)
    {
        if(!IsPlayerConnected(i) || i == playerid)continue;

        if(IsPlayerInRangeOfPoint(i, 5.0, X, Y, Z))
        {
            format(string, sizeof(string), "%s(%d)\t%s\n", string, i, PlayerName(i));
            count += 1;
        }
    }

    if(count != 0)
    {
        ShowPlayerDialog(playerid, 32767, DIALOG_STYLE_LIST, "Najbliżsi gracze", string, "Wybierz", "");
    }
    else SendClientMessage(playerid, -1, "Brak graczy w pobliżu!");
    return true;
}
OnDialogResponse
pawn Код:
case 32767:
        {
            if(!response)return false;
            else
            {
                new string[128];
                format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
                SendClientMessage(listitem, -1, string);

                format(string, sizeof(string), "Wybrałeś %s (%d)!", PlayerName(listitem), listitem);
                SendClientMessage(playerid, -1, string);
            }
        }
Reply
#2

pawn Код:
YCMD:nearby(playerid, params[], help)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);

    new string[128],
        count = 0;

    ForeachEx(i, MAX_PLAYERS)
    {
        if(!IsPlayerConnected(i) || i == playerid)continue;

        if(IsPlayerInRangeOfPoint(i, 5.0, X, Y, Z))
        {
            format(string, sizeof(string), "%s%s(%d)\n", string, PlayerName(i), i);
            count += 1;
        }
    }

    if(count != 0)
    {
        ShowPlayerDialog(playerid, 32767, DIALOG_STYLE_LIST, "Najbliżsi gracze", string, "Wybierz", "");
    }
    else SendClientMessage(playerid, -1, "Brak graczy w pobliżu!");
    return true;
}
stock GetPlayerIDFromName(const name[])
{
    new retid = INVALID_PLAYER_ID;
    ForeachEx(i, MAX_PLAYERS)
    {
        if(strcmp(name, PlayerName(i), true) == 0)
        {
            retid = i;
            break;
        }
    }
    return retid;
}

case 32767:
{
    if(!response)return false;
    else
    {
        new string[128];
strdel(inputtext, strfind(inputtext, "("), strlen(inputtext));
        format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
        SendClientMessage(GetPlayerIDFromName(inputtext), -1, string);

        format(string, sizeof(string), "Wybrałeś %s (%d)!", inputtext, GetPlayerIDFromName(inputtext));
        SendClientMessage(playerid, -1, string);
     }
}
try this, untested.

aww, you were right
Reply
#3

Why get the name and than find the id if he already passes the id ?

pawn Код:
case 32767: {
    if(!response)return false;

    inputtext[strfind(inputtext, ")", 1)] = EOS;

    new
        string[128],
        giveplayerid = strval(inputtext[1])
    ;
    format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
    SendClientMessage(giveplayerid , -1, string);

    format(string, sizeof(string), "Wybrałeś %s (%d)!", inputtext, giveplayerid);
    SendClientMessage(playerid, -1, string);
}
Reply
#4

Right, it's working but I want to have a different format in dialog.

pawn Код:
format(string, sizeof(string), "%s%d\t%s\n", string, i, PlayerName(i));
Not like yours.. so, I have to remove player id somehow, but probably I can't do it with it.
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Why get the name and than find the id if he already passes the id ?

pawn Код:
case 32767: {
    if(!response)return false;

    inputtext[strfind(inputtext, ")", 1)] = EOS;

    new
        string[128],
        giveplayerid = strval(inputtext[1])
    ;
    format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
    SendClientMessage(giveplayerid , -1, string);

    format(string, sizeof(string), "Wybrałeś %s (%d)!", inputtext, giveplayerid);
    SendClientMessage(playerid, -1, string);
}
Tried.. and it works from ID 1 and above, because when ID 0 tries to choose someone from the list it's says:
Код:
Wybrałeś "Your_name" (your_id)!
pawn Код:
case 32767:
{
    if(!response)return false;
    else
    {
        inputtext[strfind(inputtext, ")", true) != -1] = EOS;

        new string[128],
            giveplayerid = strval(inputtext[1]);
           
        format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
        SendClientMessage(giveplayerid , -1, string);

        format(string, sizeof(string), "Wybrałeś %s (%d)!", PlayerName(giveplayerid), giveplayerid);
        SendClientMessage(playerid, -1, string);
     }
}
However, I want to have this format:
pawn Код:
format(string, sizeof(string), "%s%d\t%s\n", string, i, PlayerName(i));
edit://
Fixed a message with "Wybrałeś ( (0)!" but still.. problem occurs with players list. When I am ID: 0 and I'm trying to choose player from list (1st player) it says "Wybrałeś Your_Nick (your_id)!" and "your_name (your_id) wybrał właśnie Ciebie!"
Reply
#6

Just search for the delimiter after the id "\t"
pawn Код:
case 32767: {
    if(!response)return false;

    inputtext[strfind(inputtext, "\t")] = EOS;

    new
        string[128],
        giveplayerid = strval(inputtext)
    ;
    format(string, sizeof(string), "%s (%d) wybrał właśnie Ciebie!", PlayerName(playerid), playerid);
    SendClientMessage(giveplayerid , -1, string);

    format(string, sizeof(string), "Wybrałeś %s (%d)!", PlayerName(giveplayerid), giveplayerid);
    SendClientMessage(playerid, -1, string);
}
But no clue why their should be an id 0 problem
Reply
#7

Nah, nevermind, I fixed it but forget to edit my last post. Cheers, anyway.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)