SA-MP Forums Archive
Displaying position? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Displaying position? (/showthread.php?tid=107917)



Displaying position? - jameskmonger - 11.11.2009

Код:
	if (strcmp("/mypos", cmdtext, true, 10) == 0)
	{
  		new Float:x, Float:y, Float:z;
 		GetPlayerPos(playerid, x, y, z);
 		SendClientMessage(playerid, COLOR_REDTRANS, "Displaying position... Loaded...");
		format(string, sizeof(string), "Your position: %s, %s, %s.", x, y, z);
		return 1;
	}
That's my code, but I get this:
Quote:

C:\Users\James\Desktop\SAMP Server\gamemodes\ReelWurld.pwn(124) : error 017: undefined symbol "string"
C:\Users\James\Desktop\SAMP Server\gamemodes\ReelWurld.pwn(124) : error 017: undefined symbol "string"
C:\Users\James\Desktop\SAMP Server\gamemodes\ReelWurld.pwn(124) : error 029: invalid expression, assumed zero
C:\Users\James\Desktop\SAMP Server\gamemodes\ReelWurld.pwn(124) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.




Re: Displaying position? - CAR - 11.11.2009

pawn Код:
if (strcmp("/mypos", cmdtext, true, 10) == 0)
{
    new Float:x, Float:y, Float:z, string[128];
    GetPlayerPos(playerid, x, y, z);
    SendClientMessage(playerid, COLOR_REDTRANS, "Displaying position... Loaded...");
    format(string, sizeof(string), "Your position: %f, %f, %f.", x, y, z);
    SendClientMessage(playerid, COLOR_REDTRANS, string);
    return 1;
}
Edit tabs..


Re: Displaying position? - smoker08 - 11.11.2009

Maybe you should make it like this:

Код:
//under
OnPlayerCommandText(playerid, cmdtext[])

  new string[256];

//then your code here
	if (strcmp("/mypos", cmdtext, true, 6) == 0) //should be 6 not 10
	{
  		new Float:x, Float:y, Float:z;
 		GetPlayerPos(playerid, x, y, z);
 		SendClientMessage(playerid, COLOR_REDTRANS, "Displaying position... Loaded...");
		format(string, sizeof(string), "Your position: %s, %s, %s.", x, y, z);
        SendClientMessage(playerid,COLOR_REDTRANS,string);
		return 1;
	}
And then do whatever you have to do...Cheers

AF1


Re: Displaying position? - radhakr - 11.11.2009

Quote:
Originally Posted by AF1-4-LIFE
Maybe you should make it like this:

Код:
//under
OnPlayerCommandText(playerid, cmdtext[])

  new string[256];

//then your code here
	if (strcmp("/mypos", cmdtext, true, 6) == 0) //should be 6 not 10
	{
  		new Float:x, Float:y, Float:z;
 		GetPlayerPos(playerid, x, y, z);
 		SendClientMessage(playerid, COLOR_REDTRANS, "Displaying position... Loaded...");
		format(string, sizeof(string), "Your position: %s, %s, %s.", x, y, z);
        SendClientMessage(playerid,COLOR_REDTRANS,string);
		return 1;
	}
And then do whatever you have to do...Cheers

AF1
No, use the one CAR made, although personally I would make it (strcmp("/mypos", cmdtext, true) == 0). Actually I wouldn't use strcmp, but whatever.


Re: Displaying position? - smoker08 - 11.11.2009

Yea i usually use it like this strcmp("/ ", cmdtext, true) == 0) and yea CAR's is prob better and shorter but defining the string from under OnPlayerCommandText is easier than every time adding a new command you gotta define the string. But anyways whichever is better should work, haven't tested anything, just helping out...

Cheers,
AF1


Re: Displaying position? - Brendan_Thomson - 11.11.2009

Define string with a size of 128, NOT 256.


Re: Displaying position? - radhakr - 11.11.2009

Quote:
Originally Posted by Brendan_Thomson
Define string with a size of 128, NOT 256.
Exactly. I'd also use zcmd.


Re: Displaying position? - (.Aztec); - 11.11.2009

Quote:
Originally Posted by radhakr
Quote:
Originally Posted by Brendan_Thomson
Define string with a size of 128, NOT 256.
Exactly. I'd also use zcmd.
Seconded, using ZCMD:

pawn Код:
cmd(mypos, playerid, params[])
{
new string[128], Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
format(string, sizeof(string), "* You are at: %f, %f, %f.");
SendClientMessage(playerid, COLOR, string);
return 1;
}



Re: Displaying position? - Daren_Jacobson - 11.11.2009

Quote:
Originally Posted by Brendan_Thomson
Define string with a size of 128, NOT 256.
would you mind explaining that? because i see no reason why you could not define it to be 62 big, and that has margin for error.


Re: Displaying position? - (.Aztec); - 11.11.2009

Quote:
Originally Posted by Daren_Jacobson
Quote:
Originally Posted by Brendan_Thomson
Define string with a size of 128, NOT 256.
would you mind explaining that? because i see no reason why you could not define it to be 62 big, and that has margin for error.
256 is too big, 128 is all that is needed.