sscanf Bug
#1

I was scripting taxi job,and when i got to the /fare command part,i get bugs from sscanf.
There aren't compile errors/warnings just this bug.
So i used sscanf to print Driver [PLAYER NAME HERE] is now on duty.Fare [PRICE HE TYPED AFTER "/fare"] .
The bug is next:
-when i don't enter anything after fare it's supposed to print "USAGE: ..." but it prints that and
[MY NAME IG] is now on duty.Fare 0.
Prints the same thing when i type "/fare [SOME INTEGER HERE].
I checked multiple forums,and tested other peoples codes(which are like my one) and those codes also have bugs.
Here is the code:
Код:
CMD:fare (playerid, params[])
{
	new price;
	new string[128];
	new taxistName[MAX_PLAYER_NAME];
	
	
	if (sscanf(params, "i", price)) SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
	GetPlayerName(playerid, taxistName, MAX_PLAYER_NAME);
	format (string, sizeof(string), "Taxi driver %s is now on duty.Fare: %i .", taxistName,price);
	SendClientMessageToAll(0xFFFFCC, string);

	
	return 1;
}
Thanks in advance,i would really like to know how to solve this.
Reply
#2

pawn Код:
if (sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
You need to return a value to stop the rest of the code being executed.
Reply
#3

pawn Код:
if(sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
Reply
#4

Alright,thanks for replying and helping.
Reply
#5

In fact using sscanf() is a bad choice it's not needed at all.

Consider this.

pawn Код:
#define MIN_TAXI_PRICE 100
if (isnull(params)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
else price = strval(params);
if(price < MIN_TAXI_PRICE) return SendClientMessage(playerid, 0xFFF0F0, "That price is too low");
Reply
#6

Now it just sends "USAGE: /fare [PRICE]".
Код:
CMD:fare (playerid, params[])
{
	new price;
	new string[128];
	new taxistName[MAX_PLAYER_NAME];
	
	if (PlayerIsTaxiDriver[playerid]==1)
	{
		if (sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
		GetPlayerName(playerid, taxistName, MAX_PLAYER_NAME);
		format (string, sizeof(string), "Taxi driver %s is now on duty.Fare: %i .", taxistName,price);
		SendClientMessageToAll(0xFFFFCC, string);
	}
	else if (PlayerIsTaxiDriver[playerid]==0)
	{
	    SendClientMessage(playerid, CMD_ERROR, "You're not a taxi driver.");
	}

	
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)