/admins acts weird
#1

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;
}
Reply
#2

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;
}
Reply
#3

what exactly did u change?
Reply
#4

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.
Reply
#5

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
Reply
#6

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;
}
Reply
#7

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.
Reply
#8

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

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;
}
Reply
#10

It didnt work for me:/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)