SA-MP Forums Archive
Local chat distance script - 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 distance script (/showthread.php?tid=65327)



Local chat distance script - Robin_J - 11.02.2009

Ok so im making a small local chat, i think ive nailed it, apart from i have no idea where to put or how to make a distance thing, so that only people within a certain range can see it


Код:
if(strcmp(cmdtext,"/b",true)==0)
{
 new tmp[256];
 new string[256];
 new pName[MAX_PLAYER_NAME];/
 new idx;/
 tmp = strtok(cmdtext,idx);
 if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE:/b [Local OOC Message]");
 if(IsPlayerConnected(playerid))
 {
   GetPlayerName(playerid,pName,sizeof(pName));
   format(string,sizeof(string),"%s Says: (( %s )) !!",pName,cmdtext[5]);
   SendClientMessageToAll(COLOR_WHITE,string)
ProxDetector(50.0, playerid, string,COLOR1);
 }
 return 1;
}
Thats whati have, No distance though (i think) so its jsut going out to the server



Re: Local chat distance script - MenaceX^ - 11.02.2009

ProxDetector?


Re: Local chat distance script - Robin_J - 11.02.2009

Quote:
Originally Posted by MenaceX^
Add the PlayerToPoint function.
Did i mention im spanking new to Pawno system, So what you said means nothing, And before anyone says anything, yes i have read the Wiki Sa-Mp help, Brief example of it? if you wouldnt mind


Re: Local chat distance script - MenaceX^ - 11.02.2009

It can be done with PlayerToPoint aswell but to complicated.
Add those.
pawn Код:
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);

new BigEar[MAX_PLAYERS];
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        //radi = 2.0; //Trigger Radius
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(!BigEar[i])
                {
                    GetPlayerPos(i, posx, posy, posz);
                    tempposx = (oldposx -posx);
                    tempposy = (oldposy -posy);
                    tempposz = (oldposz -posz);
                    //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
                    if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
                    {
                        SendClientMessage(i, col1, string);
                    }
                    else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
                    {
                        SendClientMessage(i, col2, string);
                    }
                    else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
                    {
                        SendClientMessage(i, col3, string);
                    }
                    else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
                    {
                        SendClientMessage(i, col4, string);
                    }
                    else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
                    {
                        SendClientMessage(i, col5, string);
                    }
                }
                else
                {
                    SendClientMessage(i, col1, string);
                }
            }
        }
    }//not connected
    return true;
}
pawn Код:
//Command with distance
Add this
ProxDetector(50.0, playerid, string,COLOR1); // 50 =distance.



Re: Local chat distance script - Robin_J - 11.02.2009

So do i use just the proxdetector one, Or both? where do i add them into my script anyway?

Thanks for you help BTW


Re: Local chat distance script - MenaceX^ - 11.02.2009

Somewhere in your script. to the cmd you do like
format(string,sizeof(string),"Hey %s.",PlayerName(playerid));
ProxDetector(50.0, playerid, string,COLOR); // 50 =distance.


Re: Local chat distance script - Robin_J - 11.02.2009

Ok done, I think that will work, Cheers for your help


Re: Local chat distance script - Robin_J - 11.02.2009

Hmmm, I just compiled it seems i get this now

(13) : error 010: invalid function or declaration
(5) : error 017: undefined symbol "MAX_PLAYER_NAME"
(5) : error 010: invalid function or declaration
(6) : error 010: invalid function or declaration
( : error 010: invalid function or declaration
(9) : error 010: invalid function or declaration
(11) : error 010: invalid function or declaration
(11) : error 010: invalid function or declaration
(11 -- 12) : error 010: invalid function or declaration
(11 -- 12) : fatal error 107: too many error messages on one line


Re: Local chat distance script - Static_X - 12.02.2009

YA use this :
first start with forwards ;
Код:
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
then define strtok:
Код:
strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}
	
	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
Lets define ProxDetector if you havent done so:
Код:
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
	new Float:posx, Float:posy, Float:posz;
	new Float:oldposx, Float:oldposy, Float:oldposz;
	new Float:tempposx, Float:tempposy, Float:tempposz;
	GetPlayerPos(playerid, oldposx, oldposy, oldposz);
	//radi = 2.0; //Trigger Radius
	for(new i = 0; i <= MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i) == 1)
		{
			{
				GetPlayerPos(i, posx, posy, posz);
				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)))
				{
					SendClientMessage(i, col1, string);
				}
				else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
				{
					SendClientMessage(i, col2, string);
				}
				else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
				{
					SendClientMessage(i, col3, string);
				}
				else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
				{
					SendClientMessage(i, col4, string);
				}
				else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
				{
					SendClientMessage(i, col5, string);
				}
			}
		}
	}
	return 1;
}
Before my code add this somwhere just below OnPlayerCommandText:
Код:
new sendername[MAX_PLAYER_NAME];
new idx;
This is pretty much i use :
pawn Код:
if(strcmp(cmd, "/local", true) == 0 || strcmp(cmd, "/l", true) == 0 || strcmp(cmd, "/say", true) == 0)
    {
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/l)ocal [local chat]");
            return 1;
        }
        format(string, sizeof(string), "%s Says %s", sendername, result);
        ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
        printf("%s", string);
        return 1;
    }
Now you would get some eror's ... here are color defines:
pawn Код:
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
PS: Change command' and ProxDetector Distance to your needs..


Re: Local chat distance script - Robin_J - 12.02.2009

That seems complicated, Ive tried, Im sure ive done it wrong............