Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.37 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include "colors_csgo.inc"
  4.  
  5. #pragma newdecls required
  6. #define PLUGIN_VERSION "1.00"
  7.  
  8. /*
  9. * Plugin Information - Please do not change this
  10. */
  11. public Plugin myinfo =
  12. {
  13. name = "Easy Spawn Protection",
  14. author = "Invex | Byte, based on work of cREANy0 and Fredd",
  15. description = "Easy to use spawn protection plugin.",
  16. version = PLUGIN_VERSION,
  17. url = "http://www.invexgaming.com.au"
  18. }
  19.  
  20. bool isEnabled;
  21. bool inRoundStartProtectionTime = false;
  22. float roundStartTime = 0.0;
  23. float freezeTime = 0.0;
  24. char PREFIX[] = "[{purple}EasySpawnProtection{default}] ";
  25. #define MODE_PLAYERSPAWN 0
  26. #define MODE_ROUNDSTART 1
  27. #define COLOUR_OFF 0
  28. #define COLOUR_ALL 1
  29. #define COLOUR_TEAMS 2
  30.  
  31. //Mod information
  32. #define teamOne 2 //CS:S T, CS:GO T, TF2 RED, L4D survivor
  33. #define teamTwo 3 //CS:S CT, CS:GO CT, TF2 BLU, L4D infected
  34. int teamSpectator;
  35. int teamTeamless;
  36. bool hasTeams = true;
  37.  
  38.  
  39. //Handles
  40. Handle g_easysp_enabled = null;
  41. Handle g_easysp_time = null;
  42. Handle g_easysp_mode = null;
  43. Handle g_easysp_endOnAttackMode = null;
  44. Handle g_easysp_notify_start = null;
  45. Handle g_easysp_notify_end = null;
  46. Handle g_easysp_rgbcolour_mode = null;
  47. Handle g_easysp_rgbcolour_all = null;
  48. Handle g_easysp_rgbcolour_teamOne = null;
  49. Handle g_easysp_rgbcolour_teamTwo = null;
  50. Handle g_easysp_sponbotcontrol = null;
  51.  
  52. //Props
  53. int g_renderOffs = -1;
  54. int g_bIsControllingBot = -1;
  55.  
  56. enum FX
  57. {
  58. FxNone = 0,
  59. FxPulseFast,
  60. FxPulseSlowWide,
  61. FxPulseFastWide,
  62. FxFadeSlow,
  63. FxFadeFast,
  64. FxSolidSlow,
  65. FxSolidFast,
  66. FxStrobeSlow,
  67. FxStrobeFast,
  68. FxStrobeFaster,
  69. FxFlickerSlow,
  70. FxFlickerFast,
  71. FxNoDissipation,
  72. FxDistort, // Distort/scale/translate flicker
  73. FxHologram, // kRenderFxDistort + distance fade
  74. FxExplode, // Scale up really big!
  75. FxGlowShell, // Glowing Shell
  76. FxClampMinScale, // Keep this sprite from getting very small (SPRITES only!)
  77. FxEnvRain, // for environmental rendermode, make rain
  78. FxEnvSnow, // " " " , make snow
  79. FxSpotlight,
  80. FxRagdoll,
  81. FxPulseFastWider,
  82. };
  83.  
  84. enum Render
  85. {
  86. Normal = 0, // src
  87. TransColor, // c*a+dest*(1-a)
  88. TransTexture, // src*a+dest*(1-a)
  89. Glow, // src*a+dest -- No Z buffer checks -- Fixed size in screen space
  90. TransAlpha, // src*srca+dest*(1-srca)
  91. TransAdd, // src*a+dest
  92. Environmental, // not drawn, used for environmental effects
  93. TransAddFrameBlend, // use a fractional frame value to blend between animation frames
  94. TransAlphaAdd, // src + dest*(1-a)
  95. WorldGlow, // Same as kRenderGlow but not fixed size in screen space
  96. None, // Don't render.
  97. };
  98.  
  99. public void OnPluginStart()
  100. {
  101. //Load translation
  102. LoadTranslations("EasySpawnProtection.phrases");
  103.  
  104. //ConVar List
  105. CreateConVar("sm_easysp_version", PLUGIN_VERSION, "Version of 'Easy Spawn Protection' plugin", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_CHEAT|FCVAR_DONTRECORD);
  106. g_easysp_enabled = CreateConVar("sm_easysp_enabled", "1", "Enable Easy Spawn Protection Plugin (0 off, 1 on, def. 1)");
  107. g_easysp_mode = CreateConVar("sm_easysp_mode", "0", "The mode of operation. (0 spawn protection when player is spawned, 1 spawn protection for set time from round start, def. 0");
  108. g_easysp_time = CreateConVar("sm_easysp_time", "5.0", "Duration of spawn protection. (min. 0.0, def. 5.0)");
  109. g_easysp_notify_start = CreateConVar("sm_easysp_notify_start", "1", "Let users know that they have gained spawn protection. (0 off, 1 on, def. 1)");
  110. g_easysp_notify_end = CreateConVar("sm_easysp_notify_end", "1", "Let users know that they have lost spawn protection. (0 off, 1 on, def. 1)");
  111. g_easysp_rgbcolour_mode = CreateConVar("sm_easysp_colour_mode", "1", "Colour highlighting mode to use. (0 off, 1 highlight all player same colour, 2 use different colours for teamOne/teamTwo, def. 1)");
  112. g_easysp_rgbcolour_all = CreateConVar("sm_easysp_colour", "0 255 0 120", "Set spawn protection model highlighting colour. <RED> <GREEN> <BLUE> <OPACITY>. (def. \"0 255 0 120\")");
  113. g_easysp_rgbcolour_teamOne = CreateConVar("sm_easysp_colour_teamOne", "0 255 0 120", "Set spawn protection model highlighting colour for team One (CS:S T, CS:GO T, TF2 RED, L4D Survivor). <RED> <GREEN> <BLUE> <OPACITY>. (def. \"0 255 0 120\")");
  114. g_easysp_rgbcolour_teamTwo = CreateConVar("sm_easysp_colour_teamTwo", "0 255 0 120", "Set spawn protection model highlighting colour for team Two (CS:S CT, CS:GO CT, TF2 BLU, L4D Infected). <RED> <GREEN> <BLUE> <OPACITY>. (def. \"0 255 0 120\")");
  115. g_easysp_endOnAttackMode = CreateConVar("sm_easysp_endonattack_mode", "0", "Specifies if spawn protection should end if player attacks. (0 off, 1 turn off SP as soon as player shots or fire any weapon, def. 0)");
  116. g_easysp_sponbotcontrol = CreateConVar("sm_easysp_sponbotcontrol", "1", "Should bots receive spawn protection if another player takes control of them. (0 off, 1 on, def. 1)");
  117.  
  118. //Event hooks
  119. HookEvent("player_spawn", Event_OnPlayerSpawn);
  120. HookEvent("round_prestart", Event_RoundPreStart);
  121. HookEvent("round_start", Event_RoundStart);
  122. HookEvent("weapon_fire", Event_WeaponFire);
  123.  
  124. //Enable status hook
  125. HookConVarChange(g_easysp_enabled, ConVarChange_enabled);
  126.  
  127. //Find some props
  128. g_renderOffs = FindSendPropOffs("CBasePlayer", "m_clrRender");
  129. g_bIsControllingBot = FindSendPropInfo("CCSPlayer", "m_bIsControllingBot");
  130.  
  131. //Detect mod
  132. char modName[21];
  133. GetGameFolderName(modName, sizeof(modName));
  134.  
  135. if(StrEqual(modName, "cstrike", false) || StrEqual(modName, "dod", false) || StrEqual(modName, "csgo", false) || StrEqual(modName, "tf", false)) {
  136. teamSpectator = 1;
  137. teamTeamless = 0;
  138. hasTeams = true;
  139. }
  140. else if(StrEqual(modName, "Insurgency", false)) {
  141. teamSpectator = 3;
  142. teamTeamless = 0;
  143. hasTeams = true;
  144. }
  145. else if(StrEqual(modName, "hl2mp", false)) {
  146. hasTeams = false;
  147. }
  148. else {
  149. SetFailState("%s is an unsupported mod", modName);
  150. }
  151.  
  152. //Set Variable Values
  153. isEnabled = true;
  154.  
  155. //AutoExecConfig
  156. AutoExecConfig(true, "easyspawnprotection");
  157. }
  158.  
  159. /*
  160. * If enable convar is changed, use this to turn the plugin off or on
  161. */
  162. public void ConVarChange_enabled(Handle convar, const char[] oldValue, const char[] newValue)
  163. {
  164. isEnabled = view_as<bool>(StringToInt(newValue));
  165. }
  166.  
  167. /*
  168. * Round Pre Start
  169. * We need this to set round start time before player spawns
  170. */
  171. public Action Event_RoundPreStart(Handle event, const char[] name, bool dontBroadcast)
  172. {
  173. if (!isEnabled)
  174. return Plugin_Continue;
  175.  
  176. //Record round start time
  177. roundStartTime = GetGameTime();
  178.  
  179. //Get MP freeze time
  180. Handle mp_freezetime = FindConVar("mp_freezetime");
  181. if (mp_freezetime != null) {
  182. freezeTime = GetConVarFloat(mp_freezetime);
  183. }
  184.  
  185. return Plugin_Continue;
  186. }
  187.  
  188. /*
  189. * Round Start
  190. */
  191. public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
  192. {
  193. if (!isEnabled)
  194. return Plugin_Continue;
  195.  
  196. //Check if mode is correct, otherwise return
  197. if (GetConVarInt(g_easysp_mode) != MODE_ROUNDSTART)
  198. return Plugin_Continue;
  199.  
  200. //Mode is fixed time mode, give sp to all players
  201. int iMaxClients = GetMaxClients();
  202. float sptime = GetConVarFloat(g_easysp_time);
  203.  
  204. for (int i = 1; i <= iMaxClients; ++i)
  205. {
  206. //Ignore players not here or dead players
  207. if(!IsClientInGame(i) || !IsPlayerAlive(i))
  208. continue;
  209.  
  210. //If client is on spectator or is teamless, ignore them
  211. int iTeam = GetClientTeam(i);
  212. if (hasTeams && (iTeam == teamSpectator || iTeam == teamTeamless))
  213. continue;
  214.  
  215. //Set spawn protection
  216. GiveSpawnProtection(i);
  217.  
  218. //Check if we should notify player of spawn protection
  219. if(GetConVarBool(g_easysp_notify_start))
  220. CPrintToChat(i, "%s%t", PREFIX, "Spawn Protection Start", RoundToNearest(sptime));
  221. }
  222.  
  223. //Now we must set up a timer to globally disable spawn protection for all
  224. CreateTimer(sptime + freezeTime, RemoveAllProtection);
  225. inRoundStartProtectionTime = true;
  226.  
  227. return Plugin_Continue;
  228. }
  229.  
  230. /*
  231. * OnPlayerSpawn
  232. */
  233. public Action Event_OnPlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
  234. {
  235. if (!isEnabled)
  236. return Plugin_Continue;
  237.  
  238. int client = GetClientOfUserId(GetEventInt(event, "userid"));
  239. int clientTeam = GetClientTeam(client);
  240.  
  241. //Ignore dead players
  242. if(!IsPlayerAlive(client))
  243. return Plugin_Continue;
  244.  
  245. //If player controlling a bot and we do not want sp on bot control, then return
  246. if (!GetConVarBool(g_easysp_sponbotcontrol) && IsPlayerControllingBot(client))
  247. return Plugin_Continue;
  248.  
  249. //If client is on spectator or is teamless, ignore them
  250. if (hasTeams && (clientTeam == teamSpectator || clientTeam == teamTeamless))
  251. return Plugin_Continue;
  252.  
  253. //Check if mode is correct, otherwise return
  254. //However, if still in spawn protection time, allow spawn protecting this client
  255. if (!inRoundStartProtectionTime && GetConVarInt(g_easysp_mode) != MODE_PLAYERSPAWN)
  256. return Plugin_Continue;
  257.  
  258. //Set spawn protection
  259. GiveSpawnProtection(client);
  260.  
  261. //Check if we should notify player of spawn protection
  262. if(GetConVarBool(g_easysp_notify_start)) {
  263. float sptime = GetConVarFloat(g_easysp_time);
  264.  
  265. if (inRoundStartProtectionTime && GetConVarInt(g_easysp_mode) != MODE_PLAYERSPAWN)
  266. PrintHintText(client, "%s%t", PREFIX, "<span style='color:green;'>Spawn Protection Start</span>",RoundToNearest(sptime - (GetGameTime() - roundStartTime) + freezeTime));
  267. else
  268. PrintHintText(client, "%s%t", PREFIX, "<span style='color:red;'>Spawn Protection Start</span>", RoundToNearest(sptime));
  269. }
  270.  
  271. return Plugin_Continue;
  272. }
  273.  
  274. /*
  275. * Give spawn protection to given player and colours them
  276. */
  277. void GiveSpawnProtection(int client)
  278. {
  279. //Get Colour Highlight information
  280. int colourMode = GetConVarInt(g_easysp_rgbcolour_mode);
  281. int clientTeam = GetClientTeam(client);
  282.  
  283. if (colourMode != COLOUR_OFF) {
  284. //We need to apply colour
  285. char SzColor[32];
  286. char Colours[4][4];
  287.  
  288. if (colourMode == COLOUR_ALL) {
  289. //Use one colour for all
  290. GetConVarString(g_easysp_rgbcolour_all, SzColor, sizeof(SzColor));
  291. }
  292. else if (colourMode == COLOUR_TEAMS) {
  293. //Different colour for team one and team two
  294. if (clientTeam == teamOne) {
  295. GetConVarString(g_easysp_rgbcolour_teamOne, SzColor, sizeof(SzColor));
  296. }
  297. else if (clientTeam == teamTwo) {
  298. GetConVarString(g_easysp_rgbcolour_teamTwo, SzColor, sizeof(SzColor));
  299. }
  300. }
  301.  
  302. //Set Colour
  303. ExplodeString(SzColor, " ", Colours, 4, 4);
  304. set_rendering(client, view_as<FX>(FxDistort), StringToInt(Colours[0]),StringToInt(Colours[1]),StringToInt(Colours[2]), view_as<Render>(RENDER_TRANSADD), StringToInt(Colours[3]));
  305. }
  306.  
  307. //Set god mode to player
  308. SetEntProp(client, Prop_Data, "m_takedamage", 0, 1);
  309.  
  310. //Organise time to reset the god mode
  311. float sptime = GetConVarFloat(g_easysp_time);
  312.  
  313. //Set a timer to reset spawn protection only if this is player spawn mode
  314. if (GetConVarInt(g_easysp_mode) == MODE_PLAYERSPAWN) {
  315. //Check if freeze time will affect this respawn
  316. float extraTime = 0.0;
  317.  
  318. //If this spawn is occuring during spawn time
  319. if (freezeTime > 0.0 && (GetGameTime() - roundStartTime <= freezeTime)) {
  320. extraTime = freezeTime - (GetGameTime() - roundStartTime);
  321. }
  322.  
  323. CreateTimer(sptime + extraTime, RemoveProtection, client);
  324. }
  325. }
  326.  
  327. /*
  328. * Timer used to remove protection
  329. */
  330. public Action RemoveProtection(Handle timer, any client)
  331. {
  332. //Check if this player currently has god mode (aka spawn protection)
  333. if(IsClientInGame(client) && IsClientSpawnProtected(client)) {
  334. SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
  335. set_rendering(client); //reset rendering
  336.  
  337. if(GetConVarBool(g_easysp_notify_end) && IsPlayerAlive(client))
  338. CPrintToChat(client, "%s%t", PREFIX, "Spawn Protection End Normal");
  339. }
  340. }
  341.  
  342. /*
  343. * Timer used to remove protection from all players
  344. */
  345. public Action RemoveAllProtection(Handle timer)
  346. {
  347. inRoundStartProtectionTime = false;
  348.  
  349. int iMaxClients = GetMaxClients();
  350.  
  351. for (int i = 1; i <= iMaxClients; ++i)
  352. {
  353. //Check if this player currently has god mode (aka spawn protection)
  354. if(IsClientInGame(i) && IsClientSpawnProtected(i)) {
  355. SetEntProp(i, Prop_Data, "m_takedamage", 2, 1);
  356. set_rendering(i); //reset rendering
  357.  
  358. if(GetConVarBool(g_easysp_notify_end) && IsPlayerAlive(i))
  359. CPrintToChat(i, "%s%t", PREFIX, "Spawn Protection End Normal");
  360. }
  361. }
  362. }
  363.  
  364. /*
  365. * Weapon Fire
  366. */
  367. public Action Event_WeaponFire(Handle event, const char[] name, bool dontBroadcast)
  368. {
  369. if (!isEnabled)
  370. return Plugin_Continue;
  371.  
  372. //Return if option is disabled
  373. if (!GetConVarBool(g_easysp_endOnAttackMode))
  374. return Plugin_Continue;
  375.  
  376. //Get client who fired
  377. int client = GetClientOfUserId(GetEventInt(event, "userid"));
  378.  
  379. //Check if this player currently has god mode (aka spawn protection)
  380. if (IsClientSpawnProtected(client)) {
  381. SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
  382. set_rendering(client); //reset rendering
  383.  
  384. if(GetConVarBool(g_easysp_notify_end) && IsPlayerAlive(client))
  385. CPrintToChat(client, "%s%t", PREFIX, "Spawn Protection End Attack");
  386. }
  387.  
  388. return Plugin_Continue;
  389. }
  390.  
  391. /*
  392. * Function to set player rendering (colour highlighting)
  393. */
  394. stock void set_rendering(int index, FX fx=FxNone, int r=255, int g=255, int b=255, Render render=Normal, int amount=255)
  395. {
  396. SetEntProp(index, Prop_Send, "m_nRenderFX", fx, 1);
  397. SetEntProp(index, Prop_Send, "m_nRenderMode", render, 1);
  398. SetEntData(index, g_renderOffs, r, 1, true);
  399. SetEntData(index, g_renderOffs + 1, g, 1, true);
  400. SetEntData(index, g_renderOffs + 2, b, 1, true);
  401. SetEntData(index, g_renderOffs + 3, amount, 1, true);
  402. }
  403.  
  404. /*
  405. * Check if a player is controlling a bot
  406. * Credit: TnTSCS
  407. * Url: https://forums.alliedmods.net/showthread.php?t=188807&page=13
  408. */
  409. bool IsPlayerControllingBot(int client)
  410. {
  411. return view_as<bool>(GetEntData(client, g_bIsControllingBot, 1));
  412. }
  413.  
  414. /*
  415. * Public function to check if player has spawn protection
  416. */
  417. public bool IsClientSpawnProtected(int client)
  418. {
  419. return (GetEntProp(client, Prop_Data, "m_takedamage") == 0);
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement