Why is it switched up?
#1

I have this command:

Код:
CMD:tradecar(playerid, params[])
{	
	new id, dif, Float:x, Float:y, Float:z, string[256];
	if(sscanf(params, "r", id)) return SCM(playerid, COLOR_GRAD2, "Usage: {FFFFFF}/tradecar [playerid] + [difference]");
	if(!IsPlayerInAnyVehicle(playerid)) return SCM(playerid, -1, "You must be in your vehicle to use this command.");
	if(!IsPlayerInAnyVehicle(id)) return SCM(playerid, -1, "That user must be in his vehicle.");
	if(dif > playerVariables[playerid][pMoney]) return SCM(playerid, -1, "You don't have that much money.");
	new cf[128];
	format(cf, sizeof(cf), "You must wait %d seconds.", Cooldown[playerid]);
	if(Cooldown[playerid] > 0) return SCM(playerid, -1, cf);
	new hiscar = GetPlayerVehicleID(id);
	new mycar = GetPlayerVehicleID(playerid);
	new hid = GetVID(hiscar);
	new mid = GetVID(mycar);
	GetPlayerPos(id, x, y, z);
	if(vehStat[hid][vOwnerID] != playerVariables[id][pInternalID]) return SCM(playerid, -1, "That vehicle is not owned by that user.");
	if(vehStat[mid][vOwnerID] != playerVariables[playerid][pInternalID]) return SCM(playerid, -1, "That vehicle is not owned by you.");
	if(sscanf(params, "rd", id, dif))
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
		{
			MyTrade[playerid] = mycar;
			HisTrade[id] = hiscar;
			format(string, sizeof(string), "New Offer From %s", GetName(playerid));
			SCM(id, 0xFF99311EFF, string);
			format(string, sizeof(string), "%s want's to trade his: %s [%d] | %d days | %d KM | colors: %d - %d", GetName(playerid), VehicleNames[GetVehicleModel(mycar) - 400], vehStat[mid][vID], vehStat[mid][vDays], vehStat[mid][vKM], vehStat[mid][vColor1], vehStat[mid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "For your: %s [%d] | %d days | %d KM | colors: %d - %d + $%s difference from him.", VehicleNames[GetVehicleModel(hiscar) - 400], vehStat[hid][vID], vehStat[hid][vDays], vehStat[hid][vKM], vehStat[hid][vColor1], vehStat[hid][vColor2], NumberFormat(dif));
			SCM(id, COLOR_YELLOW, string);	
			HisMoney[playerid] = dif;
			format(string, sizeof(string), "Use /accept tradecar %d to trade your vehicle for %s's vehicle.", playerid, playerVariables[playerid][pNormalName]);
			SCM(id, COLOR_YELLOW, string);
			SCM(playerid, -1, "Offer has been sent 2.");
			TradeType[playerid] = 2;
		}
		else return SCM(playerid, -1, "You're not near that player.");
	}
	else
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
		{
			MyTrade[playerid] = mycar;
			HisTrade[id] = hiscar;
			format(string, sizeof(string), "New Offer From %s", GetName(playerid));
			SCM(id, 0xFF99311EFF, string);
			format(string, sizeof(string), "%s want's to trade his: %s [%d] | %d days | %d KM | colors: %d - %d", GetName(playerid), VehicleNames[GetVehicleModel(mycar) - 400], vehStat[mid][vID], vehStat[mid][vDays], vehStat[mid][vKM], vehStat[mid][vColor1], vehStat[mid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "For your: %s [%d] | %d days | %d KM | colors: %d - %d", VehicleNames[GetVehicleModel(hiscar) - 400], vehStat[hid][vID], vehStat[hid][vDays], vehStat[hid][vKM], vehStat[hid][vColor1], vehStat[hid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "Use /accept tradecar %d to trade your vehiclel for %s's vehicle.", playerid, playerVariables[playerid][pNormalName]);
			SCM(id, COLOR_YELLOW, string);
			SCM(playerid, -1, "Offer has been sent.");
			TradeType[playerid] = 1;
		}
		else return SCM(playerid, -1, "You're not near that player.");
	}
	return 1;
}
Whenever I use /tradecar [playerid] [difference]
this part gets called. This part should be called when you use /tradecar [playerid]. Not /tradecar [playerid] [difference]
Код:
else
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
		{
			MyTrade[playerid] = mycar;
			HisTrade[id] = hiscar;
			format(string, sizeof(string), "New Offer From %s", GetName(playerid));
			SCM(id, 0xFF99311EFF, string);
			format(string, sizeof(string), "%s want's to trade his: %s [%d] | %d days | %d KM | colors: %d - %d", GetName(playerid), VehicleNames[GetVehicleModel(mycar) - 400], vehStat[mid][vID], vehStat[mid][vDays], vehStat[mid][vKM], vehStat[mid][vColor1], vehStat[mid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "For your: %s [%d] | %d days | %d KM | colors: %d - %d", VehicleNames[GetVehicleModel(hiscar) - 400], vehStat[hid][vID], vehStat[hid][vDays], vehStat[hid][vKM], vehStat[hid][vColor1], vehStat[hid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "Use /accept tradecar %d to trade your vehiclel for %s's vehicle.", playerid, playerVariables[playerid][pNormalName]);
			SCM(id, COLOR_YELLOW, string);
			SCM(playerid, -1, "Offer has been sent.");
			TradeType[playerid] = 1;
		}
		else return SCM(playerid, -1, "You're not near that player.");
	}
Instead of this part.
Код:
if(sscanf(params, "rd", id, dif))
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
		{
			MyTrade[playerid] = mycar;
			HisTrade[id] = hiscar;
			format(string, sizeof(string), "New Offer From %s", GetName(playerid));
			SCM(id, 0xFF99311EFF, string);
			format(string, sizeof(string), "%s want's to trade his: %s [%d] | %d days | %d KM | colors: %d - %d", GetName(playerid), VehicleNames[GetVehicleModel(mycar) - 400], vehStat[mid][vID], vehStat[mid][vDays], vehStat[mid][vKM], vehStat[mid][vColor1], vehStat[mid][vColor2]);
			SCM(id, COLOR_YELLOW, string);	
			format(string, sizeof(string), "For your: %s [%d] | %d days | %d KM | colors: %d - %d + $%s difference from him.", VehicleNames[GetVehicleModel(hiscar) - 400], vehStat[hid][vID], vehStat[hid][vDays], vehStat[hid][vKM], vehStat[hid][vColor1], vehStat[hid][vColor2], NumberFormat(dif));
			SCM(id, COLOR_YELLOW, string);	
			HisMoney[playerid] = dif;
			format(string, sizeof(string), "Use /accept tradecar %d to trade your vehicle for %s's vehicle.", playerid, playerVariables[playerid][pNormalName]);
			SCM(id, COLOR_YELLOW, string);
			SCM(playerid, -1, "Offer has been sent 2.");
			TradeType[playerid] = 2;
		}
		else return SCM(playerid, -1, "You're not near that player.");
	}
Why is this happaning?
Reply
#2

Stop making multiple threads about the same issue.
https://sampforum.blast.hk/showthread.php?tid=612336
Reply
#3

Use strcmp to get the params. Then use scanff again.
And no. I wont post a code.
Reply
#4

sscanf returns 0 when succeed, and 1 when failed,
Код:
if(sscanf(params, "rd", id, dif))
{
the code under this statement is called when a failure occurs of sscanf function here.

the code under else { is called when sscanf returns 0 (success)

so, to check if sccanf succeed, which means it returned 0:
Код:
if(!sscanf(params, "Rd", id, dif))
that means if the function sscanf returned a zero, and without the NOT operator ("!") it means if the function returned another value higher than zero
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)