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[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 (ID: %i)", playersname, i);
SendClientMessage(playerid, 0xFFFF00FF, fstr);
Count++;
continue;
}
}
}
if(Count == 0) return SendClientMessage(playerid, 0xFF0000FF, "There were no matches found.");
format(fstr, sizeof(fstr), "There was a total of %i potential matches found.", Count);
SendClientMessage(playerid, 0x00FF00FF, fstr);
return 1;
}
CMD:getid(playerid, params[])
{
new id[24], count = 0, dstring[500], string[50];
if(sscanf(params, "s[24]", id)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /getid [name/id]"); // this can be used with name and ID, check sscanf usage
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
if(strfind(id, name, true) != -1)
{
format(string, sizeof(string), "%s (ID: %i)\n", name, i);
strcat(dstring, string);
count ++;
}
}
}
if(count == 0) return ShowPlayerDialog(playerid, 2500, DIALOG_STYLE_MSGBOX, "No players found!", "Unfortunately, we couldn't find any players with the specification you gave us.", "OK", "");
new dialogtitle[50];
format(dialogtitle, sizeof(dialogtitle), "%i players were found", count);
ShowPlayerDialog(playerid, 2534, DIALOG_STYLE_LIST, dialogtitle, dstring, "Done", "");
return 1;
}
|
pawn Код:
|
|
Hi I would to ask if you someone know how to make a dialog getid. It will be like this for example. If I do "/getid Jor" after I enter it should show in dialog list box with the list of names of Jor like... BUT in Dialog LIST BOX Jorge (4) Jorosh (1) Jorja (6) Jorlol(34) Then when I click any name in the dialog list box it should teleport me to that player position that I have chosen. |
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]);
}
}
}
|
pawn Код:
Edit: Check the new code to be able to teleport to that player |
CMD:getid(playerid, params[]) {
if(isnull(params)) {
return SendClientMessage(playerid, 0xFF0000FF, "Usage: /getid [name/id]");
}
new
i = -1,
tmp[512],
name[MAX_PLAYER_NAME]
;
while(++i < MAX_PLAYERS) {
if(GetPlayerName(i, name, sizeof name) && (strfind(name, params, true) != -1)) {
format(tmp, sizeof tmp, "%s\n%s (ID: %i)", tmp, name, i);
}
}
if(tmp[0] == EOS) {
return SendClientMessage(playerid, 0xFF0000FF, "There were no matches found.");
}
return ShowPlayerDialog(playerid, YOUR_DIALOG_ID, DIALOG_STYLE_LIST, "Players", tmp[1], "Goto", "Close");
}
//OnDialogResponse
case YOUR_DIALOG_ID: {
if(response) {
new
Float: X,
Float: Y,
Float: Z,
giveplayerid = strval(inputtext[strfind(inputtext, "ID:", false) + 3])
;
if(GetPlayerPos(giveplayerid, X, Y, Z)) { // player could have left meanwhile
SetPlayerPos(playerid, X, Y, Z);
SetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
}
}
}
|
Just a little rewritten
pawn Код:
pawn Код:
|
(5938) : error 035: argument type mismatch (argument 1)
giveplayerid = strval(strfind(inputtext, "ID:", false) + 4);
|
And may I ask if you also fix when targeting a player part of name it should show the list of those who has this part of name?
|
giveplayerid = strval(inputtext[strfind(inputtext, "ID:", false) + 3])