Jump to content

New EntityTakeDamage logic based on CanTargetEntity is causing issues for me

Pending 3.3.6

evict
evict

Posted

Hi! First of all, thank you very much for this plugin. All the recent updates are great.

For context, I'm using NpcSpawn integrated to my plugin to allow players to recruit bots to fight by their side.

The thing is, since the recent changes on NpcSpawn, I'm unable to allow players to damage their own allied bots because of this logic you implemented inside the OnEntityTakeDamage hook

if (victimNpc.CanTargetEntity(attacker))
{
    if (info.isHeadshot && victimNpc.Config.InstantDeathIfHitHead && attacker is BasePlayer basePlayer && basePlayer.IsPlayer()) info.damageTypes.ScaleAll(victimNpc.health / info.damageTypes.Total());
    else
    {
        info.damageTypes.ScaleAll(info.boneArea switch
        {
            HitArea.Head => victimNpc.Config.HeadDamageScale,
            HitArea.Chest or HitArea.Stomach or HitArea.Arm or HitArea.Hand => victimNpc.Config.BodyDamageScale,
            HitArea.Foot or HitArea.Leg => victimNpc.Config.LegDamageScale,
            _ => 1f
        });
        if (attacker is CustomScientistNpc attackerNpc && IsCustomScientist(attackerNpc)) info.damageTypes.ScaleAll(attackerNpc.Config.NpcDamageScale);
        victimNpc.SetKnown(attacker);
        victimNpc.TrySendTargetGroup(attacker);
    }
    return null;
}
else
{
    if (attacker is BasePlayer player && player.IsPlayer() && (player.limitNetworking || player.isInvisible)) return null;
    return true;
}

 

The problem is, I want the allied bots to not be able to target their allied players, but the players must be able to damage their own bots even though the bots can't target them back. (so players can kill their own bots if they get stuck somewhere or even accidentaly during fights).

But with this condition if (victimNpc.CanTargetEntity(attacker)) you implemented this seems to be impossible now.

Is there a possibility that you can add another config inside NpcConfig like: bool CanBeDamagedByAnySources false by default but if true, ignore this condition here and allow any damages from any sources (return null in the hook)?

aimacak

Posted

On 6/26/2026 at 6:49 PM, evict said:

Hi! First of all, thank you very much for this plugin. All the recent updates are great.

For context, I'm using NpcSpawn integrated to my plugin to allow players to recruit bots to fight by their side.

The thing is, since the recent changes on NpcSpawn, I'm unable to allow players to damage their own allied bots because of this logic you implemented inside the OnEntityTakeDamage hook

if (victimNpc.CanTargetEntity(attacker))
{
    if (info.isHeadshot && victimNpc.Config.InstantDeathIfHitHead && attacker is BasePlayer basePlayer && basePlayer.IsPlayer()) info.damageTypes.ScaleAll(victimNpc.health / info.damageTypes.Total());
    else
    {
        info.damageTypes.ScaleAll(info.boneArea switch
        {
            HitArea.Head => victimNpc.Config.HeadDamageScale,
            HitArea.Chest or HitArea.Stomach or HitArea.Arm or HitArea.Hand => victimNpc.Config.BodyDamageScale,
            HitArea.Foot or HitArea.Leg => victimNpc.Config.LegDamageScale,
            _ => 1f
        });
        if (attacker is CustomScientistNpc attackerNpc && IsCustomScientist(attackerNpc)) info.damageTypes.ScaleAll(attackerNpc.Config.NpcDamageScale);
        victimNpc.SetKnown(attacker);
        victimNpc.TrySendTargetGroup(attacker);
    }
    return null;
}
else
{
    if (attacker is BasePlayer player && player.IsPlayer() && (player.limitNetworking || player.isInvisible)) return null;
    return true;
}

 

The problem is, I want the allied bots to not be able to target their allied players, but the players must be able to damage their own bots even though the bots can't target them back. (so players can kill their own bots if they get stuck somewhere or even accidentaly during fights).

But with this condition if (victimNpc.CanTargetEntity(attacker)) you implemented this seems to be impossible now.

Is there a possibility that you can add another config inside NpcConfig like: bool CanBeDamagedByAnySources false by default but if true, ignore this condition here and allow any damages from any sources (return null in the hook)?

Hello, sorry for the long reply, I gave this information to KpucTaJI, because I think that I, as an intermediary, will be superfluous here and you will understand each other faster without me. You can also create a ticket in Mad Mappers, there is a chance that he will respond faster there, but I do not promise.. summer..

evict

Posted

Hi! That's ok, no worries. I can wait for a reply here. When you have an answer from the developer, please let me know.

Cheers!

  • Like 1

About Us

Codefling is the largest marketplace for plugins, maps, tools, and more, making it easy for customers to discover new content and for creators to monetize their work.

Downloads
2.7m
Total downloads
Customers
11.5k
Customers served
Files Sold
164.5k
Total sales
Payments
3.6m
Processed total
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.