SA-MP Forums Archive
This function fails to show an a Message when playercount hits 0. - 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: This function fails to show an a Message when playercount hits 0. (/showthread.php?tid=375022)



This function fails to show an a Message when playercount hits 0. - HydraX - 04.09.2012

pawn Код:
IRCCMD:admins(botid, channel[], user[], host[], params[])
{
    new msg[128], msg1[50], AdmRank[128], playeramount; //Increase str to a suitable number
    foreach(Player, i)
    {
        if(PlayerInfo[i][pAdmin] == 0) { AdmRank = "Regular Player"; }
        else if(PlayerInfo[i][pAdmin] == 1) { AdmRank = "Moderator"; }
        else if(PlayerInfo[i][pAdmin] == 2) { AdmRank = "Professional Moderator"; }
        else if(PlayerInfo[i][pAdmin] == 3) { AdmRank = "Administrator"; }
        else if(PlayerInfo[i][pAdmin] == 4) { AdmRank = "Head Administrator"; }
        else if(PlayerInfo[i][pAdmin] >= 5) { AdmRank = "Owner"; }
        if(PlayerInfo[i][pAdmin] > 0 && IsPlayerConnected(i))
        {
            new name[90];
            GetPlayerName(i,name,sizeof(name));
            format(msg,sizeof(msg),"8,1***%s %s (%d)",AdmRank, name, i);
            GetPlayerName(i,name,sizeof(name));
            playeramount ++;
        }
        if(playeramount == 0) return format(msg1,sizeof(msg1), "No admins are online"); IRC_GroupSay(groupID, channel, msg1);
        IRC_GroupSay(groupID, channel, msg); //Shows dialog with admins, one button "Close"
    }
    return 1;
}
The function, if playeramount = 0, should return a message saying No admins are online, but fails to show when I type !admins, however when someone is online, it shows the admins online.


Re: This function fails to show an a Message when playercount hits 0. - mamorunl - 04.09.2012

Your playeramount check is inside the foreach loop. Put it outside the foreach


Respuesta: Re: This function fails to show an a Message when playercount hits 0. - HydraX - 04.09.2012

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
Your playeramount check is inside the foreach loop. Put it outside the foreach
Are you sure? Isn't the playeramount++ count how many admins are online when it loops through players, with a level 1 or higher?


Re: This function fails to show an a Message when playercount hits 0. - mamorunl - 04.09.2012

Yea, I meant this one:

pawn Код:
if(playeramount == 0) return format(msg1,sizeof(msg1), "No admins are online");
Also, if you return a formatted text it will still not show up!

So I take it that it has to be like this:

pawn Код:
if(playeramount == 0) { format(msg1,sizeof(msg1), "No admins are online");
return IRC_GroupSay(groupID, channel, msg1);
}



Respuesta: Re: This function fails to show an a Message when playercount hits 0. - HydraX - 04.09.2012

Why thank you ! :P


Re: This function fails to show an a Message when playercount hits 0. - mamorunl - 04.09.2012

Not a problem. We had a similar problem once in the dutch section