SA-MP Forums Archive
Sending Messages of players within a range - 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: Sending Messages of players within a range (/showthread.php?tid=298487)



Sending Messages of players within a range - nmader - 20.11.2011

Alright, once again, it is right at the very tip of my fingers but I cannot quite figure it out. I am needing help on making RP chats such a /b and /me (etc.) that are not global, but within a certain range for ANY player.

Thanks,
nmader


Re: Sending Messages of players within a range - =WoR=G4M3Ov3r - 20.11.2011

Use ProxDetector

PHP код:
public ProxDetector(Float:radiplayeridstring[],col1,col2,col3,col4,col5)
{  
//Check the comments behind some lines! (scroll to the right)
    
if(IsPlayerConnected(playerid))
    {
        new 
Float:posxFloat:posyFloat:posz;
        new 
Float:oldposxFloat:oldposyFloat:oldposz;
        new 
Float:tempposxFloat:tempposyFloat:tempposz;
        
GetPlayerPos(playeridoldposxoldposyoldposz);
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
            {
                
GetPlayerPos(iposxposyposz);
                
tempposx = (oldposx -posx);
                
tempposy = (oldposy -posy);
                
tempposz = (oldposz -posz);
                if (((
tempposx radi/16) && (tempposx > -radi/16)) && ((tempposy radi/16) && (tempposy > -radi/16)) && ((tempposz radi/16) && (tempposz > -radi/16))) // If the player is within 16 meters
                
{
                    
SendClientMessage(icol1string);
                }
                else if (((
tempposx radi/8) && (tempposx > -radi/8)) && ((tempposy radi/8) && (tempposy > -radi/8)) && ((tempposz radi/8) && (tempposz > -radi/8))) // within 8 meters
                
{
                    
SendClientMessage(icol2string);
                }
                else if (((
tempposx radi/4) && (tempposx > -radi/4)) && ((tempposy radi/4) && (tempposy > -radi/4)) && ((tempposz radi/4) && (tempposz > -radi/4))) //4 meters
                
{
                    
SendClientMessage(icol3string);
                }
                else if (((
tempposx radi/2) && (tempposx > -radi/2)) && ((tempposy radi/2) && (tempposy > -radi/2)) && ((tempposz radi/2) && (tempposz > -radi/2))) //2 meters
                
{
                    
SendClientMessage(icol4string);
                }
                else if (((
tempposx radi) && (tempposx > -radi)) && ((tempposy radi) && (tempposy > -radi)) && ((tempposz radi) && (tempposz > -radi))) //1 meter
                
{
                    
SendClientMessage(icol5string);
                }
            }
            else
            {
                
SendClientMessage(icol1string);
            }
        }
    }
    return 
1;

This is the ProxDetector code.

PHP код:
public OnPlayerText(playeridtext[]) // This callback is called when the players are chatting, we will change this from normal chat to our ProxDetector :)
{
    new 
pname[24], str[128]; // the new for the name and string the player will say
    
GetPlayerName(playeridpname24); // Gets the name so that it displays a name and not an ID
    
format(strsizeof(str), "%s Says: %s"pnametext); // The actual text, formatted into a string
    
ProxDetector(10.0playeridstrCOLOR_FADE1COLOR_FADE2COLOR_FADE3COLOR_FADE4COLOR_FADE5); // Now this is where the fun begins. 10 means the radius, playerid is, well the playerid, str is your string and the colors are the colors you would like to have. You can change it!
    
return 0//IMPORTANT! always use return 0; otherwise it will display both normal chat AND the ProxDetector

This is for player within range 10.0 can see.


Re: Sending Messages of players within a range - Calgon - 21.11.2011

Here's a function I made about a year ago:

pawn Код:
stock nearByMessage(playerid, color, string[], Float: Distance = 12.0) {
    new
        Float: nbCoords[3]; // Variable to store the position of the main player

    GetPlayerPos(playerid, nbCoords[0], nbCoords[1], nbCoords[2]); // Getting the main position

    for(new i = 0; i < MAX_PLAYERS; i++) {
        if(IsPlayerInRangeOfPoint(i, Distance, nbCoords[0], nbCoords[1], nbCoords[2]) && (GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))) { // Confirming if the player being looped is within range and is in the same virtual world and interior as the main player
            SendClientMessage(i, color, string); // Sending them the message if all checks out
        }
    }

    return 1;
}
I've commented the significant parts of the function for you - so you can perhaps understand them better.

This function should be appropriate, the code loops through all players, gets the position of the main player, checks all players to see if they're within distance (of default of 12.0 GTA meters/units) and sends them the message if they are in distance.

You can use this function like this:
pawn Код:
nearByMessage(playerid, COLOR_RED, "I'm not afraid, they can read all about it");
This function is more efficient than the function pasted above, this uses a native algorithm to confirm that the player(s) are in range.


Re: Sending Messages of players within a range - Sinc - 21.11.2011

pawn Код:
stock SendLocalMessage(playerid,color,msg[],Float:radius)
{
    new
        i,
        Float:x,
        Float:y,
        Float:z
    ;
    GetPlayerPos(playerid,x,y,z);
    for(i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInRangeOfPoint(i,radius,x,y,z))
            SendClientMessage(i,color,msg);
    }
    return 1;
}



Re: Sending Messages of players within a range - nmader - 21.11.2011

I received these errors when I tried yours G4MOv3r

Код:
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 012: invalid function call, not a valid address
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 001: expected token: ";", but found ")"
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 029: invalid expression, assumed zero
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.



Re: Sending Messages of players within a range - =WoR=G4M3Ov3r - 21.11.2011

Quote:
Originally Posted by nmader
Посмотреть сообщение
I received these errors when I tried yours G4MOv3r

Код:
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 012: invalid function call, not a valid address
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 001: expected token: ";", but found ")"
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : error 029: invalid expression, assumed zero
C:\Documents and Settings\nmader\Desktop\Folders\WWIII RP\gamemodes\WWIIIRP.pwn(1121) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Which line is that ?


Re: Sending Messages of players within a range - nmader - 21.11.2011

I will simply add the entire command if that is alright.

pawn Код:
if(strcmp(cmdtext, "/sweapons", true) == 0)
    {
    if(IsPlayerInRangeOfPoint(playerid, 6, -343.3916,1542.1134,75.5625))
        {
            new str[128];
            new ProxDetector;
            GetPlayerName(playerid, str, sizeof(str));
            format(str, sizeof(str), "* %s has been seen grabbing weaponry from Soviet's weapon box!", str[4]);
            ProxDetector(10.0, playerid, str, 0x808080FF, 0x808080FF, 0x808080FF, 0x808080FF, 0x808080FF);
            return 0;
            AC_GivePlayerWeapon(playerid, 24, 999999);
            AC_GivePlayerWeapon(playerid, 30, 999999);
            AC_GivePlayerWeapon(playerid, 17, 15);
            AC_GivePlayerWeapon(playerid, 29, 999999);
            AC_GivePlayerWeapon(playerid, 4, 999999);
            AC_GivePlayerWeapon(playerid, 34, 1);
            SendClientMessage(playerid, 0x00FFFFFF, "Your weapons have been refilled successfully!");
            return 1;
        }

        else
        {
            SendClientMessage(playerid, 0xAFAFAFAA, "You must be at Soviet's Weapon Spawn Location to use this command.");
            return 1;
   }
The first line of the script is 1112, the last being 1136

EDIT: I thought I found the error, but I did not, I fixed it, and the errors moved to line 1120, the ProxDetector.