Help with for(new i = 0 and ....
#1

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:
PHP Code:
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 
0i<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;

Reply
#2

Please, tabulate your code correctly, you'll see problems like that instantly.


pawn Code:
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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)