SA-MP Forums Archive
Cmd not working properly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Cmd not working properly (/showthread.php?tid=612417)



Cmd not working properly - MayaEU - 17.07.2016

Hello, this command worked perfectly untill i added the text "There's nothing close enough to grab."
now i can only pickup the first weapon that is dropped to the ground
what is wrong, i dont see anything..

pawn Код:
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;
    }



Re: Cmd not working properly - JXF - 17.07.2016

try
Код:
else if(GetPlayerVirtualWorld(playerid) != DropInfo[i][dWorld]))
	{
		SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab.");
		return 1;
	}



Re: Cmd not working properly - Stinged - 17.07.2016

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.");



Re: Cmd not working properly - MayaEU - 18.07.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
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.");
Can you help me with that, because i dont really understand it


Re: Cmd not working properly - MayaEU - 18.07.2016

Anyone?


Re: Cmd not working properly - MayaEU - 18.07.2016

Please help me this is very important


Re: Cmd not working properly - MayaEU - 18.07.2016

Quote:
Originally Posted by JXF
Посмотреть сообщение
try
Код:
else if(GetPlayerVirtualWorld(playerid) != DropInfo[i][dWorld]))
	{
		SendClientMessage(playerid, COLOR_GREY, "There's nothing close enough to grab.");
		return 1;
	}
Why would that work? its not the dWorld that is the problem


Re: Cmd not working properly - GangstaSunny - 18.07.2016

PHP код:
if(strcmp(cmd"/pickgun"true) == || strcmp(cmd"/pick"true) == 0)
{
    if(
MedicBill[playerid] == 1)
    {
        
SendClientMessage(playeridCOLOR_GREY" You have no access to grab items at your health.");
        return 
1;
    }
    if(
IsPlayerInAnyVehicle(playerid)){ SendClientMessage(playeridCOLOR_GRAD1"You can't grab anything right now.");return 1;}
    new 
count 0;
    for(new 
0sizeof(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.000000);
                    
SetTimerEx("gunpick"30000"i"playerid);
                    
format(stringsizeof(string), "You kneel down to pick up a weapon.");
                    
SendClientMessage(playeridCOLOR_GREYstring);
                    
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
                    
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.000000);
                    
SetTimerEx("crackpick"30000"i"playerid);
                    
format(stringsizeof(string), "You kneel down to pick up some crack.");
                    
SendClientMessage(playeridCOLOR_GREYstring);
                    
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000); // 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.000000);
                    
SetTimerEx("potpick"30000"i"playerid);
                    
format(stringsizeof(string), "You kneel down to pick up some pot.");
                    
SendClientMessage(playeridCOLOR_GREYstring);
                    
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000); // 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.000000); // 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.000000); // 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.000000); // 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.000000);
                    
SetTimerEx("moneypick"30000"i"playerid);
                    
format(stringsizeof(string), "You kneel down to pick up some money.");
                    
SendClientMessage(playeridCOLOR_GREYstring);
                    
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000); // 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(playeridCOLOR_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.


Re: Cmd not working properly - MayaEU - 18.07.2016

Quote:
Originally Posted by GangstaSunny
Посмотреть сообщение
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.
Thanks alot! rep+