getclosestplayer 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: getclosestplayer help (
/showthread.php?tid=210542)
getclosestplayer help -
WardenCS - 13.01.2011
Hello,i need help with the getclosestplayer function,i dont remember how to use it,i want to make command if player is near other player,like if the player is near someone more then meter then he will get infected.
Re: getclosestplayer help -
Gratiz - 13.01.2011
try prox detector
pawn Код:
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) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(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 1;
}
Re: getclosestplayer help -
WardenCS - 13.01.2011
Код:
forward ProxInfect(Float:radi, playerid, str[],playerid2);
public ProxInfect(Float:radi, playerid, str[],playerid2)
{
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))
{
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) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
Infected[playerid2] = 1;
Inftimer = SetTimerEx("InfectedTimer",5000,true,"i",playerid2);
}
}
}
}//not connected
return 1;
}
smth like that?and how can i use it in cmd?
Re: getclosestplayer help -
WardenCS - 13.01.2011
upsti
AW: getclosestplayer help -
Nero_3D - 14.01.2011
The ProxDetector comes from the source of all evil, the gotfather code, dont use it
pawn Код:
forward Infect();
public Infect() //Need to be called with SetTimer
{ //Will infect players if they come in the range of 2.0 of an infected
new
j = -1,
i = -1,
Float:X,
Float:Y,
Float:Z,
f = MAX_PLAYERS,
sorted[MAX_PLAYERS];
while((++i) != MAX_PLAYERS)
if(Infected[i] == 0)
sorted[++j] = i;
else sorted[--f] = i;
while((--f) != -1)
if(GetPlayerPos(sorted[f], X, Y, Z))
for(i = j; (++i) != MAX_PLAYERS; )
if(IsPlayerInRangeOfPoint(sorted[i], 2.0, X, Y, Z))
{
Infected[sorted[f]] = 1;
break;
}
}