Hey all,
I'm new to the whole pawn scripting and I try to make a command that gives me my position.
But, when I use the command it doesn't send anything in the chat.
Code: if (strcmp("/getpos", cmdtext, true, 7) == 0)
{
// Do something here
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SendClientMessage(playerid, -1,"Position: %f, %f, %f.", x, y, z);
return 1;
}
return 0;
I've also tried to remove the %f, %f, %f part but then it only sends me "Position:" without the actual player position.
Also when I compile/run my script, it gives me 3 warnings(warning 202: number of arguments does not match definition)
Any help would be appreciated.
Location: Belgrade, Serbia
2020-12-19, 06:16 PM
(This post was last modified: 2020-12-19, 06:16 PM by Pinch.)
You can't pass arguments to most of the native functions (naturally including SendClientMessage)
You need to use format before, like this:
Code: if (strcmp("/getpos", cmdtext, true, 7) == 0)
{
// Do something here
// 64 is the size of the string
new buffer[64], Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
format(buffer, sizeof(buffer), "Position: %f, %f, %f.", x, y, z);
SendClientMessage(playerid, -1, buffer);
return 1;
}
return 0;
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
Location: La Plata, Argentina
There is also an extended version of SendClientMessage which does receive parameters.
Code: stock SendClientMessageEx(playerid, color, const str[], {Float,_}:...)
{
static args, start, end,string[200];
#emit LOAD.S.pri 8
#emit STOR.pri args
if (args > 12)
{
#emit ADDR.pri str
#emit STOR.pri start
for (end = start (args - 12); end > start; end -= 4)
{
#emit LREF.pri end
#emit PUSH.pri
}
#emit PUSH.S str
#emit PUSH.C 156
#emit PUSH.C string
#emit PUSH.C args
#emit SYSREQ.C format
SendClientMessage(playerid, color, string);
#emit LCTRL 5
#emit SCTRL 4
#emit RETN
}
return SendClientMessage(playerid, color, str);
}
Location: Belgrade, Serbia
(2020-12-19, 06:23 PM)Markski Wrote: There is also an extended version of SendClientMessage which does receive parameters.
Code: stock SendClientMessageEx(playerid, color, const str[], {Float,_}:...)
{
static args, start, end,string[200];
#emit LOAD.S.pri 8
#emit STOR.pri args
if (args > 12)
{
#emit ADDR.pri str
#emit STOR.pri start
for (end = start (args - 12); end > start; end -= 4)
{
#emit LREF.pri end
#emit PUSH.pri
}
#emit PUSH.S str
#emit PUSH.C 156
#emit PUSH.C string
#emit PUSH.C args
#emit SYSREQ.C format
SendClientMessage(playerid, color, string);
#emit LCTRL 5
#emit SCTRL 4
#emit RETN
}
return SendClientMessage(playerid, color, str);
}
That's a terrible one at that, they should use va_SendClientMessage
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
Location: La Plata, Argentina
(2020-12-19, 06:59 PM)Pinch Wrote: That's a terrible one at that, they should use va_SendClientMessage
Why is that?
|