Please help with script
#3

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 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
                if(
strval(text[pos]) == i)
                    
userid i;
                else
                 {
                     if(
playerid != INVALID_PLAYER_ID)
                         
SendClientMessage(playeridCOLOR_WHITE"Error: Player not connected.");
                    
userid INVALID_PLAYER_ID;
                }
        }
    }
    else
    {
        for(new 
0MAX_PLAYERSi++)
        {
            
GetPlayerName(iplayernamesizeof(playername));
            if(
IsPlayerConnected(i))
                if(
strfind(playernametext[pos], true) != -1)
                    
count++;
        }
        if(
count == 0)
        {
                  
SendClientMessage(playeridCOLOR_WHITE"Error: Player not connected.");
                   
userid INVALID_PLAYER_ID;
        }
        else
        {
            if(
count 7)
            {
                 
SendClientMessage(playeridCOLOR_WHITE"Error: Too many players matched your searched.");
                   
userid INVALID_PLAYER_ID;
            }
            else if(
count == 1)
            {
                for(new 
0MAX_PLAYERSj++)
                {
                    if(
IsPlayerConnected(j))
                    {
                        
GetPlayerName(jplayernamesizeof(playername));
                        if(
strfind(playernametext[pos], true) != -1)
                            
userid j;
                      }
                   }
               }
            else if(
count <= 7)
            {
                for(new 
0MAX_PLAYERSj++)
                {
                    if(
IsPlayerConnected(j))
                    {
                        
GetPlayerName(jplayernamesizeof(playername));
                        if(
strfind(playernametext[pos], true) != -1)
                        {
                            
format(string,sizeof(string),"%s (%d)"playernamej);
                            
SendClientMessage(playeridCOLOR_WHITEstring);
                            
userid INVALID_PLAYER_ID;
                            continue;
                          }
                       }
                   }
                   
SendClientMessage(playeridCOLOR_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?
Reply


Messages In This Thread
Please help with script - by AkaSKY - 16.08.2015, 12:02
Re: Please help with script - by AkaSKY - 16.08.2015, 12:14
Re: Please help with script - by AkaSKY - 16.08.2015, 13:48

Forum Jump:


Users browsing this thread: 4 Guest(s)