Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.18 KB | None | 0 0
  1. /*
  2. * MyJailbreak - Warden - Friendly Fire Module.
  3. * by: shanapu
  4. * https://github.com/shanapu/MyJailbreak/
  5. *
  6. * Copyright (C) 2016-2017 Thomas Schmidt (shanapu)
  7. *
  8. * This file is part of the MyJailbreak SourceMod Plugin.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License, version 3.0, as published by the
  12. * Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22.  
  23. /******************************************************************************
  24. STARTUP
  25. ******************************************************************************/
  26.  
  27. // Includes
  28. #include <sourcemod>
  29. #include <sdktools>
  30. #include <sdkhooks>
  31. #include <cstrike>
  32. #include <colors>
  33. #include <autoexecconfig>
  34. #include <warden>
  35. #include <myjbwarden>
  36. #include <mystocks>
  37.  
  38. // Compiler Options
  39. #pragma semicolon 1
  40. #pragma newdecls required
  41.  
  42. // Console Variables
  43. ConVar gc_bFF;
  44. ConVar gc_bFFDeputy;
  45. ConVar gc_sCustomCommandFF;
  46. ConVar gc_sFFCT;
  47.  
  48. // Extern Convars
  49. ConVar g_bFF;
  50. ConVar Cvar_tg_team_none_attack;
  51. ConVar Cvar_tg_cvar_friendlyfire;
  52. ConVar Cvar_tg_ct_friendlyfire;
  53.  
  54. //Integer
  55. int OldCvar_tg_team_none_attack;
  56. int OldCvar_tg_cvar_friendlyfire;
  57. int OldCvar_tg_ct_friendlyfire;
  58.  
  59. // Start
  60. public void FriendlyFire_OnPluginStart()
  61. {
  62. // Client commands
  63. RegConsoleCmd("sm_setff", Command_FriendlyFire, "Allows player to see the state and the Warden to toggle friendly fire");
  64.  
  65. // AutoExecConfig
  66. gc_bFF = AutoExecConfig_CreateConVar("sm_warden_ff", "1", "0 - disabled, 1 - enable switch ff for the warden", _, true, 0.0, true, 1.0);
  67. gc_sFFCT = AutoExecConfig_CreateConVar("sm_warden_ff_ct_enable", "0", "0 - disabled, 1 - enable ff for cts also", _, true, 0.0, true, 1.0);
  68. gc_bFFDeputy = AutoExecConfig_CreateConVar("sm_warden_ff_deputy", "1", "0 - disabled, 1 - enable switch ff for the deputy, too", _, true, 0.0, true, 1.0);
  69. gc_sCustomCommandFF = AutoExecConfig_CreateConVar("sm_warden_cmds_ff", "isff, friendlyfire", "Set your custom chat commands for set/see friendly fire(!ff is reservered)(!setff (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands)");
  70.  
  71. // Hooks
  72. HookEvent("round_end", FriendlyFire_Event_RoundEnd);
  73. HookEvent("player_death", FriendlyFire_Event_PlayerDeath);
  74.  
  75. // FindConVar
  76. g_bFF = FindConVar("mp_teammates_are_enemies");
  77. }
  78.  
  79. /******************************************************************************
  80. COMMANDS
  81. ******************************************************************************/
  82.  
  83. public Action Command_FriendlyFire(int client, int args)
  84. {
  85. if (gc_bFF.BoolValue)
  86. {
  87. if (g_bFF.BoolValue)
  88. {
  89. if (IsClientWarden(client) || (IsClientDeputy(client) && gc_bFFDeputy.BoolValue))
  90. {
  91. SetCvar("mp_teammates_are_enemies", 0);
  92. g_bFF = FindConVar("mp_teammates_are_enemies");
  93. CPrintToChatAll("%s %t", g_sPrefix, "warden_ffisoff");
  94.  
  95. if (Cvar_tg_team_none_attack != null)
  96. {
  97. // Replace the Cvar Value with old value
  98. Cvar_tg_team_none_attack.IntValue = OldCvar_tg_team_none_attack;
  99. Cvar_tg_cvar_friendlyfire.IntValue = OldCvar_tg_cvar_friendlyfire;
  100. Cvar_tg_ct_friendlyfire.IntValue = OldCvar_tg_ct_friendlyfire;
  101. }
  102. }
  103. else CPrintToChatAll("%s %t", g_sPrefix, "warden_ffison");
  104. }
  105. else
  106. {
  107. if (IsClientWarden(client) || (IsClientDeputy(client) && gc_bFFDeputy.BoolValue))
  108. {
  109. SetCvar("mp_teammates_are_enemies", 1);
  110. g_bFF = FindConVar("mp_teammates_are_enemies");
  111. CPrintToChatAll("%s %t", g_sPrefix, "warden_ffison");
  112.  
  113. if (Cvar_tg_team_none_attack != null)
  114. {
  115. Cvar_tg_team_none_attack.IntValue = 1;
  116. Cvar_tg_cvar_friendlyfire.IntValue = 1;
  117. Cvar_tg_ct_friendlyfire.IntValue = 1;
  118. }
  119. }
  120. else CPrintToChatAll("%s %t", g_sPrefix, "warden_ffisoff");
  121. }
  122. }
  123.  
  124. return Plugin_Handled;
  125. }
  126.  
  127. /******************************************************************************
  128. EVENTS
  129. ******************************************************************************/
  130.  
  131.  
  132. public void FriendlyFire_Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
  133. {
  134. if (!gc_bPlugin.BoolValue || !g_bEnabled)
  135. return;
  136.  
  137. if (!g_bFF.BoolValue)
  138. return;
  139.  
  140. if (GetAlivePlayersCount(CS_TEAM_T) < 1)
  141. {
  142. SetCvar("mp_teammates_are_enemies", 0);
  143. CS_TerminateRound(5.0, CSRoundEnd_CTWin, false);
  144. }
  145. }
  146.  
  147. public void FriendlyFire_Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  148. {
  149. if (!gc_bPlugin.BoolValue || !g_bEnabled)
  150. return;
  151.  
  152. if (!g_bFF.BoolValue)
  153. return;
  154.  
  155. SetCvar("mp_teammates_are_enemies", 0);
  156. g_bFF = FindConVar("mp_teammates_are_enemies");
  157. CPrintToChatAll("%s %t", g_sPrefix, "warden_ffisoff");
  158.  
  159. if (Cvar_tg_team_none_attack != null)
  160. {
  161. // Replace the Cvar Value with old value
  162. Cvar_tg_team_none_attack.IntValue = OldCvar_tg_team_none_attack;
  163. Cvar_tg_cvar_friendlyfire.IntValue = OldCvar_tg_cvar_friendlyfire;
  164. Cvar_tg_ct_friendlyfire.IntValue = OldCvar_tg_ct_friendlyfire;
  165. }
  166. }
  167.  
  168. public Action FriendlyFire_OnTraceAttack(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
  169. {
  170. if (gc_sFFCT.BoolValue)
  171. return Plugin_Continue;
  172.  
  173. if (gp_bMyJailBreak && MyJailbreak_IsEventDayRunning())
  174. return Plugin_Continue;
  175.  
  176. if (!IsValidClient(victim, true, false) || !IsValidClient(attacker, true, false))
  177. {
  178. return Plugin_Continue;
  179. }
  180.  
  181. if ((victim != attacker) && ((GetClientTeam(victim) == GetClientTeam(attacker)) && (GetClientTeam(victim) == CS_TEAM_CT)))
  182. {
  183. return Plugin_Handled;
  184. }
  185.  
  186. return Plugin_Continue;
  187. }
  188.  
  189. /******************************************************************************
  190. FORWARDS LISTENING
  191. ******************************************************************************/
  192.  
  193. public void FriendlyFire_OnConfigsExecuted()
  194. {
  195. // Get the Cvar Value
  196. Cvar_tg_team_none_attack = FindConVar("tg_team_none_attack");
  197. Cvar_tg_cvar_friendlyfire = FindConVar("tg_cvar_friendlyfire");
  198. Cvar_tg_ct_friendlyfire = FindConVar("tg_ct_friendlyfire");
  199.  
  200. // Set custom Commands
  201. int iCount = 0;
  202. char sCommands[128], sCommandsL[12][32], sCommand[32];
  203.  
  204. // Friendly fire
  205. gc_sCustomCommandFF.GetString(sCommands, sizeof(sCommands));
  206. ReplaceString(sCommands, sizeof(sCommands), " ", "");
  207. iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  208.  
  209. for (int i = 0; i < iCount; i++)
  210. {
  211. Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  212. if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS) // if command not already exist
  213. RegConsoleCmd(sCommand, Command_FriendlyFire, "Allows player to see the state and the Warden to toggle friendly fire");
  214. }
  215. }
  216.  
  217. public void FriendlyFire_OnClientPutInServer(int client)
  218. {
  219. SDKHook(client, SDKHook_TraceAttack, FriendlyFire_OnTraceAttack);
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement