SA-MP Forums Archive
/admins - 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: /admins (/showthread.php?tid=305448)



/admins - Artix - 22.12.2011

Hello how can i made a /admin command with this code
i mean
i want to detect that
if the player is level 1 it would say Moderator

Level 1 : Test
Level 2 : Moderator
Level 3 : Administrator
Level 4 : Owner

what will i do ? please help me

/admin


Код:
CMD:setlevel(playerid, params[])
{
	if(Pinfo[playerid][pLevel] >= 4 || IsPlayerAdmin(playerid))
	{
		new pID, Level;
		if(Level<1 || Level>4) return SendClientMessage(playerid, ERROR, "Admins are only from level 4.");
		if(sscanf(params, "ui", pID, Level)) return SendClientMessage(playerid, ERROR, "[Usage]: /SetLevel < Player ID > < Level >");

		if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "That user is not connected!");

		format(Msg, sizeof(Msg), "Admin: %s(%d) has given you admin level: %d", pName(playerid), playerid, Level);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, Msg);

		format(Msg, sizeof(Msg), "You have been given admin level: %d to: %s(%d)", Level, pName(pID), pID);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, Msg);

		return Pinfo[pID][pLevel] = Level;
	}
	else return AdminCMD(playerid, 3);
}



Re: /admins - [ABK]Antonio - 22.12.2011

Is this what you mean?

pawn Код:
CMD:admins(playerid)
{
    new str[128], thename[MAX_PLAYER];
    for(new i; i<=MAX_PLAYERS; i++) //create a loop
    {
        switch(Pinfo[i][pLevel]) //Using a switch just because it's easier and I heard it's better for performance
        {
            case 1: //level 1
            {
                GetPlayerName(i, thename, sizeof(thename)); //get their names
                format(str, sizeof(str), "Level 1: %s - Test", thename); //format our string so we can send it
                SendClientMessage(playerid, 0x00CC00AA, str); //Send it
            }
            case 2: //level 2
            {
                GetPlayerName(i, thename, sizeof(thename)); //get their names
                format(str, sizeof(str), "Level 2: %s - Moderator", thename); //format our string so we can send it
                SendClientMessage(playerid, 0x00CC00AA, str); //Send it
            }
            case 3: //level 3
            {
                GetPlayerName(i, thename, sizeof(thename)); //get their names
                format(str, sizeof(str), "Level 3: %s - Administrator", thename); //format our string so we can send it
                SendClientMessage(playerid, 0x00CC00AA, str); //Send it
            }
            case 4: //level 4
            {
                GetPlayerName(i, thename, sizeof(thename)); //get their names
                format(str, sizeof(str), "Level 4: %s - Owner", thename); //format our string so we can send it
                SendClientMessage(playerid, 0x00CC00AA, str); //Send it
            }
        }
    }
    return 1;
}



Re: /admins - wildcookie007 - 22.12.2011

Use a loop and check if there admins above level 0, if there is make another check if there are level 1 admins then use format(str,sizeof(str),"Moderator: %s",pName(i)); sendmsg.. then repeat doing checks if there is level 2 level 3 etc. Should work, tho I'm not 100% sure.

edit: ah ye, code above me, didn't see that.


Re: /admins - Moras - 22.12.2011

PHP код:
stock GetPlayerAdmin(adminid) {
    new 
        
adm_level[10];
    switch(
adminid) {
        case 
0adm_level "User";
        case 
1adm_level "Test";
        case 
2adm_level "Moderator";
        case 
3adm_level "Administrator";
        case 
4adm_level "Owner"
    }
    return 
adm_level;

Example:
PHP код:
CMD:admins(playerid) {
    new 
        
big_str[512],
        
tiny_str[255],
        
adm_idx 0;
    for(new 
i<= GetMaxPlayers(); i++) {
        if(
Pinfo[i][pLevel] > 0) {
            
adm_idx++;
            
format(tiny_str,sizeof(tiny_str),"%s(%d) - Level: %s",pName(playerid),i,GetPlayerAdmin(Pinfo[i][pLevel]));
            
strcat(big_str,tiny_str);
        }
    }
    if(
adm_idx == 0strcat(big_str"No admins online");
    return 
ShowPlayerDialog(playerid,YOU_DIALOG_ID,0,"Admins",big_str,"OK","");