28.10.2013, 17:41
pawn Код:
new gDialogPos[MAX_PLAYERS] = {-1, ...};
CMD:getid(playerid, params[])
{
new name[24];
if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /getid [name/id]");
new Count = 0;
new fstr[512];//150];
for(new i = 0; i < MAX_PLAYERS; i++) //foreach would be the better option...
{
if(IsPlayerConnected(i))
{
new playersname[24];
GetPlayerName(i, playersname, 24);
if(strfind(name, playersname, true) != -1)
{
format(fstr, sizeof(fstr), "%s%s (ID: %i)\n", fstr, playersname, i);
//SendClientMessage(playerid, 0xFFFF00FF, fstr);
gDialogPos[Count] = i;
Count++;
//continue;
}
}
}
if(Count == 0) SendClientMessage(playerid, 0xFF0000FF, "There were no matches found.");
else
{
new str[128];
format(str, sizeof(str), "There was a total of %i potential matches found.", Count);
SendClientMessage(playerid, 0x00FF00FF, str);
ShowPlayerDialog(playerid, YOUR_DIALOG_ID, DIALOG_STYLE_LIST, "Players", fstr, "Goto", "Close");
}
return 1;
}
//On Dialog Response
switch(dialogid)
{
case YOUR_DIALOG_ID:
{
if(response)
{
new pID = gDialogPos[listitem], Float: pos[3];
GetPlayerPos(pID, pos[0], pos[1], pos[2]);
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
}
}
}
Edit: Check the new code to be able to teleport to that player