Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] GetPlayerPos and show in chat?

 
  • 0 Vote(s) - 0 Average
Pawn GetPlayerPos and show in chat?
LagunaPreza
Offline

Burgershot Member
Posts: 1
Threads: 1
Joined: Dec 2020
Reputation: 0
Location: Netherlands
#1
2020-12-19, 05:48 PM
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.
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#2
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.
Markski
Offline

Burgershot Clerk

Posts: 127
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: La Plata, Argentina
#3
2020-12-19, 06:23 PM
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);
}
Website
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#4
2020-12-19, 06:59 PM
(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.
Markski
Offline

Burgershot Clerk

Posts: 127
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: La Plata, Argentina
#5
2020-12-19, 07:27 PM
(2020-12-19, 06:59 PM)Pinch Wrote: That's a terrible one at that, they should use va_SendClientMessage

Why is that?
Website
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode