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



/admins acts weird - milanosie - 14.01.2012

Hello, Me and my friend are making a gamemode. Its going very well so far just have some minor problems.
This is a problem that I dont know how to fix:

The goal is to do /admins and then u see a list of all people online with AdminLevel 1 or higher.
But It now just shows this when there are 5 players online
players names are:
Maurits - admin lvl 0
Phil - admin lvl 0
Matt admin lvl 2
Ric - admin lvl 3
milan - admin lvl 5

Reality Roleplay Online Administrators:
[0]Maurits - lvl 0
[1]Maurits - lvl 0
[2]Maurits - lvl 0
[3]Maurits - lvl 0
[4]Maurits - lvl 0

Any idea what the problem could be?

Код:
CMD:admins(playerid, params[])
{
    new string[128], CountAdmins, Name[MAX_PLAYER_NAME];
    foreach(Player, i) {
        GetPlayerName(i, Name, sizeof(Name));
        if(PlayerInfo[playerid][AdminLevel] >= 1) {
            CountAdmins = 1;
        }
    }
    if(CountAdmins == 1) {
        SendClientMessage(playerid, 0xD8D8D8FF, "Reality Roleplay Online Administrators");
        foreach(Player, i) {
            if(PlayerInfo[playerid][AdminLevel] >= 1) {
                format(string, sizeof(string), "Admin: %s (ID: %d) - Level: %d", Name, i, PlayerInfo[i][AdminLevel]);
                SendClientMessage(playerid, 0xD8D8D8FF, string);
            }
        }
    }
    if(CountAdmins == 0) SendClientMessage(playerid, 0xD8D8D8FF, "There are no admins online!");
    CountAdmins = 0;
    return 1;
}



Re: /admins acts weird - Mean - 14.01.2012

pawn Код:
CMD:admins(playerid, params[])
{
    new string[128], CountAdmins, Name[MAX_PLAYER_NAME];
    foreach(Player, i) {
        GetPlayerName(i, Name, sizeof(Name));
        if(PlayerInfo[playerid][AdminLevel] >= 1) {
            CountAdmins = 1;
        }
    }
    if(CountAdmins == 1) {
        SendClientMessage(playerid, 0xD8D8D8FF, "Reality Roleplay Online Administrators");
        foreach(Player, i) {
            if(PlayerInfo[i][AdminLevel] >= 1) {
                format(string, sizeof(string), "Admin: %s (ID: %d) - Level: %d", Name, i, PlayerInfo[i][AdminLevel]);
                SendClientMessage(playerid, 0xD8D8D8FF, string);
            }
        }
    }
    if(CountAdmins == 0) SendClientMessage(playerid, 0xD8D8D8FF, "There are no admins online!");
    CountAdmins = 0;
    return 1;
}



Re: /admins acts weird - milanosie - 14.01.2012

what exactly did u change?


Re: /admins acts weird - Mean - 14.01.2012

I changed the line:
pawn Код:
if(PlayerInfo[i][AdminLevel] >= 1) {
Instead of i, you've put playerid. Common mistake.
Does it work? Because it should.


Re: /admins acts weird - milanosie - 14.01.2012

I will test in a minute
thanks for helping

U also have any idea how to fix this? https://sampforum.blast.hk/showthread.php?tid=310918


Re: /admins acts weird - Konstantinos - 14.01.2012

But you forgot to change it from the start.
pawn Код:
CMD:admins(playerid, params[])
{
    new string[128], CountAdmins, Name[MAX_PLAYER_NAME];
    foreach(Player, i) {
        GetPlayerName(i, Name, sizeof(Name));
        if(PlayerInfo[i][AdminLevel] >= 1) {
            CountAdmins = 1;
        }
    }
    if(CountAdmins == 1) {
        SendClientMessage(playerid, 0xD8D8D8FF, "Reality Roleplay Online Administrators");
        foreach(Player, i) {
            if(PlayerInfo[i][AdminLevel] >= 1) {
                format(string, sizeof(string), "Admin: %s (ID: %d) - Level: %d", Name, i, PlayerInfo[i][AdminLevel]);
                SendClientMessage(playerid, 0xD8D8D8FF, string);
            }
        }
    }
    if(CountAdmins == 0) SendClientMessage(playerid, 0xD8D8D8FF, "There are no admins online!");
    CountAdmins = 0;
    return 1;
}



Re: /admins acts weird - Mean - 14.01.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
But you forgot to change it from the start.
pawn Код:
CMD:admins(playerid, params[])
{
    new string[128], CountAdmins, Name[MAX_PLAYER_NAME];
    foreach(Player, i) {
        GetPlayerName(i, Name, sizeof(Name));
        if(PlayerInfo[i][AdminLevel] >= 1) {
            CountAdmins = 1;
        }
    }
    if(CountAdmins == 1) {
        SendClientMessage(playerid, 0xD8D8D8FF, "Reality Roleplay Online Administrators");
        foreach(Player, i) {
            if(PlayerInfo[i][AdminLevel] >= 1) {
                format(string, sizeof(string), "Admin: %s (ID: %d) - Level: %d", Name, i, PlayerInfo[i][AdminLevel]);
                SendClientMessage(playerid, 0xD8D8D8FF, string);
            }
        }
    }
    if(CountAdmins == 0) SendClientMessage(playerid, 0xD8D8D8FF, "There are no admins online!");
    CountAdmins = 0;
    return 1;
}
Ah yes, exactly.


Re: /admins acts weird - Lorenc_ - 14.01.2012

You should break the loop if there is a admin found.


Re: /admins acts weird - Mean - 14.01.2012

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
You should break the loop if there is a admin found.
True, but this isn't much of a huge loop, this loop doesn't even take 1ms to execute. It is always good to add it, but it's not needed here.

@Topic starter: if you want to break the loop, here:
pawn Код:
CMD:admins(playerid, params[])
{
    new string[128], CountAdmins, Name[MAX_PLAYER_NAME];
    foreach(Player, i) {
        GetPlayerName(i, Name, sizeof(Name));
        if(PlayerInfo[i][AdminLevel] >= 1) {
            CountAdmins = 1;
            break;
        }
    }
    if(CountAdmins == 1) {
        SendClientMessage(playerid, 0xD8D8D8FF, "Reality Roleplay Online Administrators");
        foreach(Player, i) {
            if(PlayerInfo[i][AdminLevel] >= 1) {
                format(string, sizeof(string), "Admin: %s (ID: %d) - Level: %d", Name, i, PlayerInfo[i][AdminLevel]);
                SendClientMessage(playerid, 0xD8D8D8FF, string);
            }
        }
    }
    if(CountAdmins == 0) SendClientMessage(playerid, 0xD8D8D8FF, "There are no admins online!");
    CountAdmins = 0;
    return 1;
}



Re: /admins acts weird - milanosie - 14.01.2012

It didnt work for me:/