Outdated "ProxDetector"
#1

I've heard that the "ProxDetector" i think it's called, from the old GF gamemode is pretty outdated, and that's what i use mine after.
So what would be the best way to send a nearby message within a given radius, and then tint it after how close the other player is.

pawn Код:
stock SendNearbyMessage(playerid, Float:radius, string[], col1, col2, col3, col4, col5)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    new Float:ix, Float:iy, Float:iz;
    new Float:cx, Float:cy, Float:cz;
    foreach(Player, i)
    {
        if(IsPlayerLoggedIn(i))
        {
            if(GetPlayerInterior(playerid) == GetPlayerInterior(i) && GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))
            {
                GetPlayerPos(i, ix, iy, iz);
                cx = (x - ix);
                cy = (y - iy);
                cz = (z - iz);
    if(((cx < radius/16) && (cx > -radius/16)) && ((cy < radius/16) && (cy > -radius/16)) && ((cz < radius/16) && (cz > -radius/16)))
                {
                    SendClientMessage(i, col1, string);
                }
                else if(((cx < radius/8) && (cx > -radius/8)) && ((cy < radius/8) && (cy > -radius/8)) && ((cz < radius/8) && (cz > -radius/8)))
                {
                    SendClientMessage(i, col2, string);
                }
                else if(((cx < radius/4) && (cx > -radius/4)) && ((cy < radius/4) && (cy > -radius/4)) && ((cz < radius/4) && (cz > -radius/4)))
                {
                    SendClientMessage(i, col3, string);
                }
                else if(((cx < radius/2) && (cx > -radius/2)) && ((cy < radius/2) && (cy > -radius/2)) && ((cz < radius/2) && (cz > -radius/2)))
                {
                    SendClientMessage(i, col4, string);
                }
                else if(((cx < radius) && (cx > -radius)) && ((cy < radius) && (cy > -radius)) && ((cz < radius) && (cz > -radius)))
                {
                    SendClientMessage(i, col5, string);
                }
            }
        }
    }
    return 1;
}
Currently this is my "stock".
Reply
#2

Isn't it working?
Reply
#3

It's working, but everyone i hear about this says that the ProxDetector sucks, outdated and bad. So im asking what the best way would be to do something like that.
Reply
#4

Ok, maybe you could use the new native GetPlayerDistanceFromPoint function. (The 'point' would be the location of the other player) and use a switch-function instead of a bunch of if-statements.
Reply
#5

Hmm that actually sounds good, but is there maybe a way to tint the color of the text to be darker the higher the distance is, instead of making a lot of cases in the switch, or maybe instead of a switch at all?
Reply
#6

Here's an array that I've generated with 100 colors gradually going from pure red to green.
pawn Код:
new RedToGreen[100] =
{
    0xFF0000FF,0xFC0300FF,0xFA0500FF,0xF70800FF,0xF50A00FF,0xF20D00FF,0xF00F00FF,0xED1200FF,0xEB1400FF,0xE81700FF,
    0xE51900FF,0xE31C00FF,0xE01F00FF,0xDE2100FF,0xDB2400FF,0xD92600FF,0xD62900FF,0xD42B00FF,0xD12E00FF,0xCF3000FF,
    0xCC3300FF,0xC93600FF,0xC73800FF,0xC43B00FF,0xC23D00FF,0xBF4000FF,0xBD4200FF,0xBA4500FF,0xB84700FF,0xB54A00FF,
    0xB24D00FF,0xB04F00FF,0xAD5200FF,0xAB5400FF,0xA85700FF,0xA65900FF,0xA35C00FF,0xA15E00FF,0x9E6100FF,0x9C6300FF,
    0x996600FF,0x966900FF,0x946B00FF,0x916E00FF,0x8F7000FF,0x8C7300FF,0x8A7500FF,0x877800FF,0x857A00FF,0x827D00FF,
    0x7F8000FF,0x7D8200FF,0x7A8500FF,0x788700FF,0x758A00FF,0x738C00FF,0x708F00FF,0x6E9100FF,0x6B9400FF,0x699600FF,
    0x669900FF,0x639C00FF,0x619E00FF,0x5EA100FF,0x5CA300FF,0x59A600FF,0x57A800FF,0x54AB00FF,0x52AD00FF,0x4FB000FF,
    0x4CB300FF,0x4AB500FF,0x47B800FF,0x45BA00FF,0x42BD00FF,0x40BF00FF,0x3DC200FF,0x3BC400FF,0x38C700FF,0x36C900FF,
    0x33CC00FF,0x30CF00FF,0x2ED100FF,0x2BD400FF,0x29D600FF,0x26D900FF,0x24DB00FF,0x21DE00FF,0x1FE000FF,0x1CE300FF,
    0x19E600FF,0x17E800FF,0x14EB00FF,0x12ED00FF,0x0FF000FF,0x0DF200FF,0x0AF500FF,0x08F700FF,0x05FA00FF,0x03FC00FF
};
You could decide the max distance a player can read the message. (for example 50 units). Then calculate the percentage of the players distance against the max distance and let the script pick the right color.
You might wanna reverse the order of the array to have the nearest players receive green messages and the furthest away players get red-messages.

pawn Код:
forward Float:GetPercentage(Float:current, Float:max);
Float:GetPercentage(Float:current, Float:max)
{
    new Float:percentage;
    percentage = floatdiv(current, max)*100;
    return percentage;
}

pawn Код:
//Your sendnearbymessage-stock:
foreach(Player, i)
{
    if(IsPlayerLoggedIn(i))
    {
        if(GetPlayerInterior(playerid) == GetPlayerInterior(i) && GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))
        {
            GetPlayerPos(i, ix, iy, iz);
            new Float:Distance = GetPlayerDistanceFromPoint(playerid, ix, iy, iz);
            new Float:Percentage = GetPercentage(Distance, 50.0);
            SendClientMessage(i, RedToGreen[floatround(Percentage)], string);
        }
    }
}
Reply
#7

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Ok, maybe you could use the new native GetPlayerDistanceFromPoint function. (The 'point' would be the location of the other player) and use a switch-function instead of a bunch of if-statements.
I was writing an argument on using IsPlayerInRangeOfPoint, but now that I've come to think of it, you may actually want to use their exact distance to just calculate the amount of gray you need, rather than going through a bunch of if statements.

There are 255 shades of gray (ha. ha.). If we establish that the maximum distance someone can be heard is 50 meters then we need to subtract 5 from 255 for every meter (255 / 50 ~= 5). Thus:

pawn Код:
new multiplier = floatround(GetPlayerDistanceFromPoint(playerid, x, y, z));
new color = 0xFFFFFFFF - (0x05050500 * multiplier);
Reply
#8

While your new functions seem better at coloring, and more optimised, it seems to disable the custom choice of distance and color for each different message.
pawn Код:
SendNearbyMessage(playerid, 10, string, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW);
As with this, it sends the message at a distance of 10, and yellow color.
pawn Код:
SendNearbyMessage(playerid, 20, string, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
But still with the abilty to make another one that's etc. sent at a distance of 20, and uses the fade options. Or well, other colors.

Doesn't seem like you can keep these custom abilities with your suggestions though.
Reply
#9

Personally, I find ProxDetector fine and it works like a bomb. However if you're looking for another way I guess you'd just loop through all the players and check whether they're IsPlayerInRangeOfPoint, if they are send them the message.
Reply
#10

I've just heard people say it's shit, so i'm just wondering if that's because there's a way better feature that i completely missed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)