SA-MP Forums Archive
Say command - 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: Say command (/showthread.php?tid=612384)



Say command - Tass007 - 17.07.2016

The command itself is really explanatory. Here is my code.
PHP код:
[CMD:say(playerid,params[])// /say command
{
     new 
string[128], say[100];// Store the intial action
    
new Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
     if(
sscanf(params"s[100]",say)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /s [Action]");//Error handling
    
for (new 0MAX_PLAYERSi++)
    {
          if (
IsPlayerInRangeOfPoint(i25.0xyz))
          {
             
format(string,sizeof(string),"*%s says\58 \34%s\34",GetName(playerid),say);//Formats the /shout cmd output
             
SendClientMessage(i,COLOR_LIGHTBLUE,string);
        }
          else 
SendClientMessage(playeridCOLOR_SILVER"You spoke but nobody heard you...");
          }
     return 
1;

There are no errors or warnings. However when I type /say I get spammed with "You spoke but nobody heard you..." Any ideas?

Thanks for your time.


Re: Say command - oMa37 - 17.07.2016

-DELETE-


Re: Say command - TaiRinsuru - 17.07.2016

pawn Код:
[CMD:say(playerid,params[])// /say command
{
     new string[128], say[100];// Store the intial action
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
     if(sscanf(params, "s[100]",say)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /s [Action]");//Error handling
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
          if (IsPlayerInRangeOfPoint(i, 25.0, x, y, z))
          {
             format(string,sizeof(string),"*%s says\58 \34%s\34",GetName(playerid),say);//Formats the /shout cmd output
             SendClientMessage(i,COLOR_LIGHTBLUE,string);
        }
          else SendClientMessage(playerid, COLOR_SILVER, "You spoke but nobody heard you...");
          break;
          }
     return 1;
}



Re: Say command - Stinged - 17.07.2016

Код:
CMD:say(playerid, params[])
{
    if (isnull(params))
        return SendClientMessage(playerid,COLOR_WHITE,"Usage: /s [Action]");
        
    new
        Float: x, Float: y, Float: z,
        string[145], count;
        
    GetPlayerPos(playerid, x, y, z);
    GetPlayerName(playerid, string, 24);
    format(string, sizeof(string), "*%s says\58 \34%s\34", string, params);
    
    for (new i, j = GetPlayerPoolSize(); i <= j; i++) // for (new i; i < MAX_PLAYERS; i++) if you don't use 0.3.7
    {
        if (!IsPlayerConnected(i))
            continue;
        if (IsPlayerInRangeOfPoint(i, 25.0, x, y, z))
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, string);
            count++;
        }
    }
    if (!count)
        SendClientMessage(playerid, COLOR_SILVER, "You spoke but nobody heard you...");
    return 1;
}
You have to count how many players got the message, and then check if no one did after the loop.
You should format once, outside the loop. No need to format every time the loop runs, because the message is not changing.

Also, no need for sscanf when you're only using a string, because 'params[]' is already a string.


Re: Say command - Tass007 - 18.07.2016

Hi. Thanks to you both for taking the time to help me out. I don't get spammed anymore, however even if no one is close to me it will display the message that has been sent and no "You spoke but nobody heard..."

Any more ideas?


Re: Say command - Stinged - 18.07.2016

Quote:
Originally Posted by Tass007
Посмотреть сообщение
Hi. Thanks to you both for taking the time to help me out. I don't get spammed anymore, however even if no one is close to me it will display the message that has been sent and no "You spoke but nobody heard..."

Any more ideas?
Add this right above "if (IsPlayerConnected(i))"

Код:
if (i == playerid)
    continue;



Re: Say command - Tass007 - 18.07.2016

Awesome that worked. Thanks so much!


Re: Say command - Tass007 - 20.07.2016

After I tested the command a little bit more, I found that when typing /say Hi. It would display to the other person but it wouldn't display to the player whom wrote it. So I added this
PHP код:
CMD:say(playeridparams[])
{
    if (
isnull(params)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /s [Action]");
    new 
FloatxFloatyFloatzstring[145], count;
    
GetPlayerPos(playeridxyz);
    
GetPlayerName(playeridstring24);
    
format(stringsizeof(string), "*%s says\58 \34%s\34"stringparams);
    for (new 
iGetPlayerPoolSize(); <= ji++) // for (new i; i < MAX_PLAYERS; i++) if you don't use 0.3.7
    
{
        if (
== playerid)    continue;
        if (!
IsPlayerConnected(i))
            continue;
        if (
IsPlayerInRangeOfPoint(i25.0xyz))
        {
            
SendClientMessage(iCOLOR_LIGHTBLUEstring);
            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
            
count++;
        }
    }
    if (!
countSendClientMessage(playeridCOLOR_SILVER"You spoke but nobody heard you...");
    return 
1;

But when I am around more than 1 person, it displays whatever has been said twice.


Re: Say command - Sew_Sumi - 20.07.2016

PHP код:
if (== playerid)    continue; 
That is what's stopping you from having it displayed for the person who said it.

Your change, will spam the player who says it if he's around more than one player.

If there are 3 around the player, you'll end up with it being shown 3 times.

If you are just with 1, you will see it once and it will look "normal".

The other players won't see the issue, until they try to chat.


Re: Say command - Tass007 - 20.07.2016

Right. So how can I fix it? How can I make it to that if 1 person is around it displays what themselves has written, but around more than 1 person it'll display only one message?