help about refill all armour & health
#1

Hi me have a question

Why does this not armoured all players?

pawn Код:
CMD:armourall(playerid, params[])
{
    new str[128];
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_ORANGE, "** You are not logged in, please login first.");
    if(PlayerAcc[playerid][Admin] == 0) return SendClientMessage(playerid, -1,""orange"** Sorry, only admins level 4+ can do that command.");
    if(PlayerAcc[playerid][Admin] >= 4)
    {
        SetPlayerArmour(playerid, 100.0);
        format(str, sizeof(str), "~g~Free Armour!");
        GameTextForAll(str, 4000, 3);
        foreach(Player, i)
        {
            if(IsPlayerConnected(i) && (i != playerid) && (PlayerAcc[playerid][Admin] < PlayerAcc[i][Admin]))
            {
                SetPlayerArmour(i, 100.0);
            }
        }
        GameTextForAll("~g~FREE ARMOUR", 3000, 3);
        format(str, sizeof(str), "** Admin %s(ID:%d) has armoured all players.", GetName(playerid), playerid);
        SendClientMessageToAll(COLOR_YELLOW, str);
        SendClientMessage(playerid, COLOR_YELLOW, "** You armoured all players.");
    }
    else return ErrorMessages(playerid, 8);
    return 1;
}
And why does this not heal all players?

pawn Код:
CMD:healall(playerid, params[])
{
    new str[128];
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_ORANGE, "** You are not logged in, please login first.");
    if(PlayerAcc[playerid][Admin] == 0) return SendClientMessage(playerid, -1,""orange"** Sorry, only admins level 4+ can do that command.");
    if(PlayerAcc[playerid][Admin] >= 4)
    {
        foreach(Player, i)
        {
            if(IsPlayerConnected(i) && (i != playerid) && (PlayerAcc[playerid][Admin] < PlayerAcc[i][Admin]))
            {
                SetPlayerHealth(i, 100.0);
            }
        }
        GameTextForAll("~g~FREE HEALTH!", 3000, 3);
        format(str, sizeof(str), "** Admin %s(ID:%d) has healed all players.", GetName(playerid), playerid);
        SendClientMessageToAll(COLOR_YELLOW, str);
        SendClientMessage(playerid, COLOR_YELLOW, "** You have been succesfully healed all players.");
    }
    else return ErrorMessages(playerid, 8);
    return 1;
}
Thx for reading
Reply
#2

Because of all the checks in the loop?
Reply
#3

pawn Код:
CMD:healall(playerid, params[])
{
    new str[128];
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_ORANGE, "** You are not logged in, please login first.");
    if(PlayerAcc[playerid][Admin] < 4) return SendClientMessage(playerid, -1,""orange"** Sorry, only admins level 4+ can do that command.");
    else
    {
        foreach(new i : Player)
        {
            SetPlayerHealth(i, 100.0);
            GameTextForPlayer(i,"~g~FREE HEALTH!", 3000, 3)
        }
        format(str, sizeof(str), "** Admin %s(ID:%d) has healed all players.", GetName(playerid), playerid);
        SendClientMessageToAll(COLOR_YELLOW, str);
        SendClientMessage(playerid, COLOR_YELLOW, "** You have been succesfully healed all players.");
    }
    return 1;
}

CMD:armourall(playerid, params[])
{
    new str[128];
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_ORANGE, "** You are not logged in, please login first.");
    if(PlayerAcc[playerid][Admin] < 4) return SendClientMessage(playerid, -1,""orange"** Sorry, only admins level 4+ can do that command.");
    else
    {
        foreach(new i : Player)
        {
            SetPlayerArmour(i, 100.0);
            GameTextForPlayer(i,"~g~FREE ARMOUR!", 3000, 3)
        }
        format(str, sizeof(str), "** Admin %s(ID:%d) has armoured all players.", GetName(playerid), playerid);
        SendClientMessageToAll(COLOR_YELLOW, str);
        SendClientMessage(playerid, COLOR_YELLOW, "** You have been succesfully armoured all players.");
    }
    return 1;
}
With foreach, you don't need to check if the player is connected. This should work.
Reply
#4

You are checking and setting armour only to people who are of higher admin level than that of the guy who uses the command.

Check the condition inside the loop and you should know what you did wrong
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)