A little params problem
#1

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;
}
Reply
#2

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;

Reply
#3

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;
}
Reply
#4

MY CODE IS NOT WRONG WHAT ARE YOU TALKING?
Reply
#5

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
Reply
#6

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
.
Reply
#7

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?
Reply
#8

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.
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)