Begginner problem with SendClientMessage
#1

Hello coders.

I am new to pawno as I have been working on c++ console projects so far. I wanted to create a command that would tell the user his location coordinates. Although when I type the command, it does not really work. I have been searching all over ****** to find some tutorial on variables in sendclientmessage but I couldn't find anything. So, please try and help me real quick. Thank you in advance.

Код:
if (strcmp("/location", cmdtext, true, 10) == 0)
	{
		new float: x,y,z;
		GetPlayerPos(playerid, x,y,z);
		new string[50]="%f,%f,%f";
		SendClientMessage(playerid, COLOR_RED, string);
		return 1;
	}
Reply
#2

new string[64];
new Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
format(string, sizeof(string), "%f, %f, %f", f, y, z);
SendClientMessage(playerid, COLOR_RED, string);
Reply
#3

You need first to format the string before you use it !

pawn Код:
if (strcmp("/location", cmdtext, true, 10) == 0)
    {
        new Float:x,Float:y,Float:z;
        GetPlayerPos(playerid, x,y,z);
        new string[50];
        format(string,sizeof(string),"%f,%f,%f",x,y,z);
        SendClientMessage(playerid, COLOR_RED, string);
        return 1;
    }
Reply
#4

thank you guys very much. I quite dont understand everything about the format but I guess ill use the wiki for that. Thanks again. works like charm
Reply
#5

First of all, the language is PAWN, the "pawno" is the compiler.

Also, the lenght is optional and it is not needed to use it. For example in the "/location" the lenght is 9, not 10.
You can read a lot of stuff on the Wiki Samp and read about Format and Floats
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/location", true))
    {
        new
            Float:Pos[3],
            string[41]
        ;
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
        format(string, sizeof(string), "X: %.4f, Y: %.4f, Z: %.4f", Pos[0], Pos[1], Pos[2]);
        SendClientMessage(playerid, COLOR_RED, string);
        return 1;
    }
    // Rest of commands
    return 0;

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)