Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3. #include <cstrike>
  4.  
  5. #include <lastrequest>
  6.  
  7. #pragma semicolon 1
  8.  
  9. #define PLUGIN_VERSION "1.5"
  10.  
  11. new Handle:gH_Enabled = INVALID_HANDLE;
  12.  
  13. new bool:gB_Enabled;
  14. new bool:gB_Boxing;
  15.  
  16. new gI_LastUsed[MAXPLAYERS + 1];
  17.  
  18. new Handle:gH_Cvars[7] = { INVALID_HANDLE, ... };
  19.  
  20. public Plugin:myinfo =
  21. {
  22. name = "Jailbreak Box",
  23. author = "ExTacY",
  24. description = "!Box will enable box",
  25. version = ""
  26. }
  27.  
  28. public OnPluginStart()
  29. {
  30. CreateConVar("sm_box_version", PLUGIN_VERSION, "Jailbreak Box version", FCVAR_PLUGIN | FCVAR_DONTRECORD | FCVAR_NOTIFY);
  31.  
  32. gH_Enabled = CreateConVar("sm_box_enabled", "1", "Enable this plugin functionality?", FCVAR_PLUGIN);
  33. gB_Enabled = true;
  34. HookConVarChange(gH_Enabled, OnConvarChanged);
  35.  
  36. HookEvent("round_end", Round_End);
  37. RegConsoleCmd("sm_box", Command_Box, "Toggle Jailbreak Box status, available for admins/CTs.");
  38.  
  39. AutoExecConfig(true, "jailbreakbox");
  40.  
  41. gH_Cvars[0] = FindConVar("ff_damage_reduction_bullets");
  42. gH_Cvars[1] = FindConVar("ff_damage_reduction_grenade");
  43. gH_Cvars[2] = FindConVar("ff_damage_reduction_grenade_self");
  44. gH_Cvars[3] = FindConVar("ff_damage_reduction_other");
  45. gH_Cvars[4] = FindConVar("mp_friendlyfire");
  46. gH_Cvars[5] = FindConVar("mp_autokick");
  47. gH_Cvars[6] = FindConVar("mp_tkpunish");
  48. }
  49.  
  50. public OnAvailableLR(Announced)
  51. {
  52. if (gB_Boxing)
  53. {
  54. gB_Boxing = false;
  55.  
  56. for (new i; i <= MaxClients; i++)
  57. {
  58. if (IsValidClient(i))
  59. {
  60. PrintToConsole(i, "Jailbreak Box has automatically disabled due to an LR.");
  61. }
  62. }
  63. }
  64.  
  65. if (gB_Enabled)
  66. {
  67. Disable();
  68. }
  69. }
  70.  
  71. public OnConvarChanged(Handle:cvar, const String:oldVal[], const String:newVal[])
  72. {
  73. if (cvar == gH_Enabled)
  74. {
  75. gB_Enabled = bool:StringToInt(newVal);
  76. }
  77. }
  78.  
  79. public OnClientPutInServer(client)
  80. {
  81. SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
  82. gI_LastUsed[client] = 0;
  83. }
  84.  
  85. public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
  86. {
  87. if (gB_Enabled && gB_Boxing)
  88. {
  89. if (IsValidClient(attacker) && IsValidClient(victim, true))
  90. {
  91. if (attacker != victim && GetClientTeam(attacker) == 3 && GetClientTeam(victim) == 3)
  92. {
  93. damage = 0.0;
  94.  
  95. return Plugin_Changed;
  96. }
  97. }
  98. }
  99.  
  100. return Plugin_Continue;
  101. }
  102.  
  103. public Action:Round_End(Handle:event, const String:name[], bool:dB)
  104. {
  105. gB_Boxing = false;
  106.  
  107. if (gB_Enabled)
  108. {
  109. Disable();
  110. }
  111.  
  112. return Plugin_Continue;
  113. }
  114.  
  115. public Action:Command_Box(client, args)
  116. {
  117. if (!IsValidClient(client))
  118. {
  119. return Plugin_Handled;
  120. }
  121.  
  122. if (!HasAccess(client))
  123. {
  124. ReplyToCommand(client, "\x04[Box]\x01 This command is available for \x05admins \x01and \x05alive prison guards\x01.");
  125.  
  126. return Plugin_Handled;
  127. }
  128.  
  129. new Time = GetTime();
  130.  
  131. if (Time - gI_LastUsed[client] < 15)
  132. {
  133. ReplyToCommand(client, "\x04[Box]\x01 You can't spam this command, time left - \x05[%d/15]\x01.", Time - gI_LastUsed[client]);
  134.  
  135. return Plugin_Handled;
  136. }
  137.  
  138. gI_LastUsed[client] = Time;
  139.  
  140. new Handle:menu = CreateMenu(MenuHandler_Box, MENU_ACTIONS_ALL);
  141. SetMenuTitle(menu, "Jailbreak Box:");
  142.  
  143. AddMenuItem(menu, "on", "Enable");
  144. AddMenuItem(menu, "off", "Disable");
  145.  
  146. SetMenuExitButton(menu, true);
  147.  
  148. DisplayMenu(menu, client, 20);
  149.  
  150. return Plugin_Handled;
  151. }
  152.  
  153. public MenuHandler_Box(Handle:menu, MenuAction:action, param1, param2)
  154. {
  155. switch (action)
  156. {
  157. case MenuAction_Select:
  158. {
  159. if (!HasAccess(param1))
  160. {
  161. PrintToChat(param1, "\x04[Box]\x01 This command is available for \x05admins \x01and \x05alive prison guards\x01.");
  162.  
  163. return 0;
  164. }
  165.  
  166. char String:info[8];
  167. GetMenuItem(menu, param2, info, 8);
  168.  
  169. new bool:enabled = StrEqual(info, "on");
  170.  
  171. enabled ? Enable():Disable();
  172.  
  173. PrintToChatAll("\x04[Box]\x01 Jailbreak Box has been \x05%sabled\x01.", enabled ? "en":"dis");
  174.  
  175. case MenuAction_End:
  176. {
  177. CloseHandle(menu);
  178. }
  179. }
  180. }
  181.  
  182.  
  183.  
  184. return 0;
  185. }
  186.  
  187. void:Enable()
  188. {
  189. for (new i; i < sizeof(gH_Cvars); i++)
  190. {
  191. if (gH_Cvars[i] != INVALID_HANDLE)
  192. {
  193. SetConVarBool(gH_Cvars[i], (i <= 4) ? true:false);
  194. }
  195. }
  196. }
  197.  
  198. void:Disable()
  199. {
  200. for (new i; i < sizeof(gH_Cvars); i++)
  201. {
  202. if (gH_Cvars[i] != INVALID_HANDLE)
  203. {
  204. SetConVarBool(gH_Cvars[i], (i <= 4) ? false:true);
  205. }
  206. }
  207. }
  208.  
  209. stock bool:HasAccess(client)
  210. {
  211. if (CheckCommandAccess(client, "jailbreakbox", ADMFLAG_SLAY))
  212. {
  213. return true;
  214. }
  215.  
  216. if (GetClientTeam(client) == CS_TEAM_CT && IsPlayerAlive(client))
  217. {
  218. return true;
  219. }
  220.  
  221. return false;
  222. }
  223.  
  224. stock bool:IsValidClient(client, bool:alive = false)
  225. {
  226. if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)))
  227. {
  228. return true;
  229. }
  230.  
  231. return false;
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement