/armorall and /healall
#1

Hello can some1 help me how to make /armorall and /healall to give to all players armor/health or some1 to make for me tnx
Reply
#2

pawn Код:
CMD:massarmor(playerid)
{
    if(PlayerInfo[playerid][pAdmin] >= 5)
    {
        foreach(Player, i)
        {
            SetPlayerArmour(i, 100);
        }
        BroadCast(COLOR_LIGHTBLUE, "An Admin has given Full Armor to Everyone!");
    }
    return 1;
}
CMD:massheal(playerid)
{
    if(PlayerInfo[playerid][pAdmin] >= 9998)
    {
        foreach(Player, i)
        {
            SetPlayerHealth(i, 100);
        }
        BroadCast(COLOR_LIGHTBLUE, "An Admin has given full health to Everyone!");
    }
    return 1;
}
Reply
#3

pawn Код:
CMD:armorall(playerid, params[])
{
    if(IsPlayerAdmin(playerid))//change to your admin system
    {
        SendClientMessageToAll(COLOR_GREEN, "All players healed by Admin");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerArmour(i, 100.0);
        }
    }
    else SendClientMessage(playerid,COLOR_RED,"You are not Admin!");
    return true;
}




CMD:healall(playerid, params[])
{
    if(IsPlayerAdmin(playerid))//change to your admin system
    {
        SendClientMessageToAll(COLOR_GREEN, "All players healed by Admin");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerHealth(i, 100.0);
        }
    }
    else SendClientMessage(playerid,COLOR_RED,"You are not Admin!");
    return true;
}

Drebin mean about dannyk0ed not mine xD
Reply
#4

For the first example you need foreach by ****** and ZCMD by ZeeX (for the second too).

Better use this:
pawn Код:
if (strcmp("/healall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerHealth(i, 100.0);
        }
        return 1;
    }
    if (strcmp("/armourall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerArmour(i, 100.0);
        }
        return 1;
    }
Reply
#5

Quote:
Originally Posted by Drebin
Посмотреть сообщение
For the above example you need foreach by ****** and ZCMD by ZeeX.

Better use this:
pawn Код:
if (strcmp("/healall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerHealth(playerid, 100.0);
        }
        return 1;
    }
    if (strcmp("/armourall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerArmour(playerid, 100.0);
        }
        return 1;
    }
Sorry, i was rushing.
Reply
#6

Quote:
Originally Posted by Drebin
Посмотреть сообщение
For the first example you need foreach by ****** and ZCMD by ZeeX (for the second too).

Better use this:
pawn Код:
if (strcmp("/healall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerHealth(i, 100.0);
        }
        return 1;
    }
    if (strcmp("/armourall", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetPlayerArmour(i, 100.0);
        }
        return 1;
    }
it gives me errors
Reply
#7

Quote:
Originally Posted by imnoob
Посмотреть сообщение
it gives me errors
Post the errors here and show which line is which.

Also change "MAX_PLAYERS" to the number of slots you have.
Reply
#8

CMD:healall(playerid,params[]) {
#pragma unused params
if(PlayerInfo[playerid][Level] >= 1) {
CMDMessageToAdmins(playerid,"HEALALL");
for(new i = 0; i < MAX_PLAYERS; i++) {
if(IsPlayerConnected(i) && (i != playerid) && i != ServerInfo[MaxAdminLevel]) {
PlayerPlaySound(i,1057,0.0,0.0,0.0); SetPlayerHealth(i,100.0);
}
}
new string[128]; format(string,sizeof(string),"Administrator \"%s\" has healed all players", pName(playerid) );
return SendClientMessageToAll(blue, string);
} else return SendClientMessage(playerid,red,"ERROR: You need to be level 3 to use this command");
}

CMD:armourall(playerid,params[]) {
#pragma unused params
if(PlayerInfo[playerid][Level] >= 1) {
CMDMessageToAdmins(playerid,"ARMOURALL");
for(new i = 0; i < MAX_PLAYERS; i++) {
if(IsPlayerConnected(i) && (i != playerid) && i != ServerInfo[MaxAdminLevel]) {
PlayerPlaySound(i,1057,0.0,0.0,0.0); SetPlayerArmour(i,100.0);
}
}
new string[128]; format(string,sizeof(string),"Administrator \"%s\" has restored all players armour", pName(playerid) );
return SendClientMessageToAll(blue, string);
} else return SendClientMessage(playerid,red,"ERROR: You need to be level 3 to use this command");
}
Reply
#9

It is always better to use foreach instead of using "for" (normal) loop.

-FalconX
Reply
#10

Quote:
Originally Posted by FalconX
Посмотреть сообщение
It is always better to use foreach instead of using "for" (normal) loop.

-FalconX
Wrong, using single statements in a regular 'for' loop is considerably better than using foreach. Also, if you're gonna check for a SA:MP 'variable' in a loop, it's better to use foreach. Examples of where 'for' is better:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerAdmin(i))
    {
        // code
    }
}
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    variable[i] = 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)