Extension provides a natives to hook action event handlers and create custom actions
Notes
If two different plugins will try to return different action for same eventhandler last will be chosen.
Extension doesn't support late load so after reload you must recreate nextbots
All actions are cached by their parent action event handlers
Commands & ConVars
PHP Code:
/* Commands */
ext_actions_dump - dumps entities actions
ext_actions_offsets - prints every hooked function offset
ext_actions_listeners - dumps actions listeners
ext_actions_list - dumps every action that manager currently holds
/* ConVars */
ext_actions_debug - debugs action propagation (1 - Enable debug, 0 - Disable debug)
ext_actions_debug_processors - Logs processors (-2 - Disabled, -1 - Debug all, N - function vtable index to debug)
Examples
Block actions
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <actions>
public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
{
if ( strcmp(name, "WitchAttack") == 0 )
{
/* Hook OnStart handler */
action.OnStart = OnStart;
}
}
public Action OnStart( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
/* When WitchAttack actions starts force it to end */
result.type = DONE;
return Plugin_Changed;
}
Custom actions
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <actions>
public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
{
if ( strcmp(name, "SurvivorAttack") == 0 )
action.OnStart = OnStart;
}
public Action OnStart( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
/* We suspend WitchAttack action for our action */
/* That means WitchAttack will be like in frozen state */
/* It's will not be updated until our action is done */
public Action OnMyActionStart( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
PrintToServer("We are started!");
return Plugin_Continue;
}
public Action OnMyActionUpdate( BehaviorAction action, int actor, float interval, ActionResult result )
{
PrintToServer("MyCustomAction is updating...");
if (GetRandomFloat() >= 0.5)
{
return action.Done("We are done");
}
return Plugin_Continue;
}
Changing original result
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <actions>
public void OnActionCreated( BehaviorAction action, int actor, int actor, const char[] name )
{
if ( strcmp(name, "WitchIdle") == 0 || strcmp(name, "WitchAngry") == 0 )
{
/* We set post hook otherwise ActionDesiredResult will contain default values */
action.OnShovedPost = OnShovedPost;
}
}
public Action OnShovedPost( BehaviorAction action, int actor, int shover, ActionDesiredResult result )
{
if ( result.type == SUSPEND_FOR )
{
result.type = CONTINUE;
return Plugin_Changed;
}
return Plugin_Continue;
}
Making bots to heal only you or self only for BW state
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <actions>
stock int m_bIsOnThirdStrike;
public void OnPluginStart()
{
m_bIsOnThirdStrike = FindSendPropInfo("CTerrorPlayer", "m_bIsOnThirdStrike");
}
public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
{
/* Hooking self healing action (when bot wants to heal self) */
if ( strcmp(name, "SurvivorHealSelf") == 0 )
action.OnStart = OnSelfAction;
/* Hooking take pills action (when bot wants to take pills) */
if ( strcmp(name, "SurvivorTakePills") == 0 )
action.OnStart = OnSelfAction;
/* Hooking give pills action (when bot wants to give pills) */
if ( strcmp(name, "SurvivorGivePillsToFriend") == 0 )
action.OnStartPost = OnFriendAction;
}
public Action OnSelfAction( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
/* When bot will be about to start healing/taking pills we chech if he's black & white */
/* if he is then we allow to heal otherwise no */
result.type = GetEntData(action.Actor, m_bIsOnThirdStrike, 1) ? CONTINUE : DONE;
return Plugin_Handled;
}
public Action OnFriendAction( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
/* When bot will be about to start healing/giving pills to someone, we chech if friend is black & white */
/* if friend is then we allow to give heal otherwise no */
int target = action.Get(0x34) & 0xFFF;
result.type = GetEntData(target, m_bIsOnThirdStrike, 1) ? CONTINUE : DONE;
return Plugin_Handled;
}
I am having a issue with this. Actions completely chokes my server, making the server unplayable. I'm using Linux for my server, and it doesn't handle well.
I am having a issue with this. Actions completely chokes my server, making the server unplayable. I'm using Linux for my server, and it doesn't handle well.
This extension doesn't do anything heavy-weighted on it's own. It's either plugin or something.
When a behavioral action is created, is it possible to change it to a different behavioral action? In one of your examples, you have this example where I took just an excerpt:
Code:
public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
{
/* Hooking self healing action (when bot wants to heal self) */
if ( strcmp(name, "SurvivorHealSelf") == 0 )
action.OnStart = OnSelfAction;
/* Hooking take pills action (when bot wants to take pills) */
if ( strcmp(name, "SurvivorTakePills") == 0 )
action.OnStart = OnSelfAction;
}
public Action OnSelfAction( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
{
/* When bot will be about to start healing/taking pills we chech if he's black & white */
/* if he is then we allow to heal otherwise no */
result.type = GetEntData(action.Actor, m_bIsOnThirdStrike, 1) ? CONTINUE : DONE;
return Plugin_Handled;
}
When the action is "SurvivorHealSelf" is it possible to change it to "SurvivorTakePills" instead, so if allowed and returned with Plugin_Changed the bot would take pills instead of healing with a first_aid_kit (assuming the bot has pain_pills of course)? I suspect the answer is No, but on the off chance the answer is Yes, please provide some information about how to configure this. Thank you!
Last edited by Mystik Spiral; 07-04-2023 at 05:50.
When a behavioral action is created, is it possible to change it to a different behavioral action?
When the action is "SurvivorHealSelf" is it possible to change it to "SurvivorTakePills" instead, so if allowed and returned with Plugin_Changed the bot would take pills instead of healing with a first_aid_kit (assuming the bot has pain_pills of course)? I suspect the answer is No, but on the off chance the answer is Yes, please provide some information about how to configure this. Thank you!
Yeah you can create your own action with custom logic or use game action and change to it.
I created a simple example with some explanation. https://pastebin.com/NCE0491B
You can control action transition by using natives and control original code execution by return value.
Plugin_Handled - Blocks original function and uses your result
Plugin_Changed - Calls original function and uses your result
Plugin_Continue - Doesn't do anything
Yeah you can create your own action with custom logic or use game action and change to it.
I created a simple example with some explanation. https://pastebin.com/NCE0491B
You can control action transition by using natives and control original code execution by return value.
Plugin_Handled - Blocks original function and uses your result
Plugin_Changed - Calls original function and uses your result
Plugin_Continue - Doesn't do anything
This was super helpful @BHaType, thank you very much!
"Actions" are all new to me so it may take a while to digest, but I believe this will let me finish what I was working on. Thank you again for such a detailed and helpful reply!
Installed the freshest version and got this in the logs:
Quote:
L 07/19/2023 - 22:01:24: [SM] Unable to load extension "actions.ext": /lib/i386-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/gpx/users/komikozovich/178.63.13.143-27370/222860/left4dead2/addons/sourcemod/extensions/actions.ext.2.l4d2.so)
L 07/19/2023 - 22:01:24: [SM] Unable to load plugin "l4d2_shove_fix.smx": Required extension "Actions" file("actions.ext") not running
UPD: Ok, I see a similar post back there, could you please post a l4d2 version of that?
Last edited by KoMiKoZa; 07-19-2023 at 17:22.
Reason: UPD
@KoMiKoZa, need to re-compile on Debian 9, or update server OS.
I see, thanks. Well, I'd be glad if anyone could post the compiled version here.
Renting a server, don't think the support is going to bother with that, but might be worth a try asking. Myself, I am clueless as to how anything beyond Windows OS works, so...
Put back the backups of shove_fix.lmx and actions.l4d2.ext, works fine. Will do until then.