SA-MP Forums Archive
Loop ends up with Spamming. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loop ends up with Spamming. (/showthread.php?tid=77678)



Loop ends up with Spamming. - shitbird - 13.05.2009

Allright, so i'm trying to do a decent /report command using DCMD + sscanf... apparently it is working, however it doesnt stop looping, and if it doesnt stop looping, it spams the IRC channel we are using to ECHO in, can someone try to explain to me, why it is bugging...

pawn Код:
dcmd_report(playerid, params[])
{
    new id, pName[MAX_PLAYER_NAME], iName[MAX_PLAYER_NAME], string[128], reason[128];
    if (sscanf(params, "us", id,reason)) SendClientMessage(playerid, COLOR_RED, "Usage: \"/report <playerid> <reason>\"");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Player not found");
    else
    {
      GetPlayerName(playerid, pName,sizeof(pName));
      GetPlayerName(id, iName,sizeof(iName));
        format(string,sizeof(string),"%s[%d] Reported %s[%d] For: '%s'",pName,playerid,iName,id,reason);
        for(new i; i <MAX_PLAYERS; i++)
        if(AdminLevel[i] >= 0)
        {
            SendClientMessage(i,COLOR_PURPLE,string);
            ircSay(EchoConnection, EchoChan,string);
        }
        return 1;
    }
    return 1;
}



Re: Loop ends up with Spamming. - dice7 - 13.05.2009

You could just break; after ircSay


Re: Loop ends up with Spamming. - Donny_k - 13.05.2009

pawn Код:
for(new i; i <MAX_PLAYERS; i++) //repeat two hundred times
        if(AdminLevel[i] >= 0) //if 'i' has a level which is equal or greater than zero
        {
            SendClientMessage(i,COLOR_PURPLE,string); //send a message to the 'i'
            ircSay(EchoConnection, EchoChan,string); //send a message to the IRC
        }
Anyone without a negative admin level will be sent a message.


Re: Loop ends up with Spamming. - Think - 13.05.2009

replace this code:

pawn Код:
for(new i; i <MAX_PLAYERS; i++)
        if(AdminLevel[i] >= 0)
        {
            SendClientMessage(i,COLOR_PURPLE,string);
            ircSay(EchoConnection, EchoChan,string);
        }
with this and try again:

pawn Код:
for(new i; i <MAX_PLAYERS; i++) {
        if(AdminLevel[i] > 0) // itll check if your adminlevel is higher than 0 i guess 0 isn't admin.
        {
            SendClientMessage(i,COLOR_PURPLE,string);
        }
        }
        ircSay(EchoConnection, EchoChan,string);



Re: Loop ends up with Spamming. - Weirdosport - 13.05.2009

If you only want it said once in the IRC chat keep that out of the loop, and then change your >= to a > as someone already said.