Admin Dialog
#1

Hey, i need your help guys
I want to create /admins command in dialog

If you can help me, please do it, I'll rep!

Код:
dcmd_admins(playerid,params[])
{
    #pragma unused params

    new count, bool:online, string[1024];
    for(new i,g=GetMaxPlayers(); i < g; i++)
	{
    if(IsPlayerConnected(i))
        {
            if(1 <= PlayerInfo[i][Level] <= 6 && PlayerInfo[i][Hide] == 0)
            {
                on‌line = true;
                switch(PlayerInfo[i][Level])
                {
                                        case 1: Ranks = "{FF0000}Tester";
                                        case 2: Ranks = "{FF0000}Moderator";
                                        case 3: Ranks = "{FFAE00}Co-Admin{FF0000}";
                                        case 4: Ranks = "{FF0000}Admin";
                                        case 5: Ranks = "{FFFFFF}Leader{FF0000}";
                                        case 6: Ranks = "{00FFFF}Manager{FF0000}";
                }
                if(IsPlayerAdmin(i)) Ranks = "{00FF00}RCON Manager{FF0000}";
                format(string,sizeof(string), "%s %s [%s], ",string,PlayerName2(i),Ranks);
                count++;
                if(count == 3)
                {
                    format(string,sizeof(string),"{00FFFF}Admins:{FF0000} %s %s",string);
                    SendClientMessage(playerid, blue, string);
                    string = "";
                    count = 0;
                }
            }
        }
    }
    if(count)
    {
        format(string,sizeof(string),"{00FFFF}Admins:{FF0000} %s %s",string);
        SendClientMessage(playerid, red, string);
    }
    if(!online) SendClientMessage(playerid,red,"No admins online");
    return 1;
    }
Reply
#2

Use it: https://sampwiki.blast.hk/wiki/OnDialogResponse
Reply
#3

Код:
dcmd_admins(playerid)
{
	new count, string[1024], lvl;
	for(new i,g=GetMaxPlayers(); i < g; i++)
	{
		if(IsPlayerConnected(i))
        	{
			if(!PlayerInfo[i][Hide])
			{
				lvl = PlayerInfo[i][Level];
				if(0 < lvl)
				{
					if(lvl < 7)
					{
		        			new Ranks[28];
		         			switch(lvl)
		                		{
							case 1: strcat(Ranks, "{FF0000}Tester");
							case 2: strcat(Ranks, "{FF0000}Moderator");
							case 3: strcat(Ranks, "{FFAE00}Co-Admin{FF0000}");
							case 4: strcat(Ranks, "{FF0000}Admin");
							case 5: strcat(Ranks, "{FFFFFF}Leader{FF0000}");
							case 6: strcat(Ranks, "{00FFFF}Manager{FF0000}");
						}
		                		if(IsPlayerAdmin(i)) Ranks = "{00FF00}RCON Manager{FF0000}";
		                		format(string,sizeof(string), "%s%s [%s]\n",string,PlayerName2(i),Ranks);
		                		count++;
					}
				}
			}
		}
	}
	if(count > 0) ShowPlayerDialog(playerid, 6969, DIALOG_STYLE_MSGBOX, "Online Admins",string,"ok","");
	else ShowPlayerDialog(playerid, 6969, DIALOG_STYLE_MSGBOX, "Online Admins","No admins online","ok","");
	return 1;
}
Some advice:

-Stop using pragma unused params shit.
-Use foreach instead of normal loop, foreach loops through connected players only thus it is faster.
-Try as much as possible to use > and < instead of >= and <= (if possible of course), this will optimize your codes when it's about big loops and heavier codes (not in this case but it's better to get change some coding habits)
-Two if checks are faster than &&
-You're checking the PlayerInfo[i][Level] variable three times, instead you can create a local variable that will retrieve the level in pinfo array only one time which will be faster (not really sure though whether it would be better if that local variable is created before the loop or at each loop)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)