OnPlayertext
#1

Hello all,

i want to make a thing so when you talk in chat that it shows ur ID.
i did this code but dont working

new name[128];
GetPlayerName(playerid, name, sizeof(name));
new string[128];
format(string, sizeof(string), "%s( %s): %s", name, playerid, text);
SendClientMessage(playerid, GetPlayerColor(playerid), text);


I hope someone can help me.
Thanks!
Reply
#2

the '%s' placeholders are for strings only. Use %d in the brackets, to insert an integer (playerid)

For more info check this page on the wiki: https://sampwiki.blast.hk/wiki/Format

Edit: You will also have to return 0 in OnPlayerText, or the normal chattext will be shown too.
Reply
#3

something like this

pawn Код:
public OnPlayerText(playerid, text[])
{
     new name[MAX_PLAYER_NAME];
     new string[128];
     GetPlayerName(playerid, name, sizeof(name));
     format(string, sizeof(string), "%s( %d) says: %s", name, playerid, text);
     new Float:x1,Float:y1,Float:z1
     GetPlayerPos(playerid,x1,y1,z1);
     for(new i = 0; i < MAX_PLAYERS;i++)
     {
          if(IsPlayerConnected(i))
          {
               Float:x2,Float:y2,Float:z2;
               GetPlayerPos(i,x2,y2,z2);
               if(GetPlayerInterior(playerid) == GetPlayerInterior(i))
               {
                     new Float:dist = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
                     if(dist < 20)
                     {
                            SendClientMessage(i,0xAFAFAFAA,string);
                      }
               }
        }
    }
    return 0;
}
Reply
#4

Quote:
Originally Posted by Rachael
Посмотреть сообщение
something like this

pawn Код:
public OnPlayerText(playerid, text[])
{
     new name[MAX_PLAYER_NAME];
     new string[128];
     GetPlayerName(playerid, name, sizeof(name));
     format(string, sizeof(string), "%s( %d) says: %s", name, playerid, text);
     new Float:x1,Float:y1,Float:z1
     GetPlayerPos(playerid,x1,y1,z1);
     for(new i = 0; i < MAX_PLAYERS;i++)
     {
          if(IsPlayerConnected(i))
          {
               Float:x2,Float:y2,Float:z2;
               GetPlayerPos(i,x2,y2,z2);
               if(GetPlayerInterior(playerid) == GetPlayerInterior(i))
               {
                     new Float:dist = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
                     if(dist < 20)
                     {
                            SendClientMessage(i,0xAFAFAFAA,string);
                      }
               }
        }
    }
    return 0;
}
This is not working
but thanks for the help
Reply
#5

Quote:
Originally Posted by Rachael
Посмотреть сообщение
something like this
He's not asking for some roleplay text thing.

This is simple, and should work without any further changes:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new
        str[128];

    format(str, sizeof(str), "(%d): %s", playerid, text);
    SendPlayerMessageToAll(playerid, str);
    return 0;
}
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
He's not asking for some roleplay text thing.

This is simple, and should work without any further changes:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new
        str[128];

    format(str, sizeof(str), "(%d): %s", playerid, text);
    SendPlayerMessageToAll(playerid, str);
    return 0;
}
Thanks Man this is working fine only when i type in Mainchat i get 2 Texts
Reply
#7

Are you sure you completely replaced it? because it must be return 0; and not 1; otherwise it will send it double (one normal one cutsom)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)