New command, 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: New command, help. (
/showthread.php?tid=81453)
New command, help. -
Abernethy - 11.06.2009
I was wondering how I would make a /infect command.
If a 'Infected' uses /infect within' a radius of 2 his team will be set to the Infecteds, & he will change skin etc ..
How would I check if they're in range & stuff?
Re: New command, help. -
efeX - 11.06.2009
Well you could use ProxDetectorS from godfather
pawn Код:
public ProxDetectorS(Float:radi, playerid, targetid)
{
if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
{
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
GetPlayerPos(targetid, posx, posy, posz);
tempposx = (oldposx -posx);
tempposy = (oldposy -posy);
tempposz = (oldposz -posz);
if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
return 1;
}
}
return 0;
}
Then you could say
pawn Код:
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (ProxDetectorS(2.0, playerid, i)
{
// infect them.
}
}
That should work.
Re: New command, help. -
Joe Staff - 11.06.2009
Should work, but that's not players within a sphere, that's players within a cube and is less efficient than the sphere check.
pawn Код:
PlayerNearPlayer(player1,player2,Float:distance)
{
new Float:tmp[2][3];
GetPlayerPos(player1,tmp[0][0],tmp[0][1],tmp[0][2]);
GetPlayerPos(player2,tmp[1][0],tmp[1][1],tmp[1][2]);
return ((((tmp[1][0]-tmp[0][0])*(tmp[1][0]-tmp[0][0]))+((tmp[1][1]-tmp[0][1])*(tmp[1][1]-tmp[0][1]))+((tmp[1][2]-tmp[0][2])*(tmp[1][2]-tmp[0][2])))<distance*distance);
}
But none-the-less it will work