Skip to content

Commit

Permalink
Add OnNpcTarget hook for new NPC types (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1lly0u authored Dec 30, 2024
1 parent ba8655f commit 136403c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
26 changes: 26 additions & 0 deletions resources/Rust.opj
Original file line number Diff line number Diff line change
Expand Up @@ -21272,6 +21272,32 @@
"BaseHookName": "OnItemSubmit",
"HookCategory": "Item"
}
},
{
"Type": "Simple",
"Hook": {
"InjectionIndex": 65,
"ReturnBehavior": 1,
"ArgumentBehavior": 3,
"ArgumentString": null,
"HookTypeName": "Simple",
"Name": "IOnNpcTarget [SenseComponent]",
"HookName": "IOnNpcTarget",
"AssemblyName": "Assembly-CSharp.dll",
"TypeName": "Rust.Ai.Gen2.SenseComponent",
"Flagged": false,
"Signature": {
"Exposure": 2,
"Name": "CanTarget",
"ReturnType": "System.Boolean",
"Parameters": [
"BaseEntity"
]
},
"MSILHash": "1IFiFqiPi/UAOwFf2XHRsTyhryQEa4oAooUITmm0s6k=",
"BaseHookName": null,
"HookCategory": "NPC"
}
}
],
"Modifiers": [
Expand Down
29 changes: 29 additions & 0 deletions src/RustHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Oxide.Core.Plugins;
using Oxide.Core.RemoteConsole;
using Oxide.Game.Rust.Libraries.Covalence;
using Rust.Ai.Gen2;
using Steamworks;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -68,6 +69,34 @@ private object IOnNpcTarget(BaseNpc npc, BaseEntity target)
return null;
}

/// <summary>
/// Called when an NPC tries to target an entity
/// </summary>
/// <param name="sense"></param>
/// <param name="target"></param>
/// <returns></returns>
[HookMethod("IOnNpcTarget")]
private object IOnNpcTarget(SenseComponent sense, BaseEntity target)
{
if (!sense || !target)
{
return null;
}

BaseEntity baseEntity = sense.baseEntity;
if (!baseEntity)
{
return null;
}

if (Interface.CallHook("OnNpcTarget", baseEntity, target) != null)
{
return false;
}

return null;
}

/// <summary>
/// Called after a BaseNetworkable has been saved into a ProtoBuf object that is about to
/// be serialized for a network connection or cache
Expand Down

0 comments on commit 136403c

Please sign in to comment.