SA-MP Forums Archive
Sends 4 messages when its supposed to send 1 - 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: Sends 4 messages when its supposed to send 1 (/showthread.php?tid=442775)



Sends 4 messages when its supposed to send 1 - RedWolfX - 08.06.2013

When I use /search, it shows 2 messages that im not near a search place. Even if I am there. (But it does the search thing right)
Same goes with the Please wait before using /search message, but it sends the message 4 times. Should I use return 1; at the end of the mesages?

code:

Код:
CMD:search(playerid, params[])
{
 	if(IsPlayerInRangeOfPoint(playerid, 4.0, 1246.7194,-3652.2080,3.7651) || IsPlayerInRangeOfPoint(playerid, 4.0,1248.8490,-3652.5339,3.9919) || IsPlayerInRangeOfPoint(playerid, 4.0,1249.7378,-3655.0664,4.1358) || IsPlayerInRangeOfPoint(playerid, 4.0,1247.8719,-3657.1309,3.9854) || IsPlayerInRangeOfPoint(playerid, 4.0,1244.9426,-3657.2202,3.6845) || IsPlayerInRangeOfPoint(playerid, 4.0, 1247.7538,-3649.2112,3.8104) || IsPlayerInRangeOfPoint(playerid, 4.0,1249.3942,-3650.7388,4.0113) ||
	IsPlayerInRangeOfPoint(playerid, 4.0, 1252.5797,-3647.4241,4.2725) || IsPlayerInRangeOfPoint(playerid,4.0,1273.4034,-3637.6157,6.7242) || IsPlayerInRangeOfPoint(playerid, 4.0,1275.7910,-3638.0093,7.2448) || IsPlayerInRangeOfPoint(playerid,4.0,1273.6541,-3632.8669,6.7017) || IsPlayerInRangeOfPoint(playerid,4.0,1276.3198,-3632.5386,7.2707) || IsPlayerInRangeOfPoint(playerid,4.0,1249.0819,-3662.0967,4.2165) || IsPlayerInRangeOfPoint(playerid,4.0,1246.3524,-3665.5642,4.0018) ||
	IsPlayerInRangeOfPoint(playerid,4.0,1246.3524,-3665.5642,4.0018) || IsPlayerInRangeOfPoint(playerid,4.0,1248.5748,-3666.4690,4.2499) || IsPlayerInRangeOfPoint(playerid,4.0, 1246.8364,-3668.2712,4.1074) || IsPlayerInRangeOfPoint(playerid,4.0,1251.7527,-3675.4429,4.7630) || IsPlayerInRangeOfPoint(playerid,4.0,1252.2264,-3678.0854,4.8663) || IsPlayerInRangeOfPoint(playerid,4.0,1255.0496,-3677.4768,5.1456) || IsPlayerInRangeOfPoint(playerid,4.0,1257.0099,-3676.6565,5.3314))
	{
	    if(CantUseSearch[playerid] == 0)
	    {
	        if(PlayerInfo[playerid][pSlotsFree] == 20 && PlayerInfo[playerid][pBackPack] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
		 	if(PlayerInfo[playerid][pSlotsFree] == 50 && PlayerInfo[playerid][pBackPack] == 1)
		 	{
		 	    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
		 	if(PlayerInfo[playerid][pSlotsFree] == 100 && PlayerInfo[playerid][pBackPack] == 2)
		 	{
		 	    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
			if(PlayerInfo[playerid][pSlotsFree] == 150 && PlayerInfo[playerid][pBackPack] == 3)
			{
			    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
			}
			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s starts to search through the boxes", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] Searching ]]]",15000,3);
  			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			TogglePlayerControllable(playerid, 0);
            SetTimerEx("searchtimer", 15000, false, "i", playerid);
            CantUseSearch[playerid] = 1;
	    }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else
	{
	    SendClientMessage(playerid, RED, "[Survival:RP] Please wait before using /search again");
	}
	if(IsPlayerInRangeOfPoint(playerid, 4.0,1519.0341,-3711.8696,32.9301) || IsPlayerInRangeOfPoint(playerid, 4.0,1515.8898,-3714.2627,31.9744) || IsPlayerInRangeOfPoint(playerid, 4.0,1516.0928,-3709.7856,32.2328) || IsPlayerInRangeOfPoint(playerid, 4.0, 1516.4968,-3709.2048,32.4523))
	{
	    if(CantUseSearch[playerid] == 0)
	    {
		    new string[158];
		    new sendername[MAX_PLAYER_NAME];
		    GetPlayerName(playerid, sendername, sizeof(sendername));
		    GameTextForPlayer(playerid, "You Found Heroin", 3500, 5);
		    PlayerInfo[playerid][pHeroin] = 7;
			format(string, sizeof(string), "%s found some heroin on the plane", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			CantUseSearch[playerid] = 1;
			SetTimerEx("CantUseSearch", 30000, false, "d", playerid);
		}
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else
	{
	    SendClientMessage(playerid, RED, "[Survival:RP] Please wait before using /search again");
	}
    if(IsPlayerInRangeOfPoint(playerid, 4.0,1431.7667,-4116.2251,39.3396) || IsPlayerInRangeOfPoint(playerid, 4.0,1434.2880,-4115.0400,39.6731) || IsPlayerInRangeOfPoint(playerid, 4.0,1437.7614,-4115.1655,40.1456) || IsPlayerInRangeOfPoint(playerid, 4.0, 1438.4326,-4113.5010,39.7022) || IsPlayerInRangeOfPoint(playerid, 4.0, 1441.3405,-4114.0352,39.7828) || IsPlayerInRangeOfPoint(playerid,4.0, 1441.3645,-4116.3027,40.0068)
    || IsPlayerInRangeOfPoint(playerid, 4.0, 1428.0555,-4113.8413,38.6727) || IsPlayerInRangeOfPoint(playerid, 4.0, 1426.0809,-4111.9956,38.2932) || IsPlayerInRangeOfPoint(playerid, 4.0, 1423.6141,-4113.7314,37.9916) || IsPlayerInRangeOfPoint(playerid, 4.0, 1424.6029,-4116.1460,38.2452) || IsPlayerInRangeOfPoint(playerid, 4.0,1426.6079,-4115.9883,38.5439) || IsPlayerInRangeOfPoint(playerid, 4.0, 1418.4247,-4112.5679,37.1516))
	{
        if(CantUseSearch[playerid] == 0)
        {
			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s starts to search through the boxes", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] Searching ]]]",15000,3);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			TogglePlayerControllable(playerid, 0);
			SetTimerEx("shiptimer", 15000, false, "i", playerid);
			CantUseSearch[playerid] = 1;
        }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else
	{
	    SendClientMessage(playerid, RED, "[Survival:RP] Please wait before using /search again");
	}
    if(IsPlayerInRangeOfPoint(playerid, 4.0,530.7824,-2430.5693,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0, 533.0804,-2431.2258,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0,535.9420,-2433.0925,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.1736,-2434.9709,1198.2407) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.7724,-2432.1477,1198.2405) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.7792,-2430.6035,1198.2404))
	{
        if(PlayerInfo[playerid][pGun2] == 0)
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You cant search here yet!");
			return 1;
		}
		if(CantUseSearch[playerid] == 0)
        {

			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s finds ammunition for a deagle", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] You found ammo for a deagle ]]]",15000,3);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			PlayerInfo[playerid][pAmmo2] += 100;
			new ammo2 = PlayerInfo[playerid][pAmmo2];
			GivePlayerWeapon(playerid, 24, ammo2);
			CantUseSearch[playerid] = 1;
			SetTimerEx("CanUseSearch", 30000, false, "d", playerid);
        }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else
	{
	    SendClientMessage(playerid, RED, "[Survival:RP] Please wait before using /search again");
	}
	return 1;
}



Re: Sends 4 messages when its supposed to send 1 - Sascha - 09.06.2013

The order in which you write it is important! Your code checks whether the player is in the first bunch of ranges and sees "nope"... so it sends the message that you are not near or w/e.....
then it checks for the next if(IsPlayerInRange.... and sees "nope".. so it sends the message again, and so on...
so first check for all ranges with "else if" and finally use "else" for the "you are not in range" message,....
try this
Код:
CMD:search(playerid, params[])
{
 	if(IsPlayerInRangeOfPoint(playerid, 4.0, 1246.7194,-3652.2080,3.7651) || IsPlayerInRangeOfPoint(playerid, 4.0,1248.8490,-3652.5339,3.9919) || IsPlayerInRangeOfPoint(playerid, 4.0,1249.7378,-3655.0664,4.1358) || IsPlayerInRangeOfPoint(playerid, 4.0,1247.8719,-3657.1309,3.9854) || IsPlayerInRangeOfPoint(playerid, 4.0,1244.9426,-3657.2202,3.6845) || IsPlayerInRangeOfPoint(playerid, 4.0, 1247.7538,-3649.2112,3.8104) || IsPlayerInRangeOfPoint(playerid, 4.0,1249.3942,-3650.7388,4.0113) ||
	IsPlayerInRangeOfPoint(playerid, 4.0, 1252.5797,-3647.4241,4.2725) || IsPlayerInRangeOfPoint(playerid,4.0,1273.4034,-3637.6157,6.7242) || IsPlayerInRangeOfPoint(playerid, 4.0,1275.7910,-3638.0093,7.2448) || IsPlayerInRangeOfPoint(playerid,4.0,1273.6541,-3632.8669,6.7017) || IsPlayerInRangeOfPoint(playerid,4.0,1276.3198,-3632.5386,7.2707) || IsPlayerInRangeOfPoint(playerid,4.0,1249.0819,-3662.0967,4.2165) || IsPlayerInRangeOfPoint(playerid,4.0,1246.3524,-3665.5642,4.0018) ||
	IsPlayerInRangeOfPoint(playerid,4.0,1246.3524,-3665.5642,4.0018) || IsPlayerInRangeOfPoint(playerid,4.0,1248.5748,-3666.4690,4.2499) || IsPlayerInRangeOfPoint(playerid,4.0, 1246.8364,-3668.2712,4.1074) || IsPlayerInRangeOfPoint(playerid,4.0,1251.7527,-3675.4429,4.7630) || IsPlayerInRangeOfPoint(playerid,4.0,1252.2264,-3678.0854,4.8663) || IsPlayerInRangeOfPoint(playerid,4.0,1255.0496,-3677.4768,5.1456) || IsPlayerInRangeOfPoint(playerid,4.0,1257.0099,-3676.6565,5.3314))
	{
	    if(CantUseSearch[playerid] == 0)
	    {
	        if(PlayerInfo[playerid][pSlotsFree] == 20 && PlayerInfo[playerid][pBackPack] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
		 	else if(PlayerInfo[playerid][pSlotsFree] == 50 && PlayerInfo[playerid][pBackPack] == 1)
		 	{
		 	    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
		 	else if(PlayerInfo[playerid][pSlotsFree] == 100 && PlayerInfo[playerid][pBackPack] == 2)
		 	{
		 	    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
		 	}
			else if(PlayerInfo[playerid][pSlotsFree] == 150 && PlayerInfo[playerid][pBackPack] == 3)
			{
			    SendClientMessage(playerid, COLOR_WHITE, "You dont have any room left in your backpack");
	    		return 1;
			}
			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s starts to search through the boxes", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] Searching ]]]",15000,3);
  			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			TogglePlayerControllable(playerid, 0);
            SetTimerEx("searchtimer", 15000, false, "i", playerid);
            CantUseSearch[playerid] = 1;
	    }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else if(IsPlayerInRangeOfPoint(playerid, 4.0,1519.0341,-3711.8696,32.9301) || IsPlayerInRangeOfPoint(playerid, 4.0,1515.8898,-3714.2627,31.9744) || IsPlayerInRangeOfPoint(playerid, 4.0,1516.0928,-3709.7856,32.2328) || IsPlayerInRangeOfPoint(playerid, 4.0, 1516.4968,-3709.2048,32.4523))
	{
	    if(CantUseSearch[playerid] == 0)
	    {
		    new string[158];
		    new sendername[MAX_PLAYER_NAME];
		    GetPlayerName(playerid, sendername, sizeof(sendername));
		    GameTextForPlayer(playerid, "You Found Heroin", 3500, 5);
		    PlayerInfo[playerid][pHeroin] = 7;
			format(string, sizeof(string), "%s found some heroin on the plane", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			CantUseSearch[playerid] = 1;
			SetTimerEx("CantUseSearch", 30000, false, "d", playerid);
		}
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	if(IsPlayerInRangeOfPoint(playerid, 4.0,1431.7667,-4116.2251,39.3396) || IsPlayerInRangeOfPoint(playerid, 4.0,1434.2880,-4115.0400,39.6731) || IsPlayerInRangeOfPoint(playerid, 4.0,1437.7614,-4115.1655,40.1456) || IsPlayerInRangeOfPoint(playerid, 4.0, 1438.4326,-4113.5010,39.7022) || IsPlayerInRangeOfPoint(playerid, 4.0, 1441.3405,-4114.0352,39.7828) || IsPlayerInRangeOfPoint(playerid,4.0, 1441.3645,-4116.3027,40.0068)
    || IsPlayerInRangeOfPoint(playerid, 4.0, 1428.0555,-4113.8413,38.6727) || IsPlayerInRangeOfPoint(playerid, 4.0, 1426.0809,-4111.9956,38.2932) || IsPlayerInRangeOfPoint(playerid, 4.0, 1423.6141,-4113.7314,37.9916) || IsPlayerInRangeOfPoint(playerid, 4.0, 1424.6029,-4116.1460,38.2452) || IsPlayerInRangeOfPoint(playerid, 4.0,1426.6079,-4115.9883,38.5439) || IsPlayerInRangeOfPoint(playerid, 4.0, 1418.4247,-4112.5679,37.1516))
	{
        if(CantUseSearch[playerid] == 0)
        {
			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s starts to search through the boxes", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] Searching ]]]",15000,3);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			TogglePlayerControllable(playerid, 0);
			SetTimerEx("shiptimer", 15000, false, "i", playerid);
			CantUseSearch[playerid] = 1;
        }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
    if(IsPlayerInRangeOfPoint(playerid, 4.0,530.7824,-2430.5693,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0, 533.0804,-2431.2258,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0,535.9420,-2433.0925,1204.1504) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.1736,-2434.9709,1198.2407) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.7724,-2432.1477,1198.2405) || IsPlayerInRangeOfPoint(playerid, 4.0, 542.7792,-2430.6035,1198.2404))
	{
        if(PlayerInfo[playerid][pGun2] == 0)
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You cant search here yet!");
			return 1;
		}
		if(CantUseSearch[playerid] == 0)
        {

			new string[158];
			new sendername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "%s finds ammunition for a deagle", sendername);
			ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
			GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~]]] You found ammo for a deagle ]]]",15000,3);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			PlayerInfo[playerid][pAmmo2] += 100;
			new ammo2 = PlayerInfo[playerid][pAmmo2];
			GivePlayerWeapon(playerid, 24, ammo2);
			CantUseSearch[playerid] = 1;
			SetTimerEx("CanUseSearch", 30000, false, "d", playerid);
        }
	    else
		{
			SendClientMessage(playerid, RED, "[Survival:RP] You are not near the search place");
		}
	}
	else
	{
	    SendClientMessage(playerid, RED, "[Survival:RP] Please wait before using /search again");
	}
	return 1;
}