New command, help.
#1

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?
Reply
#2

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.
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)