Checking if player is a team member?Solved
Hello, im trying to make a friendlyfire plugin for teammates with the function onentitytakedamage, i know i need to use this hook right? But idk how put it to check if is team members, help me please or explain me how it works, im new in plugin dev i only now and bad the basics
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
    if (entity is BasePlayer)
    {
        return true;
    }

    return null;
}
 object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (entity is BasePlayer && info.Initiator is BasePlayer)
            {
                var victim = entity.ToPlayer();
                var attacker = info.Initiator.ToPlayer();

                if (attacker.Team.members.Contains(victim.userID))
                {
                    return false;
                }
            }
            return null;
        }

i have not tested this yet as its time for me to go to work . but this should give you a direction

I would nullify the damage rather than returning with that hook.
thank you wolf . with some testing we got it to wok without fail with this

 object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (entity is BasePlayer && info.Initiator is BasePlayer)
            {
                var victim = entity.ToPlayer();
                var attacker = info.Initiator.ToPlayer();
                if (victim.userID != attacker.userID)
                {

                    if (attacker.Team != null)
                    {
                        if (!attacker.Team.members.Contains(victim.userID))
                        {
                            return null;
                        }
                    }
                    if (attacker.Team == null)
                    {
                        return null;
                    }
                    return false;
                }

            }
            return null;
        }​
5d45358864483.png NooBlet
thank you wolf . with some testing we got it to wok without fail with this

 object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (entity is BasePlayer && info.Initiator is BasePlayer)
            {
                var victim = entity.ToPlayer();
                var attacker = info.Initiator.ToPlayer();
                if (victim.userID != attacker.userID)
                {

                    if (attacker.Team != null)
                    {
                        if (!attacker.Team.members.Contains(victim.userID))
                        {
                            return null;
                        }
                    }
                    if (attacker.Team == null)
                    {
                        return null;
                    }
                    return false;
                }

            }
            return null;
        }​
That wasn't what I meant by nullify. :p You can see an example of nullifying the damage in some plugins, like Godmode or maybe Friendly Fire.
Locked automatically