Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sourcemod>
- #include <sdktools>
- #include <actions>
- methodmap SurvivorTakePillsOrAdrenaline < BehaviorAction
- {
- public SurvivorTakePillsOrAdrenaline()
- {
- /* Create custom action */
- SurvivorTakePillsOrAdrenaline action = view_as<SurvivorTakePillsOrAdrenaline>(ActionsManager.Create("SurvivorTakePillsOrAdrenaline"));
- /* Hook anything that we need */
- action.OnStart = SurvivorTakePillsOrAdrenaline_OnStart;
- action.Update = SurvivorTakePillsOrAdrenaline_Update;
- action.OnEnd = SurvivorTakePillsOrAdrenaline_OnEnd;
- return action;
- }
- public bool IsHoldingUsable()
- {
- int actor = this.Actor;
- int hold = GetEntPropEnt(actor, Prop_Send, "m_hActiveWeapon");
- if (hold == -1)
- return false;
- return hold == GetPlayerWeaponSlot(actor, 4);
- }
- }
- Handle g_hSwitchWeapon;
- bool g_bShouldPressM1[MAXPLAYERS + 1];
- public void OnPluginStart()
- {
- StartPrepSDKCall(SDKCall_Player);
- PrepSDKCall_SetVirtual(284); // 285 linux
- PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- g_hSwitchWeapon = EndPrepSDKCall();
- }
- public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
- {
- if ( strcmp(name, "SurvivorHealSelf") == 0 )
- action.OnStart = SurvivorHealSelf_OnStart;
- }
- public Action SurvivorHealSelf_OnStart( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
- {
- /* When action for healing youself start we check if bot has pills or adrenaline */
- if (HasPillsOrAdrenaline(actor))
- {
- /* Create action to change to */
- SurvivorTakePillsOrAdrenaline take = SurvivorTakePillsOrAdrenaline();
- action.ChangeTo(take, "Use something else instead first aid kit");
- return Plugin_Handled;
- }
- return Plugin_Continue;
- }
- public Action SurvivorTakePillsOrAdrenaline_OnStart( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
- {
- /* Action transitions are not instant and we could lose pills/adrenaline while transitioning, check it again */
- if (!HasPillsOrAdrenaline(actor))
- {
- return action.Done("I don't have any pills or adrenaline");
- }
- return action.Continue();
- }
- public Action SurvivorTakePillsOrAdrenaline_Update( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
- {
- /* If we used pills then we don't have them anymore */
- if (!HasPillsOrAdrenaline(actor))
- {
- return action.Done("Used healthy thingy");
- }
- /* if holding item is not what we need then switch and continue on next frame */
- if (!action.IsHoldingUsable())
- {
- int usable = GetPlayerWeaponSlot(actor, 4);
- SwitchWeapon(actor, usable);
- }
- else
- {
- /* switched to usable. use it */
- g_bShouldPressM1[actor] = true;
- }
- return action.Continue();
- }
- public void SurvivorTakePillsOrAdrenaline_OnEnd( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
- {
- g_bShouldPressM1[actor] = false;
- }
- public Action OnPlayerRunCmd(int client, int& buttons)
- {
- if (g_bShouldPressM1[client])
- {
- buttons |= IN_ATTACK;
- return Plugin_Changed;
- }
- return Plugin_Continue;
- }
- bool HasPillsOrAdrenaline(int actor)
- {
- return GetPlayerWeaponSlot(actor, 4) != -1;
- }
- stock void SwitchWeapon(int client, int weapon)
- {
- SDKCall(g_hSwitchWeapon, client, weapon, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement