PDA

View Full Version : Help with for(new i = 0 and ....


aCloudy
12/03/2015, 03:57 PM
Hello everyone.
When i use this command (below), Only i get the weapon i write, But others don't get..
Can someone tell me why and fix it please?

The command:
CMD:giveweaponall(playerid,params[])
{
#pragma unused params
new string[128];
new Ammo;
new Wepid;
new ID;
if(AdminLevel[playerid] < 4) return SendClientMessage(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}You do not have the the right admin level for this command.");
if(sscanf(params,"ii",Wepid,Ammo))
{
SendClientMessage(playerid,COLOR_WHITE,""COL_USAGE"[SYNTAX] {FFFFFF}/giveweaponall [WEAPON_ID] [AMMO]");
return 1;
}
if(!IsValidWeapon(Wepid)) return SendClientMessage(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}Invalid weapon ID. Please enter a weapon ID between <1-18> || <22-46>.");
if(AdminLevel[playerid] < 5)
{
if(Wepid == 38) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 45) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 44) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 39) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 40) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 36) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
}
for(new i = 0; i<MAX_PLAYERS;i++)
{
if(JailTime[i] == 0)
{
GivePlayerWeapon(i,Wepid,Ammo);
}
format(string,sizeof(string),""COL_ADMIN"[ADMIN] {FFFFFF}All players have been given a %s from %s(%d)!",aWeaponNames[Wepid],PlayerName(playerid),ID);
SendClientMessageToAll(COLOR_WHITE,string);
format(string,sizeof(string),"%s(%d) has given all players a %s",PlayerName(playerid),playerid,aWeaponNames[Wepid]);
SendPROMessage(string);
return 1;
}
return 1;
}

Misiur
12/03/2015, 04:03 PM
Please, tabulate your code correctly, you'll see problems like that instantly.


CMD:giveweaponall(playerid,params[])
{
#pragma unused params
new string[128];
new Ammo;
new Wepid;
new ID;
if(AdminLevel[playerid] < 4) return SendClientMessage(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}You do not have the the right admin level for this command.");
if(sscanf(params,"ii",Wepid,Ammo))
{
SendClientMessage(playerid,COLOR_WHITE,""COL_USAGE"[SYNTAX] {FFFFFF}/giveweaponall [WEAPON_ID] [AMMO]");
return 1;
}
if(!IsValidWeapon(Wepid)) return SendClientMessage(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}Invalid weapon ID. Please enter a weapon ID between <1-18> || <22-46>.");
if(AdminLevel[playerid] < 5)
{
if(Wepid == 38) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 45) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 44) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 39) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 40) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
if(Wepid == 36) return SCM(playerid,COLOR_WHITE,"{AFAFAF}[Error]: {FFFFFF}This weapon is not allowed in this command.");
}

format(string,sizeof(string),""COL_ADMIN"[ADMIN] {FFFFFF}All players have been given a %s from %s(%d)!",aWeaponNames[Wepid],PlayerName(playerid),ID);
SendClientMessageToAll(COLOR_WHITE,string);

format(string,sizeof(string),"%s(%d) has given all players a %s",PlayerName(playerid),playerid,aWeaponNames[Wepid]);
SendPROMessage(string);

for(new i = 0; i < MAX_PLAYERS; i++)
{
if(JailTime[i] == 0)
{
GivePlayerWeapon(i,Wepid,Ammo);
}
}
return 1;
}

I moved "Player adsad has given..." as it's called using SendClientMessageToAll, we don't want it sent MAX_PLAYERS times, and I removed return in loop