Message appear four times
#1

Why does the error message appear four times?

Code:
if(cargopicked[playerid] == 1)
	{
	    for(new i; i < sizeof(meatcar); i++)
	    {
			if(IsPlayerInRangeOfVehicle(playerid, meatcar[i], 4))
			{
			    RemovePlayerAttachedObject(playerid, 0);
			    SendClientMessage(playerid, COLOR_YELLOW, "You loaded the cargo into the van, now get inside and drive it.");
			    SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "** %s places the bag of meat in the back of the van.", ReturnName(playerid, 0));
			}
			else
			{
			    SendClientMessage(playerid, COLOR_GREY, "You are not behind a van.");
			}
		}
	}
This message appear even if I do the thing right and it displays four times
Code:
SendClientMessage(playerid, COLOR_GREY, "You are not behind a van.");
Reply
#2

Which callback are you using for this code or it`s just command?
Reply
#3

Show your function IsPlayerInRangeOfVehicle
Reply
#4

Code:
stock IsPlayerInRangeOfVehicle(playerid, vehicleid, Float:Range)
{
    new Float:Pos[3];
	GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
	return IsPlayerInRangeOfPoint(playerid, Range, Pos[0], Pos[1], Pos[2]);
}


Code:
CMD:loadcargo(playerid, params[])
{
	if(cargopicked[playerid] == 1)
	{
	    for(new i; i < sizeof(meatcar); i++)
	    {
			new vehicleid = meatcar[i];
			if(IsPlayerInRangeOfVehicle(playerid, meatcar[i], 4))
			{
			    RemovePlayerAttachedObject(playerid, 0);
			    SendClientMessage(playerid, COLOR_YELLOW, "You loaded the cargo into the van, now get inside and drive it.");
			    SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "** %s places the bag of meat in the back of the van.", ReturnName(playerid, 0));
				ClearAnimations(playerid, 1);
				SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
				loadedcargo[vehicleid]++;
			}
			else
			{
			    SendClientMessage(playerid, COLOR_GREY, "You are not behind a van.");
			}
		}
	}
	return 1;
}

CMD:checkcargo(playerid, params[])
{
	new string[40];
	for(new i; i < sizeof(meatcar); i++)
 	{
		new vehicleid = meatcar[i];
		if(IsPlayerInRangeOfVehicle(playerid, meatcar[i], 4))
		{
			format(string, sizeof(string), "You have %d bags of meat loaded.", loadedcargo[vehicleid]);
			SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
		}
		else
		{
  			SendClientMessage(playerid, COLOR_GREY, "You are not behind a van.");
		}
	}
	return 1;
}
Reply
#5

Try this
PHP Code:
CMD:loadcargo(playeridparams[])
{
    if(
cargopicked[playerid] == 1)
    {
        for(new 
isizeof(meatcar); i++)
        {
            new 
vehicleid meatcar[i];
            if(
IsPlayerInRangeOfVehicle(playeridmeatcar[i], 4))
            {
                
RemovePlayerAttachedObject(playerid0);
                
SendClientMessage(playeridCOLOR_YELLOW"You loaded the cargo into the van, now get inside and drive it.");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s places the bag of meat in the back of the van."ReturnName(playerid0));
                
ClearAnimations(playerid1);
                
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
                
loadedcargo[vehicleid]++;
                break;
//got what you want, stop looping..
            
}
            else
            {
                
SendClientMessage(playeridCOLOR_GREY"You are not behind a van.");
            }
        }
    }
    return 
1;

Reply
#6

Simply because you shouldn't send a message when a player isn't even close to a vehicle when looping, right place to send that is outside the loop, if everything fails.
PHP Code:
for(...)
{
        ...
}
SendClientMessage(playeridCOLOR_GREY"You are not behind any van."); 
And you also need to return when finding the right vehicle to load cargo behind, so it won't keep looping.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)