/heal ID
#1

Hello, I'm almost finished with my /heal command, but the only thing I must fix is that only players in a specific range of the player should be able to heal the player. How do I do it?

pawn Код:
if(strcmp(cmd, "/heal", true) == 0)
    {
      if(IsPlayerConnected(playerid))
      {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "/heal ID");
                return 1;
            }
            new playa;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(HealInfo[playerid][pHealkit] == 1)
            {
              if(IsPlayerConnected(playa))
              {
                if(playa != INVALID_PLAYER_ID)
                {
                  HealInfo[playerid][pHeal] = 0;
                        SetPlayerHealth(playa, 100);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command");
            }
        }
        return 1;
    }
Reply
#2

pawn Код:
stock Float:GetDistanceBetweenPlayers(p1,p2){
    new Float:x1,Float:y1,Float:z1,Float:x3,Float:y3,Float:z3;
    if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x3,y3,z3);
    return floatsqroot(floatpower(floatabs(floatsub(x3,x1)),2)+floatpower(floatabs(floatsub(y3,y1)),2)+floatpower(floatabs(floatsub(z3,z1)),2));
}
Reply
#3

Shouldn't it be possible to use a functions such as IsPlayerInRangeOfPoint of PlayerToPoint?
Reply
#4

use use GetPlayerPos(targetid,x,y,z); to get the pos of targetid

then
Код:
If(!IsPlayerInRangeOfPoint(playerid,6,x,y,z) return SendClientMessage(playerid,color,"msg");
Reply
#5

Код:
new Target,Float:X,Float:Y,Float:Z;
GetPlayerPos(Target,X,Y,Z);
if(IsPlayerInRangeOfPoint(playerid,2.0,X,Y,Z))
{
//DO
}
else
{
//Don't
}
Reply
#6

download a good admin system and it will have that cmd
Reply
#7

Add this somewhere in your script:

pawn Код:
stock GetDistanceBetweenPlayers(playerid,playerid2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(playerid2,x2,y2,z2);
    tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
    return floatround(tmpdis);
}
Then add this to your /heal command

pawn Код:
if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 5)
{
  SendClientMessage(playerid,0x87CEEBAA, "Player is not close enough to heal")
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)