Jump to content

Hook conflicts

Closed 2.6.9

IIIaKa
IIIaKa

Posted (edited)


Calling hook OnNpcTarget resulted in a conflict between the following plugins: RealPVE - False (Boolean), ArcticBaseEvent (True (Boolean))
Calling hook OnNpcTarget resulted in a conflict between the following plugins: NpcSpawn - True (Boolean), RealPVE (False (Boolean))

Hello, in your plugin, you return true to prevent targeting your NPC. Could you change true to false? It is more logical.

 NpcSpawn:

private object OnNpcTarget(NPCPlayer attacker, CustomScientistNpc victim)
{
  if (attacker == null || !IsCustomScientist(victim)) return null;
  if (_config.CanTargetNpc) return null;
  else return true;
}

private object OnNpcTarget(BaseAnimalNPC attacker, CustomScientistNpc victim)
{
  if (attacker == null || !IsCustomScientist(victim)) return null;
  if (_config.CanTargetAnimal) return null;
  else return true;
}


Like this(I think the check for attacker == null is unnecessary):

private object OnNpcTarget(NPCPlayer attacker, CustomScientistNpc victim)
{
  if (attacker == null || !IsCustomScientist(victim) || _config.CanTargetNpc) return null;
  return false;
}

private object OnNpcTarget(BaseAnimalNPC attacker, CustomScientistNpc victim)
{
  if (attacker == null || !IsCustomScientist(victim) || _config.CanTargetAnimal) return null;
  return false;
}

 

Alternatively, this avoids the unnecessary IsCustomScientist check. But I'm not entirely sure, it needs to be checked:

private object OnNpcTarget(NPCPlayer attacker, CustomScientistNpc victim) => _config.CanTargetNpc ? null : false;
private object OnNpcTarget(BaseAnimalNPC attacker, CustomScientistNpc victim) => _config.CanTargetAnimal ? null : false;

private object OnNpcTarget(NPCPlayer attacker, ScientistNPC victim) => null;
private object OnNpcTarget(BaseAnimalNPC attacker, ScientistNPC victim) => null;


HumanNPC:

public BaseEntity GetBestTarget()
{
  BaseEntity result = null;
  float num = -1f;
  foreach (BaseEntity player in Brain.Senses.Players)
  {
    if (!(player == null) && !(player.Health() <= 0f) && Interface.CallHook("OnNpcTarget", this, player) == null)
    {
      float value = Vector3.Distance(player.transform.position, base.transform.position);
      float num2 = 1f - Mathf.InverseLerp(1f, Brain.SenseRange, value);
      float value2 = Vector3.Dot((player.transform.position - eyes.position).normalized, eyes.BodyForward());
      num2 += Mathf.InverseLerp(Brain.VisionCone, 1f, value2) / 2f;
      num2 += (Brain.Senses.Memory.IsLOS(player) ? 2f : 0f);
      if (num2 > num)
      {
        result = player;
        num = num2;
      }
    }
  }
  
  return result;
}



 

Edited by IIIaKa
IIIaKa

Posted (edited)

*del

Edited by IIIaKa
Jbird

Posted

On 5/29/2024 at 2:07 AM, IIIaKa said:


Calling hook OnNpcTarget resulted in a conflict between the following plugins: RealPVE - False (Boolean), ArcticBaseEvent (True (Boolean))
Calling hook OnNpcTarget resulted in a conflict between the following plugins: NpcSpawn - True (Boolean), RealPVE (False (Boolean))

Hello, in your plugin, you return true to prevent targeting your NPC. Could you change true to false? It is more logical.

There is a config option in NpcSpawn main config for this.

KpucTaJl

Posted

Hello everyone, the OnNpcTarget hook returns the value of object, not bool, so according to the rules of writing code, it is correct to return the value true and not false. Thus, it is necessary to edit the RealPVE plugin to prevent a conflict

KpucTaJl

Posted

Changed Status from Pending to Closed

1.7m

Downloads

Total number of downloads.

7.2k

Customers

Total customers served.

108.2k

Files Sold

Total number of files sold.

2.2m

Payments Processed

Total payments processed.

×
×
  • 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.