Skip to content

Conversation

@k1lly0u
Copy link
Contributor

@k1lly0u k1lly0u commented Dec 5, 2024

No description provided.

@MrBlue MrBlue merged commit 136403c into OxideMod:develop Dec 30, 2024
@IIIaKa
Copy link
Contributor

IIIaKa commented Jan 9, 2025

If returning null, this hook is called very, very frequently. If returning anything other than null, it is called slightly less often than when returning null, but still more frequently than for the others NPCs.

@IIIaKa
Copy link
Contributor

IIIaKa commented Jan 9, 2025

@MrBlue @k1lly0u
I think this hook needs to be moved to another method because CanTarget is also called in other places.
For example, we can move it in the TickTargeting method, within the foreach loop, after CanTarget(item), or in the TrySetTarget method.

@IIIaKa
Copy link
Contributor

IIIaKa commented Jan 9, 2025

Rust.Ai.Gen2.SenseComponent.TickTargeting(float deltaTime)

Code before:

foreach (BaseEntity item in pooledList)
{
    if (CanTarget(item))
    {
        float num2 = base.baseEntity.SqrDistance(item);
        if (item.IsNpc)
        {
            num2 += 100f;
        }

        if (num2 < num)
        {
            num = num2;
            baseEntity = item;
        }
    }
}

if (baseEntity != null)
{
    TrySetTarget(baseEntity, bypassCooldown: false);
}

Code after:

foreach (BaseEntity item in pooledList)
{
    if (CanTarget(item))
    {
        ////////OR BEFORE CanTarget(item)
        object obj = Interface.CallHook("IOnNpcTarget", this, item);
        if (obj != null)
        {
            continue;
        }
        ////////

        float num2 = base.baseEntity.SqrDistance(item);
        if (item.IsNpc)
        {
            num2 += 100f;
        }

        if (num2 < num)
        {
            num = num2;
            baseEntity = item;
        }
    }
}

if (baseEntity != null)
{
    TrySetTarget(baseEntity, bypassCooldown: false);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants