Please help with script - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Please help with script (
/showthread.php?tid=585750)
Please help with script -
AkaSKY - 16.08.2015
So, I got this script:
http://pastebin.com/Lg2BgHWN. It searches for a specified part of a player name and if it finds more than one, it writes all players that their part of name matches with the searched one. If there are more than 7 cases, it will write that too many matches were found. What I want is to put that big number of lines in just one line (like ReturnUser) so I won't be needed to copy-paste it at anytime I need it.
Re: Please help with script -
AkaSKY - 16.08.2015
PHP код:
new player1, tmp[256], playername[MAX_PLAYER_NAME];
new count = 0;
tmp = strtok(cmdtext, idx);
if(IsNumeric(tmp))
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
if(strval(tmp) == i)
player1 = i;
else
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
player1 = INVALID_PLAYER_ID;
}
}
}
else
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerName(i, playername, sizeof(playername));
if(IsPlayerConnected(i))
if(strfind(playername, tmp, true) != -1)
count++;
}
if(count == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
player1 = INVALID_PLAYER_ID;
}
else
{
if(count > 7)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Too many players matched your searched.");
player1 = INVALID_PLAYER_ID;
}
else if(count == 1)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, tmp, true) != -1)
player1 = j;
}
}
}
else if(count <= 7)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, tmp, true) != -1)
{
format(string,sizeof(string),"%s (%d)", playername, j);
SendClientMessage(playerid, COLOR_WHITE, string);
player1 = INVALID_PLAYER_ID;
continue;
}
}
}
SendClientMessage(playerid, COLOR_WHITE, "Error: More than one player found. Choose one of the IDs above.");
}
}
}
Sorry, forgot about PHP Code.
Re: Please help with script -
AkaSKY - 16.08.2015
Well, I tried to solve by myself:
PHP код:
SearchUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) // Strip out leading spaces
{
if(text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
new string[128], playername[MAX_PLAYER_NAME];
new count = 0;
if(IsNumeric(text[pos]))
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
if(strval(text[pos]) == i)
userid = i;
else
{
if(playerid != INVALID_PLAYER_ID)
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
userid = INVALID_PLAYER_ID;
}
}
}
else
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerName(i, playername, sizeof(playername));
if(IsPlayerConnected(i))
if(strfind(playername, text[pos], true) != -1)
count++;
}
if(count == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
userid = INVALID_PLAYER_ID;
}
else
{
if(count > 7)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Too many players matched your searched.");
userid = INVALID_PLAYER_ID;
}
else if(count == 1)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, text[pos], true) != -1)
userid = j;
}
}
}
else if(count <= 7)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, text[pos], true) != -1)
{
format(string,sizeof(string),"%s (%d)", playername, j);
SendClientMessage(playerid, COLOR_WHITE, string);
userid = INVALID_PLAYER_ID;
continue;
}
}
}
SendClientMessage(playerid, COLOR_WHITE, "Error: More than one player found. Choose one of the IDs above.");
}
}
}
return userid;
}
The problem now is that playerid (the one who made the search) won't recieve any message if there were found more than one players or if the player who was searching is not connected ("Error: Player not connected."). Any ideas?