SA-MP Forums Archive
RolePlay help - 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: RolePlay help (/showthread.php?tid=328865)



RolePlay help - RicaNiel - 26.03.2012

Guys i am wondering
if anyone could teach me how to make
a system like this

Real-Chat

like when player chats
the only one who can see the chat is the player near at the player
like real chat

and then also when they shout the player can hear it far but not in the entire global chat


Re: RolePlay help - antonio112 - 26.03.2012

You have to get the player who's talking position then loop through all online players, see if they are in range of X to player. If they are in X range, they can see the text. It ain't that hard.


Re: RolePlay help - RicaNiel - 26.03.2012

oh thanks but
mind if i ask for some startup codes?
i am to confused


Re : RolePlay help - Vukilore - 26.03.2012

Use the function "NearByMessageForPlayer" or "ProxDetector". Check on ****** to find it


Re: RolePlay help - dannyk0ed - 26.03.2012

Here is a Example of ProxDetector

pawn Код:
forward ProxDetector(Float:radi, playerid, string[],col1);///----Put this by all your forwards
pawn Код:
public ProxDetector(Float:radi, playerid, string[],col1)
{
    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);
       
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
            {
                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
            {
                SendClientMessage(i, col1, string);
            }
        }
    }
    return 1;
}



Re: RolePlay help - RicaNiel - 26.03.2012

wait but sending the message? how?


Re: RolePlay help - dannyk0ed - 26.03.2012

Like /local? Only local can hear it?


Re: RolePlay help - antonio112 - 26.03.2012

I'd suggest using the new function, IsPlayerInRangeOfPoint in the ProxDetector:
pawn Код:
stock ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    GetPlayerPos(playerid, oldposx, oldposy, oldposz);
    foreach (Player,i) // This loops through all players
    {
        if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid) && GetPlayerInterior(i) == GetPlayerInterior(playerid)) // This checks if the virtual world and interior are the same with the playerid
        {
            if(IsPlayerInRangeOfPoint(i, radi/16,oldposx, oldposy, oldposz)) SendClientMessage(i, col1, string);
            else if(IsPlayerInRangeOfPoint(i, radi/8,oldposx, oldposy, oldposz)) SendClientMessage(i, col2, string);
            else if(IsPlayerInRangeOfPoint(i, radi/4,oldposx, oldposy, oldposz)) SendClientMessage(i, col3, string);
            else if(IsPlayerInRangeOfPoint(i, radi/2,oldposx, oldposy, oldposz)) SendClientMessage(i, col4, string);
            else if(IsPlayerInRangeOfPoint(i, radi,oldposx, oldposy, oldposz)) SendClientMessage(i, col5, string);
        }
    }
    return 1;
}
And to send the local message, use OnPlayerText:
pawn Код:
public OnPlayerText(playerid, text[])
{
    new String[128];
    format(String, sizeof String, "%s says: %s", pName(playerid), text);
    ProxDetector(7.0, playerid, String, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
    return 0;
}
Something like this. Now, when a player texts anything, only the players in range of 7.0 to the player can 'see' it.

COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, etc are the colors used, as the target keeps getting away from the player.

So, if other players are next to the one that texts, they'll see the text in WHITE and as they go far away, the color'll slowly "turn" into grey, like they would 'hear' it a bit lower.

Of course, you can use the same color five times. For instance, in the /me command. You'll use the me color in every 5 'color' parameters. Something like:

pawn Код:
ProxDetector(7.0, playerid, String, 0xF9B7FFAA, 0xF9B7FFAA, 0xF9B7FFAA,  0xF9B7FFAA, 0xF9B7FFAA);
Where '0xF9B7FFAA' = the color of /me


Re: RolePlay help - dannyk0ed - 26.03.2012

i dont see a difference between (10.0) and (7.0)


Re: RolePlay help - RicaNiel - 08.04.2012

Quote:
Originally Posted by antonio112
Посмотреть сообщение
I'd suggest using the new function, IsPlayerInRangeOfPoint in the ProxDetector:
pawn Код:
stock ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    GetPlayerPos(playerid, oldposx, oldposy, oldposz);
    foreach (Player,i) // This loops through all players
    {
        if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid) && GetPlayerInterior(i) == GetPlayerInterior(playerid)) // This checks if the virtual world and interior are the same with the playerid
        {
            if(IsPlayerInRangeOfPoint(i, radi/16,oldposx, oldposy, oldposz)) SendClientMessage(i, col1, string);
            else if(IsPlayerInRangeOfPoint(i, radi/8,oldposx, oldposy, oldposz)) SendClientMessage(i, col2, string);
            else if(IsPlayerInRangeOfPoint(i, radi/4,oldposx, oldposy, oldposz)) SendClientMessage(i, col3, string);
            else if(IsPlayerInRangeOfPoint(i, radi/2,oldposx, oldposy, oldposz)) SendClientMessage(i, col4, string);
            else if(IsPlayerInRangeOfPoint(i, radi,oldposx, oldposy, oldposz)) SendClientMessage(i, col5, string);
        }
    }
    return 1;
}
And to send the local message, use OnPlayerText:
pawn Код:
public OnPlayerText(playerid, text[])
{
    new String[128];
    format(String, sizeof String, "%s says: %s", pName(playerid), text);
    ProxDetector(7.0, playerid, String, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
    return 0;
}
Something like this. Now, when a player texts anything, only the players in range of 7.0 to the player can 'see' it.

COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, etc are the colors used, as the target keeps getting away from the player.

So, if other players are next to the one that texts, they'll see the text in WHITE and as they go far away, the color'll slowly "turn" into grey, like they would 'hear' it a bit lower.

Of course, you can use the same color five times. For instance, in the /me command. You'll use the me color in every 5 'color' parameters. Something like:

pawn Код:
ProxDetector(7.0, playerid, String, 0xF9B7FFAA, 0xF9B7FFAA, 0xF9B7FFAA,  0xF9B7FFAA, 0xF9B7FFAA);
Where '0xF9B7FFAA' = the color of /me
why did it return to 0?