31.03.2012, 12:35
Harish, first of all, the code won't compile, because Max_PLAYERS is not a default definition. MAX_PLAYERS is. And for the sake of some efficiency, redefining it on top of your script would be handy unless your server actually has 500 slots.
Continuing, in the IsPlayerConnected check, you pass playerid as the parameter! - That is clearly wrong, you need to pass i instead.
Also, you can effectively combine 2 if-checks like this:
To this:
Ultimately, since IsPlayerAdmin is a native function of the SA-MP server, it already has an INBUILT connection check, so actually, your whole loop can be simplified to:
Continuing, the maximal possible length of "Admin (%d) : %s was online" is definitely not 256. Start off by reading this post (why not to make your strings 256 cells large).
Also, why do you even bother posting when you see that a suitable solution has already been given? Besides your code does not do what he asked for.
pawn Code:
#undef
#define MAX_PLAYERS 100 // for a server with 100 slots
Also, you can effectively combine 2 if-checks like this:
pawn Code:
if(IsPlayerConnected(i))
{
if(IsPlayerAdmin(i))
{
}
}
pawn Code:
if(IsPlayerConnected(i) && IsPlayerAdmin(i))
pawn Code:
for(new i = 0; i != MAX_PLAYERS; i++)
{
if(IsPlayerAdmin(i))
{
// code
}
}
Also, why do you even bother posting when you see that a suitable solution has already been given? Besides your code does not do what he asked for.