SA-MP Forums Archive
Begginner problem with SendClientMessage - 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: Begginner problem with SendClientMessage (/showthread.php?tid=391042)



Begginner problem with SendClientMessage - Sam5513 - 09.11.2012

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;
	}



Re: Begginner problem with SendClientMessage - mSlat3r - 09.11.2012

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);


Re: Begginner problem with SendClientMessage - doreto - 09.11.2012

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;
    }



Re: Begginner problem with SendClientMessage - Sam5513 - 09.11.2012

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


Re: Begginner problem with SendClientMessage - Konstantinos - 09.11.2012

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;

}