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;
}
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
};
forward Float:GetPercentage(Float:current, Float:max);
Float:GetPercentage(Float:current, Float:max)
{
new Float:percentage;
percentage = floatdiv(current, max)*100;
return percentage;
}
//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);
}
}
}
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.
|
new multiplier = floatround(GetPlayerDistanceFromPoint(playerid, x, y, z));
new color = 0xFFFFFFFF - (0x05050500 * multiplier);
SendNearbyMessage(playerid, 10, string, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW, COLOR_YELLOW);
SendNearbyMessage(playerid, 20, string, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);