SA-MP Forums Archive
params[0] problem. - 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: params[0] problem. (/showthread.php?tid=592030)



params[0] problem. - GuitarMan - 19.10.2015

Can someone please help me to find the mistake?

So, the problem is, params[0] acts weird... First of all it does not really check if params[0] is smaller or bigger then the allowed amount, also it takes less cash and less units then it should. I tried to debug it by printing the value of params[0], if the params are 20000, it would print that the params[0] value is 50... and i cant figure it out why.

HEres the code.
Код:
CMD:loadtruck(playerid, params[])
{
	if(PlayerLogged[playerid] == 0) return true;
	if(PlayerInfo[playerid][pJob] != J_TRUCKER) return SendClientMessage(playerid, COLOR_GREY, "This job is not suitable for you");
	if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You need to be the driver");
	if(IsPlayerInRangeOfPoint(playerid, 15.0 ,-2365.9382,-1362.3243,302.3563))
	{
	    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 406) return SendClientMessage(playerid, COLOR_GREY, "you have to be in dumper");
	    if(params[0] > 20000 || params[0]< 1) return SendClientMessage(playerid, COLOR_GREY, "You can only load between 1 - 20000 units");
	    if(params[0] > RudaStock) return SendClientMessage(playerid, COLOR_GREY, "Not enough units");
		if(GetMoney(playerid) < params[0]*2) return SendClientMessage(playerid, COLOR_GREY, "You dont have that much money.");
		GiveMoney(playerid, -params[0]*2);
		RudaStock = RudaStock - params[0];
		format(string, 50, "Params[0] = i", params[0]);
		SendClientMessage(playerid, COLOR_GREEN, string);

  		
	}

	return 1;
}
I am not rly changing the value of params anywhere...


Re: params[0] problem. - AndySedeyn - 19.10.2015

Params is a string with an indefinite size, not an integer. The number params[0] prints is the ASCII code for that character.
The ASCII table: http://www.asciitable.com/

As you can see the number '2' is represented as the integer 50.

Quote:
Originally Posted by Wiki
params[], is the string entered after the command



AW: params[0] problem. - Kaliber - 19.10.2015

Store it like this:

PHP код:
new units strval(params); 



Re: params[0] problem. - GuitarMan - 19.10.2015

Thank you, worked like a charm!