Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.86 KB | None | 0 0
  1. #define PLUGIN_VERSION "1.0"
  2.  
  3. /*=======================================================================================
  4. Plugin Info:
  5.  
  6. * Name : [L4D & L4D2] Survivor Shove
  7. * Author : SilverShot
  8. * Descrp : Allows shoving to stagger survivors. Stumbles a survivor when shoved by another survivor.
  9. * Link : https://forums.alliedmods.net/showthread.php?t=318694
  10. * Plugins : http://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
  11.  
  12. ========================================================================================
  13. Change Log:
  14.  
  15. 1.0 (15-Sep-2019)
  16. - Initial release.
  17.  
  18. ======================================================================================*/
  19.  
  20. #pragma semicolon 1
  21. #pragma newdecls required
  22.  
  23. #include <sourcemod>
  24. #include <sdktools>
  25.  
  26. #define CVAR_FLAGS FCVAR_NOTIFY
  27.  
  28. ConVar g_hCvarAllow, g_hCvarMPGameMode, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog;
  29. bool g_bCvarAllow, g_bLeft4Dead2;
  30. Handle g_hConfStagger;
  31.  
  32.  
  33.  
  34. // ====================================================================================================
  35. // PLUGIN INFO / START / END
  36. // ====================================================================================================
  37. public Plugin myinfo =
  38. {
  39. name = "[L4D & L4D2] Survivor Shove",
  40. author = "SilverShot",
  41. description = "Allows shoving to stagger survivors. Stumbles a survivor when shoved by another survivor.",
  42. version = PLUGIN_VERSION,
  43. url = "https://forums.alliedmods.net/showthread.php?t=318694"
  44. }
  45.  
  46. public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
  47. {
  48. EngineVersion test = GetEngineVersion();
  49. if( test == Engine_Left4Dead ) g_bLeft4Dead2 = false;
  50. else if( test == Engine_Left4Dead2 ) g_bLeft4Dead2 = true;
  51. else
  52. {
  53. strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
  54. return APLRes_SilentFailure;
  55. }
  56. return APLRes_Success;
  57. }
  58.  
  59. public void OnPluginStart()
  60. {
  61. // GAMEDATA
  62. if( !g_bLeft4Dead2 )
  63. {
  64. // Stagger: SDKCall method
  65. Handle hConf = LoadGameConfigFile("l4d_survivor_shove");
  66. if( hConf == null )
  67. SetFailState("Missing required 'gamedata/l4d_survivor_shove.txt', please re-download.");
  68.  
  69. StartPrepSDKCall(SDKCall_Entity);
  70. if( PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CTerrorPlayer::OnStaggered") == false )
  71. SetFailState("Could not load the 'CTerrorPlayer::OnStaggered' gamedata signature.");
  72.  
  73. PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
  74. PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
  75. g_hConfStagger = EndPrepSDKCall();
  76. if( g_hConfStagger == null )
  77. SetFailState("Could not prep the 'CTerrorPlayer::OnStaggered' function.");
  78. }
  79.  
  80. // CVARS
  81. g_hCvarAllow = CreateConVar( "l4d_survivor_shove_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
  82. g_hCvarModes = CreateConVar( "l4d_survivor_shove_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
  83. g_hCvarModesOff = CreateConVar( "l4d_survivor_shove_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
  84. g_hCvarModesTog = CreateConVar( "l4d_survivor_shove_modes_tog", "0", "Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.", CVAR_FLAGS );
  85. CreateConVar( "l4d_survivor_shove_version", PLUGIN_VERSION, "Survivor Shove plugin version.", CVAR_FLAGS|FCVAR_DONTRECORD);
  86. AutoExecConfig(true, "l4d_survivor_shove");
  87.  
  88. g_hCvarMPGameMode = FindConVar("mp_gamemode");
  89. g_hCvarMPGameMode.AddChangeHook(ConVarChanged_Allow);
  90. g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
  91. g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
  92. g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
  93. g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
  94. }
  95.  
  96.  
  97.  
  98. // ====================================================================================================
  99. // CVARS
  100. // ====================================================================================================
  101. public void OnConfigsExecuted()
  102. {
  103. IsAllowed();
  104. }
  105.  
  106. public void ConVarChanged_Allow(Handle convar, const char[] oldValue, const char[] newValue)
  107. {
  108. IsAllowed();
  109. }
  110.  
  111. void IsAllowed()
  112. {
  113. bool bCvarAllow = g_hCvarAllow.BoolValue;
  114. bool bAllowMode = IsAllowedGameMode();
  115.  
  116. if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
  117. {
  118. g_bCvarAllow = true;
  119. HookEvent("player_shoved", Event_PlayerShoved);
  120. }
  121.  
  122. else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
  123. {
  124. g_bCvarAllow = false;
  125. UnhookEvent("player_shoved", Event_PlayerShoved);
  126. }
  127. }
  128.  
  129. int g_iCurrentMode;
  130. bool IsAllowedGameMode()
  131. {
  132. if( g_hCvarMPGameMode == null )
  133. return false;
  134.  
  135. int iCvarModesTog = g_hCvarModesTog.IntValue;
  136. if( iCvarModesTog != 0 )
  137. {
  138. g_iCurrentMode = 0;
  139.  
  140. int entity = CreateEntityByName("info_gamemode");
  141. DispatchSpawn(entity);
  142. HookSingleEntityOutput(entity, "OnCoop", OnGamemode, true);
  143. HookSingleEntityOutput(entity, "OnSurvival", OnGamemode, true);
  144. HookSingleEntityOutput(entity, "OnVersus", OnGamemode, true);
  145. HookSingleEntityOutput(entity, "OnScavenge", OnGamemode, true);
  146. ActivateEntity(entity);
  147. AcceptEntityInput(entity, "PostSpawnActivate");
  148. AcceptEntityInput(entity, "Kill");
  149.  
  150. if( g_iCurrentMode == 0 )
  151. return false;
  152.  
  153. if( !(iCvarModesTog & g_iCurrentMode) )
  154. return false;
  155. }
  156.  
  157. char sGameModes[64], sGameMode[64];
  158. g_hCvarMPGameMode.GetString(sGameMode, sizeof(sGameMode));
  159. Format(sGameMode, sizeof(sGameMode), ",%s,", sGameMode);
  160.  
  161. g_hCvarModes.GetString(sGameModes, sizeof(sGameModes));
  162. if( strcmp(sGameModes, "") )
  163. {
  164. Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
  165. if( StrContains(sGameModes, sGameMode, false) == -1 )
  166. return false;
  167. }
  168.  
  169. g_hCvarModesOff.GetString(sGameModes, sizeof(sGameModes));
  170. if( strcmp(sGameModes, "") )
  171. {
  172. Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
  173. if( StrContains(sGameModes, sGameMode, false) != -1 )
  174. return false;
  175. }
  176.  
  177. return true;
  178. }
  179.  
  180. public void OnGamemode(const char[] output, int caller, int activator, float delay)
  181. {
  182. if( strcmp(output, "OnCoop") == 0 )
  183. g_iCurrentMode = 1;
  184. else if( strcmp(output, "OnSurvival") == 0 )
  185. g_iCurrentMode = 2;
  186. else if( strcmp(output, "OnVersus") == 0 )
  187. g_iCurrentMode = 4;
  188. else if( strcmp(output, "OnScavenge") == 0 )
  189. g_iCurrentMode = 8;
  190. }
  191.  
  192.  
  193.  
  194. // ====================================================================================================
  195. // EVENTS
  196. // ====================================================================================================
  197. public void Event_PlayerShoved(Event event, const char[] name, bool dontBroadcast)
  198. {
  199. int client = GetClientOfUserId(event.GetInt("attacker"));
  200. int userid = event.GetInt("userid");
  201. int target = GetClientOfUserId(userid);
  202.  
  203. if( GetClientTeam(client) == 2 && GetClientTeam(target) == 2 )
  204. {
  205. float vPos[3];
  206. GetClientAbsOrigin(client, vPos);
  207.  
  208. if( g_bLeft4Dead2 )
  209. StaggerClient(userid, vPos);
  210. else
  211. SDKCall(g_hConfStagger, target, target, vPos); // Stagger: SDKCall method
  212. }
  213. }
  214.  
  215. // Credit to Timocop on VScript function
  216. void StaggerClient(int userid, const float vPos[3])
  217. {
  218. static int iScriptLogic = INVALID_ENT_REFERENCE;
  219. if(iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic))
  220. {
  221. iScriptLogic = EntIndexToEntRef(CreateEntityByName("logic_script"));
  222. if(iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic))
  223. LogError("Could not create 'logic_script");
  224.  
  225. DispatchSpawn(iScriptLogic);
  226. }
  227.  
  228. char sBuffer[96];
  229. Format(sBuffer, sizeof(sBuffer), "GetPlayerFromUserID(%d).Stagger(Vector(%d,%d,%d))", userid, RoundFloat(vPos[0]), RoundFloat(vPos[1]), RoundFloat(vPos[2]));
  230. SetVariantString(sBuffer);
  231. AcceptEntityInput(iScriptLogic, "RunScriptCode");
  232. AcceptEntityInput(iScriptLogic, "Kill");
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement