/armorall and /healall -
imnoob - 04.06.2012
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
Re: /armorall and /healall -
dannyk0ed - 04.06.2012
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;
}
Re: /armorall and /healall -
doreto - 04.06.2012
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
AW: /armorall and /healall -
Drebin - 04.06.2012
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;
}
Re: AW: /armorall and /healall -
dannyk0ed - 04.06.2012
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.
Re: AW: /armorall and /healall -
imnoob - 04.06.2012
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
Re: AW: /armorall and /healall -
DaRealShazz - 04.06.2012
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.
Re: /armorall and /healall -
AbO.SbRe - 04.06.2012
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");
}
Re: /armorall and /healall -
FalconX - 04.06.2012
It is always better to use foreach instead of using "for" (normal) loop.
-FalconX
Re: /armorall and /healall -
SuperViper - 04.06.2012
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;
}