if(strcmp(cmd, "/pickgun", true) == 0 || strcmp(cmd, "/pick", true) == 0)
{
if(MedicBill[playerid] == 1)
{
SendClientMessage(playerid, COLOR_GREY, " You have no access to grab items at your health.");
return 1;
}
if(IsPlayerInAnyVehicle(playerid)){ SendClientMessage(playerid, COLOR_GRAD1, "You can't grab anything right now.");return 1;}
for(new i = 0; i < sizeof(DropInfo); i++)
{
if (PlayerToPoint(0.6,playerid,DropInfo[i][dx],DropInfo[i][dy],DropInfo[i][dz])) // 0.6
{
if(GetPlayerVirtualWorld(playerid) == DropInfo[i][dWorld])
{
if(DropInfo[i][dType] == 1) // Weapons
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("gunpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up a weapon.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 2) // Crack
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("crackpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some crack.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 3) // Pot
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("potpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some pot.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 4) // Mats A
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d A materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMats] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 5) // Mats B
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d B materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMatsb] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 6) // Mats C
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d C materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMatsc] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 7) //Money
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("moneypick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some money.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab.");
return 1;
}
}
return 1;
}
else if(GetPlayerVirtualWorld(playerid) != DropInfo[i][dWorld])) { SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab."); return 1; }
new count; // .... { count++; } // After the loop. if (!count) return SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab.");
The problem is that you're breaking the loop by returning something.
Which means it will stop once "there's nothing close enough to grab" You should create a variable, that counts the amount of times it actually works. And then in the end, you check if that is equal to zero. If it is, you send the message. Код:
new count; // .... { count++; } // After the loop. if (!count) return SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab."); |
try
Код:
else if(GetPlayerVirtualWorld(playerid) != DropInfo[i][dWorld])) { SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab."); return 1; } |
if(strcmp(cmd, "/pickgun", true) == 0 || strcmp(cmd, "/pick", true) == 0)
{
if(MedicBill[playerid] == 1)
{
SendClientMessage(playerid, COLOR_GREY, " You have no access to grab items at your health.");
return 1;
}
if(IsPlayerInAnyVehicle(playerid)){ SendClientMessage(playerid, COLOR_GRAD1, "You can't grab anything right now.");return 1;}
new count = 0;
for(new i = 0; i < sizeof(DropInfo); i++)
{
if (PlayerToPoint(0.6,playerid,DropInfo[i][dx],DropInfo[i][dy],DropInfo[i][dz])) // 0.6
{
count++;
if(GetPlayerVirtualWorld(playerid) == DropInfo[i][dWorld])
{
if(DropInfo[i][dType] == 1) // Weapons
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("gunpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up a weapon.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 2) // Crack
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("crackpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some crack.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 3) // Pot
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("potpick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some pot.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(DropInfo[i][dType] == 4) // Mats A
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d A materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMats] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 5) // Mats B
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d B materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMatsb] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 6) // Mats C
{
ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s picks up %d C materials.",MaskOnOff(playerid),DropInfo[i][dAmount]);
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
PlayerInfo[playerid][pMatsc] += DropInfo[i][dAmount][0];
DropInfo[i][dAmount][0] = 0;
DropInfo[i][dType] = 0;
DestroyObject(DropObject[i]);
return 1;
}
if(DropInfo[i][dType] == 7) //Money
{
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
SetTimerEx("moneypick", 3000, 0, "i", playerid);
format(string, sizeof(string), "You kneel down to pick up some money.");
SendClientMessage(playerid, COLOR_GREY, string);
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
format(string,sizeof(string),"* %s kneels down to pick up something on the ground.",MaskOnOff(playerid));
ProxDetector(30.0,playerid,string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
}
}
}
if(count == 0)
{
SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab.");
return 1;
}
return 1;
}
If you use the "else" inside of the for it will always be called if you are not on the position and will return the for. Which will be the end and all other positions wont be asked. So just build in a counter for this.
|