SA-MP Forums Archive
A little params 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: A little params problem (/showthread.php?tid=407255)



A little params problem - Frede - 13.01.2013

i got a little problem. Acctully i could make it alot of different way, but now i have found this, i will try this.
But i got some problems. I cant get strtok to work. How can i get it to work.
errors and warnings
Quote:

C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(225) : error 035: argument type mismatch (argument 1)//this is the error line
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(225) : warning 213: tag mismatch
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(226) : error 035: argument type mismatch (argument 1)//this is the error line
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(226) : warning 213: tag mismatch
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(227) : error 035: argument type mismatch (argument 1)//this is the error line
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(227) : warning 213: tag mismatch
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(228) : error 035: argument type mismatch (argument 2)//this is the error line
C:\Users\Frederik Vester\Desktop\Samp game fs\try.pwn(224) : warning 203: symbol is never used: "index"

And this is the script.
Код:
CMD:gotopos(playerid, params)
{
	new Float:x[128],Float:y[128],Float:z[128];
	new index;
	x = strtok(params, index);
	y = strtok(params, index);
	z = strtok(params, index);
	SetPlayerPos(playerid, x, y, z);
	return 1;
}

strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}



AW: A little params problem - BiosMarcel - 13.01.2013

Here the Plugin: https://sampforum.blast.hk/showthread.php?tid=120356

Here thats with SSCANF2
PHP код:
CMD:gotopos(playerid,params[])
{
new 
Float:X,Float:Y,Float:Z;
if(
sscanf(params,"fff",X,Y,Z)) return SendClientMessage(playerid,YOURCOLOR,"YOUR ERROR MESSAGE!!!");
{
SetPlayerPos(playerid,X,Y,Z);
}
return 
1;




Re: A little params problem - Threshold - 13.01.2013

Use sscanf instead? :S
strtok doesn't handle Floats, only strings or values other than float values.

add:
pawn Код:
#include <sscanf2>
to the top of your script after downloading the latest sscanf from ******.
Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
Here thats with SSCANF2
CMD:gotopos(playerid,params[])
{
new Float:X,Float:Y,Float:Z;
if(sscanf(params,"fff",X,Y,Z)) return SendClientMessage(playerid,YOURCOLOR,"YOUR ERROR MESSAGE!!!");
{
SetPlayerPos(playerid,X,Y,Z);
}
return 1;
}
Wrong.
pawn Код:
CMD:gotopos(playerid, params[])
{
    new Float:x, Float:y, Float:z;
    if(sscanf(params, "fff", x, y, z)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /gotopos x y z");
    SetPlayerPos(playerid, x, y, z);
    return 1;
}



AW: A little params problem - BiosMarcel - 13.01.2013

MY CODE IS NOT WRONG WHAT ARE YOU TALKING?


Re: A little params problem - Frede - 13.01.2013

No i wanted this, because i dont understand the "fff". sry i but this could pretty nice if it worked.
I have tried with sscanf but now i would try this


AW: A little params problem - BiosMarcel - 13.01.2013

X,Y and Z are Floats.
f is the letter for float.So you have to use f 3 times f(X),f(Y),f(Z),X,Y,Z
.


Re: AW: A little params problem - Threshold - 13.01.2013

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
MY CODE IS NOT WRONG WHAT ARE YOU TALKING?
pawn Код:
if(sscanf(params,"fff",X,Y,Z)) return SendClientMessage(playerid,YOURCOLOR,"YOUR ERROR MESSAGE!!!");
{
SetPlayerPos(playerid,X,Y,Z);
}
You seriously think this would work?


Re: A little params problem - RajatPawar - 13.01.2013

Explanation: (Btw, BIOS, you can turn off your caps.)

pawn Код:
CMD:gotopos(playerid, params[]) //This is how you DECLARE the start of a command in ZCMD.
{
    new Float:x, Float:y, Float:z; //Declaring floats x, y and z here.
    if(sscanf(params, "fff", x, y, z)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /gotopos x y z");
/*Okay. Now, sscanf detects 'parts' of text you input.
Like if you did, sscanf("hello 27","si",string,int) it would return *hello*
*27* It kind of splits it. So since you have not input any thing, if you sscanf it, there's nothing to split.
Hence, if(sscanf(params,"fff",x,y,z)) return error message. Here "fff" means "float float float" --> x, y, z. Meaning first float entered is given value of x and so on. */

    SetPlayerPos(playerid, x, y, z); //Simple.
    return 1;
}
This is how I understood sscanf, I don't know if the original explanation differs.


Re: A little params problem - Frede - 13.01.2013

hmmm... ok, but is there anyway you can get my code to work. I mean with strtok


AW: A little params problem - BiosMarcel - 13.01.2013

Why did you think it doesn't works In my Script it works...