Admin list is not working properly
#1

So hi everyone I got problem.
If Admin 1 and(or) 2 is off not showing they are off. Always show they are online. What is wrong with this script?
It get's from database Admin names, ID. I set on gamemode init and onplayerconnect Player[playerid][Admin] = 0;
Код:
CMD:Adminlist(playerid,params[])
{
	mysql_function_query(g_SQL,"SELECT `username`,`Admin` FROM `players` WHERE `Admin` > 0;",true,"Admins","d",playerid);
	return 1;
}
forward AdminList(playerid);
public AdminList(playerid)
{
	new info[2048];
	if(cache_get_row_count() > 0)
	{
		for(new row = 0;row<cache_get_row_count();row++)
		{
			new Nickas[24],AdmID,id;
			cache_get_row(row, 0, Nickas);
			AdmID = cache_get_row_int(row, 1);
			printf("%s %i", Nickas, AdmID);
			if(!sscanf(Nickas, "u", id))
			{
				if(IsPlayerConnected(id))
				{
					switch(AdmID)
					{
						case 1:
						{
							new string[144];
							format(string, 144, "{FFFFFF}ON {00FF00}%s\n",Nickas);
							strcat(info, string);
						}
						case 2:
						{
							new string[144];
							format(string, 144, "{FFFFFF}ON {00FF00}%s\n",Nickas);
							strcat(info, string);
						}
					}
				}
				else
				{
					switch(AdmID)
					{
						case 1:
						{
							new string[144];
							format(string, 144, "{FFFFFF}OFF {FF0000}%s\n",Nickas);
							strcat(info, string);
						}
						case 2:
						{
							new string[144];
							format(string, 144, "{FFFFFF}OFF {FF0000}%s\n",Nickas);
							strcat(info, string);
						}
					}
				}
			}
		}
	}
	ShowPlayerDialog(playerid, 8, DIALOG_STYLE_MSGBOX, "List", info, "OK", "");
	return 1;
}
Reply
#2

Please help me
Reply
#3

Change ,true,"Admins","d",playerid);
To ,true,"AdminList","d",playerid);

Note that I put minimum effort into reading your code because I'm hungry and tired, but since no one else is responding...
Reply
#4

You dont have to always create threaded query, you can also use inline querys.
PHP код:

cmd
:adminlist(pid){
    new 
Cache:cq=mysql_query(g_SQL,"select username,Admin from players where Admin > 0"),
        
r=cache_num_rows(),
        
id,
        
bs[500]="There are no admins!",
        
name[24];
    if(
r){
        
bs[0]=EOS;
        for(new 
iri++){
            
cache_get_field_content(i,"username",name);
            
format(bs,sizeof(bs),"%s%s - %d: %s\n",bs,name,cache_get_field_content_int(i,"Admin"), (!sscanf(name,"u",id) && IsPlayerConnected(id))?("Online"):("Offline"));
        }
    }
    
cache_delete(cq);
    return 
ShowPlayerDialog(pid8DIALOG_STYLE_MSGBOX"List"bs"OK""");

Reply
#5

I did printf("%s %i", name, cache_get_field_content_int(i,"Admin")); and it's show this:
[16:15:17] Nick_Nick 1
[16:15:17] Nick_Name 2

But when I write /adminlist it shows that they are ON even they are off
Reply
#6

Quote:
Originally Posted by Darijus
Посмотреть сообщение
I did printf("%s %i", name, cache_get_field_content_int(i,"Admin")); and it's show this:
[16:15:17] Nick_Nick 1
[16:15:17] Nick_Name 2

But when I write /adminlist it shows that they are ON even they are off
update your sscanf or simple do its:

PHP код:
IsPlayerConnectedByName(const name[])
{
    for(new 
0MAX_PLAYERSi++)
    {
        new 
pNaMe[MAX_PLAYER_NAME];
        
GetPlayerName(ipNaMesizeof pNaMe);
        if(!
strcmp(pNaMenamefalse))
        {
            return 
true;
        }
    }
    return 
false;

and then
PHP код:
forward AdminList(playerid);
public 
AdminList(playerid)
{
    new 
info[2048];
    if(
cache_get_row_count() > 0)
    {
        for(new 
row 0;row<cache_get_row_count();row++)
        {
            new 
Nickas[24],AdmID,id;
            
cache_get_row(row0Nickas);
            
AdmID cache_get_row_int(row1);
            
printf("%s %i"NickasAdmID);
            if(
IsPlayerConnectedByName(Nickas))
            {
                switch(
AdmID)
                {
                    case 
1:
                    {
                        new 
string[144];
                        
format(string144"{FFFFFF}ON {00FF00}%s\n",Nickas);
                        
strcat(infostring);
                    }
                    case 
2:
                    {
                        new 
string[144];
                        
format(string144"{FFFFFF}ON {00FF00}%s\n",Nickas);
                        
strcat(infostring);
                    }
                }
            }
            else
            {
                switch(
AdmID)
                {
                    case 
1:
                    {
                        new 
string[144];
                        
format(string144"{FFFFFF}OFF {FF0000}%s\n",Nickas);
                        
strcat(infostring);
                    }
                    case 
2:
                    {
                        new 
string[144];
                        
format(string144"{FFFFFF}OFF {FF0000}%s\n",Nickas);
                        
strcat(infostring);
                    }
                }
            }
        }
    }
    
ShowPlayerDialog(playerid8DIALOG_STYLE_MSGBOX"List"info"OK""");
    return 
1;

Reply
#7

Still showing they are ON even they are off
Reply
#8

Quote:
Originally Posted by Darijus
Посмотреть сообщение
Still showing they are ON even they are off
ops, forgot player connected check.

PHP код:
IsPlayerConnectedByName(const name[])
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(!
IsPlayerConnected(i))
            continue;
        new 
pNaMe[MAX_PLAYER_NAME];
        
GetPlayerName(ipNaMesizeof pNaMe);
        if(!
strcmp(pNaMenamefalse))
        {
            return 
true;
        }
    }
    return 
false;

Reply
#9

Thanks. Working!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)