ProxDetector - 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: ProxDetector (
/showthread.php?tid=492983)
ProxDetector -
Mauricee - 06.02.2014
I am outdated from the world of SA-MP Scripting ... There is a fastest function for classic-ProxDetector?
Re: ProxDetector -
Wizzy951 - 06.02.2014
You may try this one:
pawn Код:
Stock SendNearMessage(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;
}
//Example
SendNearMessage(playerid, 15, string, COLOR_WHITE COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE)
AW: Re: ProxDetector -
Nero_3D - 06.02.2014
Quote:
Originally Posted by Wizzy951
|
The only difference would be foreach... at least use the natives now available and a switch
pawn Код:
ProxDetector(playerid, Float: radius, string[], col1, col2, col3, col4, col5) {
new
Float: x,
Float: y,
Float: z
;
if(GetPlayerPos(playerid, x, y, z)) {
new
interior = GetPlayerInterior(playerid),
virtualworld = GetPlayerVirtualWorld(playerid)
;
foreach(Player, i) {
if((GetPlayerInterior(i) == interior) && (GetPlayerVirtualWorld(i) == virtualworld)) {
switch(floatround((radius / GetPlayerDistanceFromPoint(i, x, y, z)), floatround_floor)) {
case 0: {} // not in range
case 1: SendClientMessage(i, col5, string);
case 2, 3: SendClientMessage(i, col4, string);
case 4..7: SendClientMessage(i, col3, string);
case 8..15: SendClientMessage(i, col2, string);
default: SendClientMessage(i, col1, string); // 16 or over
}
}
}
return true;
}
return false;
}