Advertisement
Guest User

Untitled

a guest
Jul 4th, 2023
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.43 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sourcemod>
  5. #include <sdktools>
  6.  
  7. #include <actions>
  8.  
  9. methodmap SurvivorTakePillsOrAdrenaline < BehaviorAction
  10. {
  11.     public SurvivorTakePillsOrAdrenaline()
  12.     {
  13.         /* Create custom action */
  14.         SurvivorTakePillsOrAdrenaline action = view_as<SurvivorTakePillsOrAdrenaline>(ActionsManager.Create("SurvivorTakePillsOrAdrenaline"));
  15.  
  16.         /* Hook anything that we need */
  17.         action.OnStart = SurvivorTakePillsOrAdrenaline_OnStart;
  18.         action.Update = SurvivorTakePillsOrAdrenaline_Update;
  19.         action.OnEnd = SurvivorTakePillsOrAdrenaline_OnEnd;
  20.        
  21.         return action;
  22.     }
  23.  
  24.     public bool IsHoldingUsable()
  25.     {
  26.         int actor = this.Actor;
  27.         int hold = GetEntPropEnt(actor, Prop_Send, "m_hActiveWeapon");
  28.  
  29.         if (hold == -1)
  30.             return false;
  31.  
  32.         return hold == GetPlayerWeaponSlot(actor, 4);
  33.     }
  34. }
  35.  
  36. Handle g_hSwitchWeapon;
  37. bool g_bShouldPressM1[MAXPLAYERS + 1];
  38.  
  39. public void OnPluginStart()
  40. {
  41.     StartPrepSDKCall(SDKCall_Player);
  42.     PrepSDKCall_SetVirtual(284); // 285 linux
  43.     PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
  44.     PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
  45.     g_hSwitchWeapon = EndPrepSDKCall();
  46. }
  47.  
  48. public void OnActionCreated( BehaviorAction action, int actor, const char[] name )
  49. {
  50.     if (  strcmp(name, "SurvivorHealSelf") == 0 )    
  51.         action.OnStart = SurvivorHealSelf_OnStart;
  52. }
  53.  
  54. public Action SurvivorHealSelf_OnStart( BehaviorAction action, int actor, BehaviorAction priorAction, ActionResult result )
  55. {
  56.     /* When action for healing youself start we check if bot has pills or adrenaline */
  57.     if (HasPillsOrAdrenaline(actor))
  58.     {
  59.         /* Create action to change to */
  60.         SurvivorTakePillsOrAdrenaline take = SurvivorTakePillsOrAdrenaline();
  61.         action.ChangeTo(take, "Use something else instead first aid kit");
  62.         return Plugin_Handled;
  63.     }
  64.  
  65.     return Plugin_Continue;
  66. }
  67.  
  68. public Action SurvivorTakePillsOrAdrenaline_OnStart( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
  69. {
  70.     /* Action transitions are not instant and we could lose pills/adrenaline while transitioning, check it again */
  71.     if (!HasPillsOrAdrenaline(actor))
  72.     {
  73.         return action.Done("I don't have any pills or adrenaline");
  74.     }
  75.  
  76.     return action.Continue();
  77. }
  78.  
  79. public Action SurvivorTakePillsOrAdrenaline_Update( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
  80. {
  81.     /* If we used pills then we don't have them anymore */
  82.     if (!HasPillsOrAdrenaline(actor))
  83.     {
  84.         return action.Done("Used healthy thingy");
  85.     }
  86.  
  87.     /* if holding item is not what we need then switch and continue on next frame */
  88.     if (!action.IsHoldingUsable())
  89.     {
  90.         int usable = GetPlayerWeaponSlot(actor, 4);
  91.         SwitchWeapon(actor, usable);
  92.     }
  93.     else
  94.     {
  95.         /* switched to usable. use it */
  96.         g_bShouldPressM1[actor] = true;
  97.     }
  98.  
  99.     return action.Continue();
  100. }
  101.  
  102. public void SurvivorTakePillsOrAdrenaline_OnEnd( SurvivorTakePillsOrAdrenaline action, int actor, BehaviorAction priorAction, ActionResult result )
  103. {
  104.     g_bShouldPressM1[actor] = false;
  105. }
  106.  
  107. public Action OnPlayerRunCmd(int client, int& buttons)
  108. {
  109.     if (g_bShouldPressM1[client])
  110.     {
  111.         buttons |= IN_ATTACK;
  112.         return Plugin_Changed;
  113.     }
  114.  
  115.     return Plugin_Continue;
  116. }
  117.  
  118. bool HasPillsOrAdrenaline(int actor)
  119. {
  120.     return GetPlayerWeaponSlot(actor, 4) != -1;
  121. }
  122.  
  123. stock void SwitchWeapon(int client, int weapon)
  124. {
  125.     SDKCall(g_hSwitchWeapon, client, weapon, 0);
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement