Script isn't reading part of the timer
#1

Had problems with this all day, really need this fixed.

pawn Код:
public MedicTimer()
{
    foreach(Player, playerid)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][Medic] == 1 && PlayerInfo[playerid][Army] == 1)
            {
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                foreach(Player, i)
                {
                    if(IsPlayerConnected(i) && i != playerid)
                    {
                        if(IsPlayerInRangeOfPoint(i, 1.0, x, y, z))
                        {
                            new Float:health;
                            GetPlayerHealth(i, health);
                            if(health < 100.0)
                            {
                                SetPlayerHealth(i, 100.0);
                                SendClientMessage(i, COLOUR_GREEN, "HEALED" );
                                SendClientMessage(i, COLOUR_GREEN, "Thank the medic, who risked his life to save yours!" );
                                return 1;
                            }
                        }
                        if(PlayerInfo[i][Enemy] == 1 || PlayerInfo[i][Medic] == 1)
                        {
                            return 0;
                        }
                    }
                }
            }
        }
    }
}
For some reason it ignores the fact that the other player is the enemy and heals them as well.
Reply
#2

pawn Код:
public MedicTimer()
{
    foreach(Player, playerid)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][Medic] == 1 && PlayerInfo[playerid][Army] == 1)
            {
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                foreach(Player, i)
                {
                    if(IsPlayerConnected(i))
                    {
                        if(IsPlayerInRangeOfPoint(i, 1.0, x, y, z))
                        {
                            new Float:health;
                            GetPlayerHealth(i, health);
                            if(health < 100.0 && PlayerInfo[i][Enemy] == 0)//make sure not setting it to the enemie
                            {
                                SetPlayerHealth(i, 100.0);
                                SendClientMessage(i, COLOUR_GREEN, "HEALED" );
                                SendClientMessage(i, COLOUR_GREEN, "Thank the medic, who risked his life to save yours!" );
                                return 1;
                            }
                        }
                    }
                }
            }
        }
    }
}
this needs to be rescripted into a better way if you want it to be more accurate :X
some of the variables are not need it makes more checks then it needs :X
Reply
#3

foreach(Player, i)
{
if(IsPlayerConnected(i))
{

There is no need for that - foreach ONLY loops through CONNECTED players - that's the entire reason it exists.
Reply
#4

1) get rid of isplayerconnected. As MP2 said, its useless in a foreach loop
2) Also, check to see if they are worthy of healing (not an enemy) towards the BEGINNING of the second loop, and move onto the next player if they are the enemy. AKA put it somewhere before it checks the players distance from the medic.

EDIT: yah jsut checked again...you aren't checking their friend/foe status before the heal. Its just going to heal anyone close to the medic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)