SA-MP Forums Archive
Local Chat - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Local Chat (/showthread.php?tid=59184)



Local Chat - Soeren - 24.12.2008

Hey!

I'm using LimitGlobalChatRadius(125) on my server, so automatically when you write it only sends to the people around you.
Now I want to send the Message "Nobody around you recieved the message." if noone received the message. Now i have the weird bug, that the message also comes if 1 Person heard you, but as soon as 2 people hear it, it is all ok and the Message does not appear.

Anyone can help me please? Here is the code I'm using:

pawn Код:
LimitGlobalChatRadius(125);
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        if(GetDistanceBetweenPlayers(playerid, i) > 125)
        {
           SendClientMessage(playerid,COLOUR_WHITE , "( ! ) (INFO) Nobody around you recieved the message.");
        }
    }



Re: Local Chat - Soeren - 25.12.2008

Omg, noone? Please help me >.<


Re: Local Chat - LarzI - 25.12.2008

Use MAX_PLAYERS and replace the number of MAX_PLAYERS inside a_samp.inc with your max amount of players...
Shouldn't fix the problem, but it's better that way...


Re: Local Chat - x-cutter - 25.12.2008

Here, I'll show you my /l (local chat) command and I hope it helps you out.

Код:
		if(strcmp(cmd,"/l",true)==0 || strcmp(cmd,"/b",true)==0)
		{
		  new tmp[256];
		  new playername[24];
		  new string[150];
		  tmp=strtokmsg(cmdtext,idx);
		  if(!strlen(tmp))
		  {
		    SendClientMessage(playerid,White,"USAGE : /l [text]");
		    return 1;
		  }
		  for(new i = 0; i < MAX_PLAYERS; i++)
		  {
				GetPlayerName(playerid,playername,sizeof(playername));
				format(string,sizeof(string),"Local Chat~ %s : %s",playername,tmp);
				if(GetDistanceBetweenPlayers(playerid,i)<125)
				{
				  SendClientMessage(i,White,string);
				}
		  }
		  return 1;
		}



Re: Local Chat - Soeren - 25.12.2008

Thanks for the replies. Well, not quite the thing I was searching for though... But I will try to replace 'GetMaxPlayers' with 'MAX_PLAYERS'... although I think it won't make such a big difference?

Maybe someone else knows the best solution for it...


Re: Local Chat - Ycto - 25.12.2008

Hai!

I really don't know if this will work, but, you can try it :P
Replace this:
pawn Код:
for(new i = 0; i < GetMaxPlayers(); i++)
With this:
pawn Код:
for(new i = 0; i <= GetMaxPlayers(); i++)
I don't know if it will work, just guessing =)
Merry X-Mas and good luck!


Re: Local Chat - Soeren - 25.12.2008

Quote:
Originally Posted by [SAP
Ycto ]
pawn Код:
for(new i = 0; i <= GetMaxPlayers(); i++)
Merry X-Mas and good luck!
I will give it a try... Merry christmas to you too


Re: Local Chat - dax123 - 25.12.2008

Quote:
Originally Posted by [SAP
Ycto ]
Hai!

I really don't know if this will work, but, you can try it :P
Replace this:
pawn Код:
for(new i = 0; i < GetMaxPlayers(); i++)
With this:
pawn Код:
for(new i = 0; i <= GetMaxPlayers(); i++)
I don't know if it will work, just guessing =)
Merry X-Mas and good luck!
pawn Код:
for(new i = 0; i <= GetMaxPlayers(); i++)
obviously it doesn't work.
and also it's irrelevant with the problem.

even if you use this :
pawn Код:
for(new i = 0, j = GetMaxPlayers(); i < j; i++)
it's slower than:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
but if you limit max players lower than 200 in this case you should use the first method.
(i think so cause it will call useless IPC function)

you could try this.
but you should confirm before using this that GetDistanceBetweenPlayers is checking IPC(IsPlayerConnected).
pawn Код:
LimitGlobalChatRadius(125);
new i;
for(new i = 0, j = GetMaxPlayers(); i < j; i++)
{
    if( GetDistanceBetweenPlayers(playerid, i) <= 125 ) break;
}
if( i == MAX_PLAYERS ) SendClientMessage(playerid,COLOUR_WHITE , "( ! ) (INFO) Nobody around you recieved the message.");
if it works enjoy it



Re: Local Chat - Soeren - 25.12.2008

Yes, the IPC is checked by GetDistanceBetweenPlayers.

If I compile your idea, it gives me "warning 219: local variable "i" shadows a variable at a preceding level"


Re: Local Chat - Serbish - 25.12.2008

Quote:
Originally Posted by Soeren
Yes, the IPC is checked by GetDistanceBetweenPlayers.

If I compile your idea, it gives me "warning 219: local variable "i" shadows a variable at a preceding level"
That means you have to delete the variable "i" in that line.