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



/admins confused - tyler12 - 15.08.2012

pawn Code:
CMD:admins(playerid,params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(Duty[i] == 1)
        {
        new string[124];
        format(string,sizeof(string),"%s",GetName(i));
        SendClientMessage(playerid,-1,string);
        }
        if(Duty[i] == 0)
        {
        SendClientMessage(playerid,-1,"No admins online");
        }
    }
    return 1;
}
I dont know where to send the message. I know not to do it in le' loop but im not sure where else to put it. Any help would be appreciated..

- tyler.


Re: /admins confused - CROSS_Hunter - 15.08.2012

whats the exact problem?


Re: /admins confused - tyler12 - 15.08.2012

Quote:
Originally Posted by CROSS_Hunter
View Post
whats the exact problem?
Its in a loop, it sends the message alot. I just dont know where to put the code.


Re: /admins confused - sansko - 15.08.2012

You are looping trough all the players and if they arn't admin you will get the message for each player online. you need to check outside the loop if any admin is online and if not, send the message.


Re: /admins confused - ryansheilds - 15.08.2012

pawn Code:
CMD:admins(playerid,params[])
{
    new count = 0, string[128];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(Duty[i] == 1)
        {
            new string[124];
            format(string,sizeof(string),"%s",GetName(i));
            SendClientMessage(playerid,-1,string);
            count ++;
        }
    }
    if(count == 0)
    {
        SendClientMessage(playerid,-1,"No admins online");
    }
    return 1;
}



Re: /admins confused - Jessyy - 15.08.2012

Try this ...
Code:
acmd:admins(playerid, params[], bool:help)
{
	new string[128], bool:dfound = false, dcount = 0;
	for(new i = 0; i < GetMaxPlayers(); i++) {
		if(Duty[i] != 1) continue;
		
		if(dcount == 0) {
			dfound = true; dcount += 1;
			format(string, sizeof(string), "%s", GetName(i));
		} else {
			dcount += 1;
			format(string, sizeof(string), "%s, %s", string, GetName(i));
		}
		
		if(dcount == 6) {
			dcount = 0;
			SendClientMessage(playerid, -1, string);
		}
	}
	if(dcount != 0) {
		SendClientMessage(playerid, -1, string);
	}
	if(!dfound) {
		SendClientMessage(playerid, -1, "No admins online");
	}
	return 1;
}