Guest User

Untitled

a guest
Apr 19th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.  *  [INS] Player Respawn Script - Player and BOT respawn script for sourcemod plugin.
  3.  * 
  4.  *  This program is free software: you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation, either version 3 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. #pragma dynamic 131072 // Increase heap size
  19. #pragma semicolon 1
  20. //#pragma newdecls required
  21. #include <sourcemod>
  22. #include <sdktools>
  23. #include <sdkhooks>
  24. #include <insurgencydy>
  25. #include <smlib>
  26. //#undef REQUIRE_EXTENSIONS
  27. //#include <cstrike>
  28. //#include <tf2>
  29. //#include <tf2_stocks>
  30. #define REQUIRE_EXTENSIONS
  31.  
  32. //Lua Healing Variables
  33. float g_iTimeCheckHeight[2048] = {0.0, ...};
  34.  
  35. // Handle for revive
  36. Handle g_hForceRespawn;
  37. Handle g_hGameConfig;
  38.  
  39. // AI Director Variables
  40. int g_AIDir_TeamStatus = 50;
  41. int g_AIDir_TeamStatus_min = 0;
  42. int g_AIDir_TeamStatus_max = 100;
  43. int g_AIDir_BotsKilledReq_mult = 4;
  44. int g_AIDir_BotsKilledCount = 0;
  45. int g_AIDir_AnnounceCounter = 0;
  46.     //g_AIDir_AnnounceTrig = 5,
  47. int g_AIDir_ChangeCond_Counter = 0;
  48. int g_AIDir_ChangeCond_Min = 60;
  49. int g_AIDir_ChangeCond_Max = 180;
  50. int g_AIDir_AmbushCond_Counter = 0;
  51. int g_AIDir_AmbushCond_Min = 120;
  52. int g_AIDir_AmbushCond_Max = 300;
  53. int g_AIDir_AmbushCond_Rand = 240;
  54. int g_AIDir_AmbushCond_Chance = 10;
  55. int g_AIDir_ChangeCond_Rand = 180;
  56. int g_AIDir_ReinforceTimer_Orig;
  57. int g_AIDir_ReinforceTimer_SubOrig;
  58.     //g_AIDir_CurrDiff = 0,
  59. int g_AIDir_DiffChanceBase = 0;
  60. bool g_AIDir_BotReinforceTriggered = false;
  61.  
  62. // Player respawn
  63. int g_iEnableRevive = 0;
  64. int g_GiveBonusLives = 0;
  65. int g_iRespawnTimeRemaining[MAXPLAYERS+1];
  66. int g_iReviveRemainingTime[MAXPLAYERS+1];
  67. int g_iReviveNonMedicRemainingTime[MAXPLAYERS+1];
  68. int g_iPlayerRespawnTimerActive[MAXPLAYERS+1];
  69. int g_iSpawnTokens[MAXPLAYERS+1];
  70. int g_iHurtFatal[MAXPLAYERS+1];
  71. int g_iClientRagdolls[MAXPLAYERS+1];
  72. int g_iNearestBody[MAXPLAYERS+1];
  73. int g_botStaticGlobal[MAXPLAYERS+1];
  74. int g_resupplyCounter[MAXPLAYERS+1];
  75. int g_ammoResupplyAmt[MAX_ENTITIES+1];
  76. int g_trackKillDeaths[MAXPLAYERS+1];
  77. float g_badSpawnPos_Track[MAXPLAYERS+1][3];
  78. int g_iRespawnCount[4];
  79.     // g_huntReinforceCacheAdd = 120,
  80.     // bool:g_huntCacheDestroyed = false,
  81. bool g_playersReady = false;
  82.     //bool:g_easterEggRound = false,
  83.     //bool:g_easterEggFlag = false,
  84. int g_removeBotGrenadeChance = 50;
  85.     // float g_fPlayerPosition[MAXPLAYERS+1][3],
  86. float g_fDeadPosition[MAXPLAYERS+1][3];
  87. float g_fRagdollPosition[MAXPLAYERS+1][3];
  88. float g_vecOrigin[MAXPLAYERS+1][3];
  89. int g_iPlayerBGroups[MAXPLAYERS+1];
  90. int g_spawnFrandom[MAXPLAYERS+1];
  91. int g_squadSpawnEnabled[MAXPLAYERS+1] = 0;
  92. int g_squadLeader[MAXPLAYERS+1];
  93.     // g_enemySpawnTimer[MAXPLAYERS+1],
  94. int g_LastButtons[MAXPLAYERS+1];
  95.     //g_extendMapVote[MAXPLAYERS+1] = 0,
  96. float g_fRespawnPosition[3];
  97.  
  98. //Ammo Amounts
  99. // Track primary and secondary ammo
  100. int playerClip[MAXPLAYERS + 1][2];
  101.     // track player ammo based on weapon slot 0 - 4
  102. int playerAmmo[MAXPLAYERS + 1][4];
  103. int playerPrimary[MAXPLAYERS + 1];
  104. int playerSecondary[MAXPLAYERS + 1];
  105. //  playerGrenadeType[MAXPLAYERS + 1][10], //track player grenade types
  106. //  playerRole[MAXPLAYERS + 1]; // tracks player role so if it changes while wounded, he dies
  107.  
  108. // Handle g_donorTagRemove_Array;
  109. ArrayList g_playerArrayList;
  110.  
  111. //Bot Spawning
  112. // ArrayList g_badSpawnPos_Array;
  113.  
  114. // Navmesh Init
  115. // Handle g_hHidingSpots = null,
  116. // g_iHidingSpotCount,
  117. // m_iNumControlPoints,
  118. // g_iCPHidingSpots[MAX_OBJECTIVES][MAX_HIDING_SPOTS],
  119. int g_iCPHidingSpotCount[MAX_OBJECTIVES];
  120. // g_iCPLastHidingSpot[MAX_OBJECTIVES],
  121. float m_vCPPositions[MAX_OBJECTIVES][3];
  122.  
  123. // Status
  124. int g_isMapInit;
  125.     //0 is over, 1 is active
  126. int g_iRoundStatus = 0;
  127. // bool:g_bIsCounterAttackTimerActive = false,
  128. int g_clientDamageDone[MAXPLAYERS+1];
  129. int playerPickSquad[MAXPLAYERS + 1];
  130. bool playerRevived[MAXPLAYERS + 1];
  131. bool playerInRevivedState[MAXPLAYERS + 1];
  132. bool g_preRoundInitial = false;
  133. char g_client_last_classstring[MAXPLAYERS+1][64];
  134. char g_client_org_nickname[MAXPLAYERS+1][64];
  135.     //float g_enemyTimerPos[MAXPLAYERS+1][3],   // Kill Stray Enemy Bots Globals
  136.     //float g_enemyTimerAwayPos[MAXPLAYERS+1][3],   // Kill Stray Enemy Bots Globals
  137. int g_playerActiveWeapon[MAXPLAYERS + 1];
  138. int g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
  139. int g_plyrFireScreamCoolDown[MAXPLAYERS+1];
  140. int g_playerMedicHealsAccumulated[MAXPLAYERS+1];
  141. int g_playerMedicRevivessAccumulated[MAXPLAYERS+1];
  142. int g_playerNonMedicHealsAccumulated[MAXPLAYERS+1];
  143. int g_playerNonMedicRevive[MAXPLAYERS+1];
  144. int g_playerWoundType[MAXPLAYERS+1];
  145. int g_playerWoundTime[MAXPLAYERS+1];
  146. //g_hintCoolDown[MAXPLAYERS+1] = 30,
  147. bool g_hintsEnabled[MAXPLAYERS+1] = true;
  148. float g_fPlayerLastChat[MAXPLAYERS+1] = {0.0, ...};
  149.  
  150.     //Wave Based Arrays
  151. //g_WaveSpawnActive[MAXPLAYERS+1],
  152.  
  153. int g_playerFirstJoin[MAXPLAYERS+1];
  154.  
  155. // Player Distance Plugin //Credits to author = "Popoklopsi", url = "http://popoklopsi.de"
  156. // unit to use 1 = feet, 0 = meters
  157. int g_iUnitMetric;
  158.  
  159. // Handle for config
  160. ConVar sm_respawn_enabled;
  161. ConVar sm_revive_enabled;
  162. //AI Director Specific
  163. ConVar sm_ai_director_setdiff_chance_base;
  164. // Respawn delay time
  165. ConVar sm_respawn_delay_team_ins;
  166. ConVar sm_respawn_delay_team_ins_special;
  167. ConVar sm_respawn_delay_team_sec;
  168. ConVar sm_respawn_delay_team_sec_player_count_01;
  169. ConVar sm_respawn_delay_team_sec_player_count_02;
  170. ConVar sm_respawn_delay_team_sec_player_count_03;
  171. ConVar sm_respawn_delay_team_sec_player_count_04;
  172. ConVar sm_respawn_delay_team_sec_player_count_05;
  173. ConVar sm_respawn_delay_team_sec_player_count_06;
  174. ConVar sm_respawn_delay_team_sec_player_count_07;
  175. ConVar sm_respawn_delay_team_sec_player_count_08;
  176. ConVar sm_respawn_delay_team_sec_player_count_09;
  177. ConVar sm_respawn_delay_team_sec_player_count_10;
  178. ConVar sm_respawn_delay_team_sec_player_count_11;
  179. ConVar sm_respawn_delay_team_sec_player_count_12;
  180. ConVar sm_respawn_delay_team_sec_player_count_13;
  181. ConVar sm_respawn_delay_team_sec_player_count_14;
  182. ConVar sm_respawn_delay_team_sec_player_count_15;
  183. ConVar sm_respawn_delay_team_sec_player_count_16;
  184. ConVar sm_respawn_delay_team_sec_player_count_17;
  185. ConVar sm_respawn_delay_team_sec_player_count_18;
  186. ConVar sm_respawn_delay_team_sec_player_count_19;
  187.    
  188.     // Respawn Mode (individual or wave based)
  189. ConVar sm_respawn_mode_team_sec;
  190. ConVar sm_respawn_mode_team_ins;
  191. //Wave interval
  192. //Handle sm_respawn_wave_int_team_sec = null,
  193. ConVar sm_respawn_wave_int_team_ins;
  194.  
  195. //VIP Cvars
  196. // Handle sm_vip_obj_time = null,
  197. // Handle sm_vip_min_sp_reward = null,
  198. // Handle sm_vip_max_sp_reward = null,
  199. // Handle sm_vip_enabled = null,
  200.  
  201.  
  202. // Respawn type
  203. ConVar sm_respawn_type_team_ins;
  204. ConVar sm_respawn_type_team_sec;
  205.  
  206. // Respawn lives
  207. ConVar sm_respawn_lives_team_sec;
  208. ConVar sm_respawn_lives_team_ins;
  209. ConVar sm_respawn_lives_team_ins_player_count_01;
  210. ConVar sm_respawn_lives_team_ins_player_count_02;
  211. ConVar sm_respawn_lives_team_ins_player_count_03;
  212. ConVar sm_respawn_lives_team_ins_player_count_04;
  213. ConVar sm_respawn_lives_team_ins_player_count_05;
  214. ConVar sm_respawn_lives_team_ins_player_count_06;
  215. ConVar sm_respawn_lives_team_ins_player_count_07;
  216. ConVar sm_respawn_lives_team_ins_player_count_08;
  217. ConVar sm_respawn_lives_team_ins_player_count_09;
  218. ConVar sm_respawn_lives_team_ins_player_count_10;
  219. ConVar sm_respawn_lives_team_ins_player_count_11;
  220. ConVar sm_respawn_lives_team_ins_player_count_12;
  221. ConVar sm_respawn_lives_team_ins_player_count_13;
  222. ConVar sm_respawn_lives_team_ins_player_count_14;
  223. ConVar sm_respawn_lives_team_ins_player_count_15;
  224. ConVar sm_respawn_lives_team_ins_player_count_16;
  225. ConVar sm_respawn_lives_team_ins_player_count_17;
  226. ConVar sm_respawn_lives_team_ins_player_count_18;
  227. ConVar sm_respawn_lives_team_ins_player_count_19;
  228.  
  229. // Fatal dead
  230. ConVar sm_respawn_fatal_chance;
  231. ConVar sm_respawn_fatal_head_chance;
  232. ConVar sm_respawn_fatal_limb_dmg;
  233. ConVar sm_respawn_fatal_head_dmg;
  234. ConVar sm_respawn_fatal_burn_dmg;
  235. ConVar sm_respawn_fatal_explosive_dmg;
  236. ConVar sm_respawn_fatal_chest_stomach;
  237.  
  238. // Counter-attack
  239. ConVar sm_respawn_counterattack_type;
  240. ConVar sm_respawn_counterattack_vanilla;
  241. ConVar sm_respawn_final_counterattack_type;
  242. ConVar sm_respawn_security_on_counter;
  243. ConVar sm_respawn_counter_chance;
  244. ConVar sm_respawn_min_counter_dur_sec;
  245. ConVar sm_respawn_max_counter_dur_sec;
  246. ConVar sm_respawn_final_counter_dur_sec;
  247.  
  248. //Dynamic Respawn Mechanics
  249. ConVar sm_respawn_dynamic_distance_multiplier;
  250. ConVar sm_respawn_dynamic_spawn_counter_percent;
  251. ConVar sm_respawn_dynamic_spawn_percent;
  252.  
  253. // Misc
  254. ConVar sm_respawn_reset_type;
  255. ConVar sm_respawn_enable_track_ammo;
  256.  
  257. // Reinforcements
  258. ConVar sm_respawn_reinforce_time;
  259. ConVar sm_respawn_reinforce_time_subsequent;
  260. ConVar sm_respawn_reinforce_multiplier;
  261. ConVar sm_respawn_reinforce_multiplier_base;
  262.  
  263. // Monitor static enemy
  264. //ConVar sm_respawn_check_static_enemy = null,
  265. //ConVar sm_respawn_check_static_enemy_counter = null,
  266.  
  267. // Donor tag
  268. ConVar sm_respawn_enable_donor_tag;
  269.  
  270. // Related to 'RoundEnd_Protector' plugin
  271. //ConVar sm_remaininglife = null,
  272.  
  273. // Medic specific
  274. ConVar sm_revive_seconds;
  275. //ConVar sm_revive_bonus = null,
  276. ConVar sm_revive_distance_metric;
  277. //ConVar sm_heal_bonus = null,
  278. ConVar sm_heal_cap_for_bonus;
  279. ConVar sm_revive_cap_for_bonus;
  280. ConVar sm_reward_medics_enabled;
  281. ConVar sm_heal_amount_medpack;
  282. ConVar sm_heal_amount_paddles;
  283. ConVar sm_non_medic_heal_amt;
  284. ConVar sm_non_medic_revive_hp;
  285. ConVar sm_medic_minor_revive_hp;
  286. ConVar sm_medic_moderate_revive_hp;
  287. ConVar sm_medic_critical_revive_hp;
  288. ConVar sm_minor_wound_dmg;
  289. ConVar sm_moderate_wound_dmg;
  290. ConVar sm_medic_heal_self_max;
  291. ConVar sm_non_medic_max_heal_other;
  292. ConVar sm_minor_revive_time;
  293. ConVar sm_moderate_revive_time;
  294. ConVar sm_critical_revive_time;
  295. ConVar sm_non_medic_revive_time;
  296. ConVar sm_medpack_health_amount;
  297. ConVar sm_multi_loadout_enabled;
  298. ConVar sm_bombers_only;
  299. ConVar sm_non_medic_heal_self_max;
  300. ConVar sm_elite_counter_attacks;
  301. ConVar sm_enable_bonus_lives;
  302. ConVar sm_finale_counter_spec_enabled;
  303. ConVar sm_finale_counter_spec_percent;
  304.  
  305. // NAV MESH SPECIFIC CVARS
  306. //1 = Spawn in ins_spawnpoints, 2 = any spawnpoints that meets criteria, 0 = only at normal spawnpoints at next objective
  307. ConVar cvarSpawnMode;
  308. //ConVar cvarMinCounterattackDistance = null, //Min distance from counterattack objective to spawn
  309. //Min/max distance from players to spawn
  310. ConVar cvarMinPlayerDistance;
  311. //Adds to the minplayerdistance cvar when spawning behind player.
  312. ConVar cvarBackSpawnIncrease;
  313. //Attack delay for spawning bots
  314. ConVar cvarSpawnAttackDelay;
  315. //Min/max distance from next objective to spawn
  316. ConVar cvarMinObjectiveDistance;
  317. //Min/max distance from next objective to spawn
  318. ConVar cvarMaxObjectiveDistance;
  319. //Min/max distance from next objective to spawn using nav
  320. ConVar cvarMaxObjectiveDistanceNav;
  321. //CanSeeVector Multiplier divide this by cvarMaxPlayerDistance
  322. ConVar cvarCanSeeVectorMultiplier;
  323. //Range of ammo resupply
  324. ConVar sm_ammo_resupply_range;
  325. //Delay to resupply
  326. ConVar sm_resupply_delay;
  327. //Jammer required for intel messages?
  328. ConVar sm_jammer_required;
  329. //Min/max distance from players to spawn
  330. ConVar cvarMaxPlayerDistance;
  331.    
  332.  
  333.  
  334. // Init global variables
  335. int g_iCvar_respawn_enable;
  336. int g_jammerRequired;
  337. int g_elite_counter_attacks;
  338. int g_finale_counter_spec_enabled;
  339. int g_finale_counter_spec_percent;
  340. int g_cqc_map_enabled;
  341.     // g_elitePeriod,
  342.     // g_elitePeriod_min,
  343.     // g_elitePeriod_max,
  344. int g_iCvar_revive_enable;
  345. float g_respawn_counter_chance;
  346. int g_counterAttack_min_dur_sec;
  347. int g_counterAttack_max_dur_sec;
  348. int g_iCvar_respawn_type_team_ins;
  349. int g_iCvar_respawn_type_team_sec;
  350. int g_iCvar_respawn_reset_type;
  351. float g_fCvar_respawn_delay_team_ins;
  352. float g_fCvar_respawn_delay_team_ins_spec;
  353. int g_iCvar_enable_track_ammo;
  354. int g_iCvar_counterattack_type;
  355. int g_iCvar_counterattack_vanilla;
  356. int g_iCvar_final_counterattack_type;
  357.     //g_iCvar_SpawnMode,
  358.  
  359.     //Dynamic Respawn cvars
  360. int g_DynamicRespawn_Distance_mult;
  361. int g_dynamicSpawnCounter_Perc;
  362. int g_dynamicSpawn_Perc;
  363.  
  364.     // Fatal dead
  365. float g_fCvar_fatal_chance;
  366. float g_fCvar_fatal_head_chance;
  367. int g_iCvar_fatal_limb_dmg;
  368. int g_iCvar_fatal_head_dmg;
  369. int g_iCvar_fatal_burn_dmg;
  370. int g_iCvar_fatal_explosive_dmg;
  371. int g_iCvar_fatal_chest_stomach;
  372.     //Dynamic Loadouts
  373.     //g_iCvar_bombers_only,
  374.     //g_iCvar_multi_loadout_enabled,
  375.  
  376.     //Respawn Mode (wave based)
  377. int g_respawn_mode_team_sec;
  378.     //g_respawn_mode_team_ins,
  379.     //g_respawn_wave_int_team_ins,
  380.  
  381.     //NEW Respawn system globals (temporary)
  382.     //Grab directly from theater (3 scouts, 5 jugs, 4 bombers, All others 20)
  383.     // g_maxbots_std = 0,
  384.     // g_maxbots_light = 0,
  385.     // g_maxbots_jug = 0,
  386.     // g_maxbots_bomb = 0,
  387.     //Template of bots AI Director uses
  388.     // g_bots_std = 0,
  389.     // g_bots_light = 0,
  390.     // g_bots_jug = 0,
  391.     // g_bots_bomb = 0,
  392.  
  393.     //VIP Globals
  394.     //g_iCvar_vip_obj_time,
  395.     // g_iCvar_vip_min_sp_reward,
  396.     // g_iCvar_vip_max_sp_reward,
  397.     // g_vip_enable,
  398.     // g_vip_obj_count,
  399.     //g_vip_obj_ready,
  400.     // g_vip_min_reward,
  401.     // g_vip_max_reward,
  402.     // g_nVIP_ID = 0,
  403.  
  404. int g_cacheObjActive = 0;
  405.     //g_checkStaticAmt,
  406.     //g_checkStaticAmtCntr,
  407.     //g_checkStaticAmtAway,
  408.     //g_checkStaticAmtCntrAway,
  409. int g_iReinforceTime;
  410.     //g_iReinforceTimeSubsequent,
  411. int g_iReinforceTime_AD_Temp;
  412. int g_iReinforceTimeSubsequent_AD_Temp;
  413. int g_iReinforce_Mult;
  414. int g_iReinforce_Mult_Base;
  415. int g_iRemaining_lives_team_sec;
  416. int g_iRemaining_lives_team_ins;
  417. int g_iRespawn_lives_team_sec;
  418. int g_iRespawn_lives_team_ins;
  419.     // g_iReviveSeconds,
  420. int g_iRespawnSeconds;
  421. int g_secWave_Timer;
  422. int g_iHeal_amount_paddles;
  423. int g_iHeal_amount_medPack;
  424. int g_nonMedicHeal_amount;
  425. int g_nonMedicRevive_hp;
  426. int g_minorWoundRevive_hp;
  427. int g_modWoundRevive_hp;
  428. int g_critWoundRevive_hp;
  429. int g_minorWound_dmg;
  430. int g_moderateWound_dmg;
  431. int g_medicHealSelf_max;
  432. int g_nonMedicHealSelf_max;
  433. int g_nonMedic_maxHealOther;
  434. int g_minorRevive_time;
  435. int g_modRevive_time;
  436. int g_critRevive_time;
  437. int g_nonMedRevive_time;
  438.     //g_medpack_health_amt,
  439. int g_botsReady;
  440. int g_isConquer;
  441. int g_isOutpost;
  442. int g_isCheckpoint;
  443. int g_isHunt;
  444. float g_flMinPlayerDistance;
  445. float g_flBackSpawnIncrease;
  446. float g_flMaxPlayerDistance;
  447. float g_flCanSeeVectorMultiplier;
  448. float g_flMinObjectiveDistance;
  449.     //float g_flMaxObjectiveDistance,
  450.     //float g_flMaxObjectiveDistanceNav,
  451. float g_flSpawnAttackDelay;
  452.     //float g_flMinCounterattackDistance,
  453.  
  454.     //Elite bots Counters
  455. int g_ins_bot_count_checkpoint_max_org;
  456. int g_mp_player_resupply_coop_delay_max_org;
  457. int g_mp_player_resupply_coop_delay_penalty_org;
  458. int g_mp_player_resupply_coop_delay_base_org;
  459. int g_bot_attack_aimpenalty_amt_close_org;
  460. int g_bot_attack_aimpenalty_amt_far_org;
  461. float g_bot_attack_aimpenalty_time_close_org;
  462. float g_bot_attack_aimpenalty_time_far_org;
  463. float g_bot_aim_aimtracking_base_org;
  464. float g_bot_aim_aimtracking_frac_impossible_org;
  465. float g_bot_aim_angularvelocity_frac_impossible_org;
  466. float g_bot_aim_angularvelocity_frac_sprinting_target_org;
  467. float g_bot_aim_attack_aimtolerance_frac_impossible_org;
  468. float g_bot_attackdelay_frac_difficulty_impossible_org;
  469. float g_bot_attack_aimtolerance_newthreat_amt_org;
  470. float g_bot_attack_aimtolerance_newthreat_amt_mult;
  471. int g_bot_attack_aimpenalty_amt_close_mult;
  472. int g_bot_attack_aimpenalty_amt_far_mult;
  473. float g_bot_attackdelay_frac_difficulty_impossible_mult;
  474. float g_bot_attack_aimpenalty_time_close_mult;
  475. float g_bot_attack_aimpenalty_time_far_mult;
  476. float g_bot_aim_aimtracking_base;
  477. float g_bot_aim_aimtracking_frac_impossible;
  478. float g_bot_aim_angularvelocity_frac_impossible;
  479. float g_bot_aim_angularvelocity_frac_sprinting_target;
  480. float g_bot_aim_attack_aimtolerance_frac_impossible;
  481. int g_coop_delay_penalty_base;
  482. int g_isEliteCounter;
  483.  
  484. int m_hMyWeapons;
  485. int m_flNextPrimaryAttack;
  486.  
  487. int m_flNextSecondaryAttack;
  488.  
  489. // KOLOROWE KREDKI
  490. #define YELLOW 0x01
  491. #define GREEN 0x04
  492.  
  493. // SOME DEFINES
  494. #define MAX_LINE_WIDTH 60
  495. #define PLUGIN_VERSION "1.4"
  496.  
  497. // STATS TIME (SET DAYS AFTER STATS ARE DELETE OF NONACTIVE PLAYERS)
  498. #define PLAYER_STATSOLD 30
  499.  
  500. // STATS DEFINATION FOR PLAYERS
  501. int g_iStatKills[MAXPLAYERS+1];
  502. int g_iStatDeaths[MAXPLAYERS+1];
  503. int g_iStatHeadShots[MAXPLAYERS+1];
  504. int g_iStatSuicides[MAXPLAYERS+1];
  505. int g_iStatRevives[MAXPLAYERS+1];
  506. int g_iStatHeals[MAXPLAYERS+1];
  507. char g_sSecBot[] = "[INS] RoundEnd Protector";
  508. int g_iSecBotID = -1;
  509. float g_iCollOff;
  510.  
  511. enum FX
  512. {
  513.     FxNone = 0,
  514.     FxPulseFast,
  515.     FxPulseSlowWide,
  516.     FxPulseFastWide,
  517.     FxFadeSlow,
  518.     FxFadeFast,
  519.     FxSolidSlow,
  520.     FxSolidFast,
  521.     FxStrobeSlow,
  522.     FxStrobeFast,
  523.     FxStrobeFaster,
  524.     FxFlickerSlow,
  525.     FxFlickerFast,
  526.     FxNoDissipation,
  527.     FxDistort,               // Distort/scale/translate flicker
  528.     FxHologram,              // kRenderFxDistort + distance fade
  529.     FxExplode,               // Scale up really big!
  530.     FxGlowShell,             // Glowing Shell
  531.     FxClampMinScale,         // Keep this sprite from getting very small (SPRITES only!)
  532.     FxEnvRain,               // for environmental rendermode, make rain
  533.     FxEnvSnow,               //  "        "            "    , make snow
  534.     FxSpotlight,    
  535.     FxRagdoll,
  536.     FxPulseFastWider,
  537. };
  538.  
  539. enum Render
  540. {
  541.     Normal = 0,         // src
  542.     TransColor,         // c*a+dest*(1-a)
  543.     TransTexture,       // src*a+dest*(1-a)
  544.     Glow,               // src*a+dest -- No Z buffer checks -- Fixed size in screen space
  545.     TransAlpha,         // src*srca+dest*(1-srca)
  546.     TransAdd,           // src*a+dest
  547.     Environmental,      // not drawn, used for environmental effects
  548.     TransAddFrameBlend, // use a fractional frame value to blend between animation frames
  549.     TransAlphaAdd,      // src + dest*(1-a)
  550.     WorldGlow,          // Same as kRenderGlow but not fixed size in screen space
  551.     None,               // Don't render.
  552. };
  553.  
  554. FX:g_Effect = FX:FxGlowShell,
  555. Render:g_Render = Render:Glow;
  556.  
  557. #define PLUGIN_DESCRIPTION "Respawn dead players via admincommand or by queues"
  558. #define UPDATE_URL  "http://ins.jballou.com/sourcemod/update-respawn.txt"
  559.  
  560. // Plugin info
  561. public Plugin myinfo =
  562. {
  563.     name = "[INS] Player Respawn",
  564.     author = "Jared Ballou (Contributor: Daimyo, naong, ozzy and community members)",
  565.     version = PLUGIN_VERSION,
  566.     description = PLUGIN_DESCRIPTION,
  567.     url = "http://jballou.com"
  568. };
  569.  
  570.     ConVar sm_roundendblock_enabled = null;
  571.     ConVar sm_roundendblock_times = null;
  572.     ConVar sm_roundendblock_revive_delay = null;
  573.     ConVar sm_roundendblock_reset_each_round = null;
  574.     ConVar sm_roundendblock_debug = null;
  575.     g_iRoundEndBlockEnabled;
  576.     //g_iRoundEndBlockCapCount = 0;
  577.     //g_iRoundEndBlockMaxCapPoints = 3;
  578.     g_iRoundEndBlockTimes;
  579.     g_iRoundEndBlockReviveDelay;
  580.     g_iRoundEndBlockResetRound;
  581.     g_iRoundEndBlockDebug;
  582.     Handle g_hPlayerRespawn;
  583.     float g_fSpawnPoint[3];
  584.     g_iIsRoundStarted = 0;  //0 is over, 1 is active
  585.     g_iIsRoundStartedPost = 0; //0 is over, 1 is active
  586.     g_iIsGameEnded = 0;     //0 is not ended, 1 is ended
  587.     g_iRoundBlockCount;
  588.     g_iReviveCount;
  589.     //g_iAnnounceActive;
  590.     g_max_AnnounceTime = 480;
  591.     g_announceTick;
  592.     g_bIsCounterAttackTimerActive = false;
  593.     //g_isReviving = 0;
  594.  
  595.  
  596. // Start plugin
  597. public OnPluginStart()
  598. {
  599.     //Find player gear offset
  600.     //g_iPlayerEquipGear = FindSendPropInfo("CINSPlayer", "m_EquippedGear");
  601.    
  602.     //Create player array list
  603.     g_playerArrayList = new ArrayList();
  604.     //g_badSpawnPos_Array = CreateArray();
  605.    
  606.  
  607.     CreateConVar("sm_respawn_version", PLUGIN_VERSION, PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD);
  608.     sm_respawn_enabled = CreateConVar("sm_respawn_enabled", "1", "Automatically respawn players when they die; 0 - disabled, 1 - enabled");
  609.     sm_revive_enabled = CreateConVar("sm_revive_enabled", "1", "Reviving enabled from medics?  This creates revivable ragdoll after death; 0 - disabled, 1 - enabled");
  610.     // Nav Mesh Botspawn specific START
  611.     cvarSpawnMode = CreateConVar("sm_botspawns_spawn_mode", "1", "Only normal spawnpoints at the objective, the old way (0), spawn in hiding spots following rules (1)", FCVAR_NOTIFY);
  612.     //cvarMinCounterattackDistance = CreateConVar("sm_botspawns_min_counterattack_distance", "3600.0", "Min distance from counterattack objective to spawn", FCVAR_NOTIFY);
  613.     cvarMinPlayerDistance = CreateConVar("sm_botspawns_min_player_distance", "240.0", "Min distance from players to spawn", FCVAR_NOTIFY);
  614.     cvarMaxPlayerDistance = CreateConVar("sm_botspawns_max_player_distance", "16000.0", "Max distance from players to spawn", FCVAR_NOTIFY);
  615.     cvarCanSeeVectorMultiplier = CreateConVar("sm_botpawns_can_see_vect_mult", "1.5", "Divide this with sm_botspawns_max_player_distance to get CanSeeVector allowed distance for bot spawning in LOS", FCVAR_NOTIFY);
  616.     cvarMinObjectiveDistance = CreateConVar("sm_botspawns_min_objective_distance", "240", "Min distance from next objective to spawn", FCVAR_NOTIFY);
  617.     cvarMaxObjectiveDistance = CreateConVar("sm_botspawns_max_objective_distance", "12000", "Max distance from next objective to spawn", FCVAR_NOTIFY);
  618.     cvarMaxObjectiveDistanceNav = CreateConVar("sm_botspawns_max_objective_distance_nav", "2000", "Max distance from next objective to spawn", FCVAR_NOTIFY);
  619.     cvarBackSpawnIncrease = CreateConVar("sm_botspawns_backspawn_increase", "1400.0", "Whenever bot spawn on last point, this is added to minimum player respawn distance to avoid spawning too close to player.", FCVAR_NOTIFY);  
  620.     cvarSpawnAttackDelay = CreateConVar("sm_botspawns_spawn_attack_delay", "2", "Delay in seconds for spawning bots to wait before firing.", FCVAR_NOTIFY);
  621.  
  622.     // Nav Mesh Botspawn specific END
  623.  
  624.     // Respawn delay time
  625.     sm_respawn_delay_team_ins = CreateConVar("sm_respawn_delay_team_ins",
  626.         "1.0", "How many seconds to delay the respawn (bots)");
  627.     sm_respawn_delay_team_ins_special = CreateConVar("sm_respawn_delay_team_ins_special",
  628.         "20.0", "How many seconds to delay the respawn (special bots)");
  629.  
  630.  
  631.     sm_respawn_delay_team_sec = CreateConVar("sm_respawn_delay_team_sec",
  632.         "30.0", "How many seconds to delay the respawn (If not set 'sm_respawn_delay_team_sec_player_count_XX' uses this value)");
  633.     sm_respawn_delay_team_sec_player_count_01 = CreateConVar("sm_respawn_delay_team_sec_player_count_01",
  634.         "5.0", "How many seconds to delay the respawn (when player count is 1)");
  635.     sm_respawn_delay_team_sec_player_count_02 = CreateConVar("sm_respawn_delay_team_sec_player_count_02",
  636.         "10.0", "How many seconds to delay the respawn (when player count is 2)");
  637.     sm_respawn_delay_team_sec_player_count_03 = CreateConVar("sm_respawn_delay_team_sec_player_count_03",
  638.         "20.0", "How many seconds to delay the respawn (when player count is 3)");
  639.     sm_respawn_delay_team_sec_player_count_04 = CreateConVar("sm_respawn_delay_team_sec_player_count_04",
  640.         "30.0", "How many seconds to delay the respawn (when player count is 4)");
  641.     sm_respawn_delay_team_sec_player_count_05 = CreateConVar("sm_respawn_delay_team_sec_player_count_05",
  642.         "60.0", "How many seconds to delay the respawn (when player count is 5)");
  643.     sm_respawn_delay_team_sec_player_count_06 = CreateConVar("sm_respawn_delay_team_sec_player_count_06",
  644.         "60.0", "How many seconds to delay the respawn (when player count is 6)");
  645.     sm_respawn_delay_team_sec_player_count_07 = CreateConVar("sm_respawn_delay_team_sec_player_count_07",
  646.         "70.0", "How many seconds to delay the respawn (when player count is 7)");
  647.     sm_respawn_delay_team_sec_player_count_08 = CreateConVar("sm_respawn_delay_team_sec_player_count_08",
  648.         "70.0", "How many seconds to delay the respawn (when player count is 8)");
  649.     sm_respawn_delay_team_sec_player_count_09 = CreateConVar("sm_respawn_delay_team_sec_player_count_09",
  650.         "80.0", "How many seconds to delay the respawn (when player count is 9)");
  651.     sm_respawn_delay_team_sec_player_count_10 = CreateConVar("sm_respawn_delay_team_sec_player_count_10",
  652.         "80.0", "How many seconds to delay the respawn (when player count is 10)");
  653.     sm_respawn_delay_team_sec_player_count_11 = CreateConVar("sm_respawn_delay_team_sec_player_count_11",
  654.         "90.0", "How many seconds to delay the respawn (when player count is 11)");
  655.     sm_respawn_delay_team_sec_player_count_12 = CreateConVar("sm_respawn_delay_team_sec_player_count_12",
  656.         "90.0", "How many seconds to delay the respawn (when player count is 12)");
  657.     sm_respawn_delay_team_sec_player_count_13 = CreateConVar("sm_respawn_delay_team_sec_player_count_13",
  658.         "100.0", "How many seconds to delay the respawn (when player count is 13)");
  659.     sm_respawn_delay_team_sec_player_count_14 = CreateConVar("sm_respawn_delay_team_sec_player_count_14",
  660.         "100.0", "How many seconds to delay the respawn (when player count is 14)");
  661.     sm_respawn_delay_team_sec_player_count_15 = CreateConVar("sm_respawn_delay_team_sec_player_count_15",
  662.         "110.0", "How many seconds to delay the respawn (when player count is 15)");
  663.     sm_respawn_delay_team_sec_player_count_16 = CreateConVar("sm_respawn_delay_team_sec_player_count_16",
  664.         "110.0", "How many seconds to delay the respawn (when player count is 16)");
  665.     sm_respawn_delay_team_sec_player_count_17 = CreateConVar("sm_respawn_delay_team_sec_player_count_17",
  666.         "120.0", "How many seconds to delay the respawn (when player count is 17)");
  667.     sm_respawn_delay_team_sec_player_count_18 = CreateConVar("sm_respawn_delay_team_sec_player_count_18",
  668.         "120.0", "How many seconds to delay the respawn (when player count is 18)");
  669.     sm_respawn_delay_team_sec_player_count_19 = CreateConVar("sm_respawn_delay_team_sec_player_count_19",
  670.         "130.0", "How many seconds to delay the respawn (when player count is 19)");
  671.    
  672.     // Respawn type
  673.     sm_respawn_type_team_sec = CreateConVar("sm_respawn_type_team_sec",
  674.         "1", "1 - individual lives, 2 - each team gets a pool of lives used by everyone, sm_respawn_lives_team_sec must be > 0");
  675.     sm_respawn_type_team_ins = CreateConVar("sm_respawn_type_team_ins",
  676.         "2", "1 - individual lives, 2 - each team gets a pool of lives used by everyone, sm_respawn_lives_team_ins must be > 0");
  677.    
  678.     // Respawn lives
  679.     sm_respawn_lives_team_sec = CreateConVar("sm_respawn_lives_team_sec",
  680.         "-1", "Respawn players this many times (-1: Disables player respawn)");
  681.     sm_respawn_lives_team_ins = CreateConVar("sm_respawn_lives_team_ins",
  682.         "10", "If 'sm_respawn_type_team_ins' set 1, respawn bots this many times. If 'sm_respawn_type_team_ins' set 2, total bot count (If not set 'sm_respawn_lives_team_ins_player_count_XX' uses this value)");
  683.     sm_respawn_lives_team_ins_player_count_01 = CreateConVar("sm_respawn_lives_team_ins_player_count_01",
  684.         "5", "Total bot count (when player count is 1)(sm_respawn_type_team_ins must be 2)");
  685.     sm_respawn_lives_team_ins_player_count_02 = CreateConVar("sm_respawn_lives_team_ins_player_count_02",
  686.         "10", "Total bot count (when player count is 2)(sm_respawn_type_team_ins must be 2)");
  687.     sm_respawn_lives_team_ins_player_count_03 = CreateConVar("sm_respawn_lives_team_ins_player_count_03",
  688.         "15", "Total bot count (when player count is 3)(sm_respawn_type_team_ins must be 2)");
  689.     sm_respawn_lives_team_ins_player_count_04 = CreateConVar("sm_respawn_lives_team_ins_player_count_04",
  690.         "20", "Total bot count (when player count is 4)(sm_respawn_type_team_ins must be 2)");
  691.     sm_respawn_lives_team_ins_player_count_05 = CreateConVar("sm_respawn_lives_team_ins_player_count_05",
  692.         "25", "Total bot count (when player count is 5)(sm_respawn_type_team_ins must be 2)");
  693.     sm_respawn_lives_team_ins_player_count_06 = CreateConVar("sm_respawn_lives_team_ins_player_count_06",
  694.         "30", "Total bot count (when player count is 6)(sm_respawn_type_team_ins must be 2)");
  695.     sm_respawn_lives_team_ins_player_count_07 = CreateConVar("sm_respawn_lives_team_ins_player_count_07",
  696.         "35", "Total bot count (when player count is 7)(sm_respawn_type_team_ins must be 2)");
  697.     sm_respawn_lives_team_ins_player_count_08 = CreateConVar("sm_respawn_lives_team_ins_player_count_08",
  698.         "40", "Total bot count (when player count is 8)(sm_respawn_type_team_ins must be 2)");
  699.     sm_respawn_lives_team_ins_player_count_09 = CreateConVar("sm_respawn_lives_team_ins_player_count_09",
  700.         "45", "Total bot count (when player count is 9)(sm_respawn_type_team_ins must be 2)");
  701.     sm_respawn_lives_team_ins_player_count_10 = CreateConVar("sm_respawn_lives_team_ins_player_count_10",
  702.         "50", "Total bot count (when player count is 10)(sm_respawn_type_team_ins must be 2)");
  703.     sm_respawn_lives_team_ins_player_count_11 = CreateConVar("sm_respawn_lives_team_ins_player_count_11",
  704.         "55", "Total bot count (when player count is 11)(sm_respawn_type_team_ins must be 2)");
  705.     sm_respawn_lives_team_ins_player_count_12 = CreateConVar("sm_respawn_lives_team_ins_player_count_12",
  706.         "60", "Total bot count (when player count is 12)(sm_respawn_type_team_ins must be 2)");
  707.     sm_respawn_lives_team_ins_player_count_13 = CreateConVar("sm_respawn_lives_team_ins_player_count_13",
  708.         "65", "Total bot count (when player count is 13)(sm_respawn_type_team_ins must be 2)");
  709.     sm_respawn_lives_team_ins_player_count_14 = CreateConVar("sm_respawn_lives_team_ins_player_count_14",
  710.         "70", "Total bot count (when player count is 14)(sm_respawn_type_team_ins must be 2)");
  711.     sm_respawn_lives_team_ins_player_count_15 = CreateConVar("sm_respawn_lives_team_ins_player_count_15",
  712.         "75", "Total bot count (when player count is 15)(sm_respawn_type_team_ins must be 2)");
  713.     sm_respawn_lives_team_ins_player_count_16 = CreateConVar("sm_respawn_lives_team_ins_player_count_16",
  714.         "80", "Total bot count (when player count is 16)(sm_respawn_type_team_ins must be 2)");
  715.     sm_respawn_lives_team_ins_player_count_17 = CreateConVar("sm_respawn_lives_team_ins_player_count_17",
  716.         "85", "Total bot count (when player count is 17)(sm_respawn_type_team_ins must be 2)");
  717.     sm_respawn_lives_team_ins_player_count_18 = CreateConVar("sm_respawn_lives_team_ins_player_count_18",
  718.         "90", "Total bot count (when player count is 18)(sm_respawn_type_team_ins must be 2)");
  719.     sm_respawn_lives_team_ins_player_count_19 = CreateConVar("sm_respawn_lives_team_ins_player_count_19",
  720.         "90", "Total bot count (when player count is 19)(sm_respawn_type_team_ins must be 2)");
  721.    
  722.     // Fatally death
  723.     sm_respawn_fatal_chance = CreateConVar("sm_respawn_fatal_chance", "0.20", "Chance for a kill to be fatal, 0.6 default = 60% chance to be fatal (To disable set 0.0)");
  724.     sm_respawn_fatal_head_chance = CreateConVar("sm_respawn_fatal_head_chance", "0.30", "Chance for a headshot kill to be fatal, 0.6 default = 60% chance to be fatal");
  725.     sm_respawn_fatal_limb_dmg = CreateConVar("sm_respawn_fatal_limb_dmg", "80", "Amount of damage to fatally kill player in limb");
  726.     sm_respawn_fatal_head_dmg = CreateConVar("sm_respawn_fatal_head_dmg", "100", "Amount of damage to fatally kill player in head");
  727.     sm_respawn_fatal_burn_dmg = CreateConVar("sm_respawn_fatal_burn_dmg", "50", "Amount of damage to fatally kill player in burn");
  728.     sm_respawn_fatal_explosive_dmg = CreateConVar("sm_respawn_fatal_explosive_dmg", "200", "Amount of damage to fatally kill player in explosive");
  729.     sm_respawn_fatal_chest_stomach = CreateConVar("sm_respawn_fatal_chest_stomach", "100", "Amount of damage to fatally kill player in chest/stomach");
  730.    
  731.     // Counter attack
  732.     sm_respawn_counter_chance = CreateConVar("sm_respawn_counter_chance", "0.5", "Percent chance that a counter attack will happen def: 50%");
  733.     sm_respawn_counterattack_type = CreateConVar("sm_respawn_counterattack_type", "2", "Respawn during counterattack? (0: no, 1: yes, 2: infinite)");
  734.     sm_respawn_final_counterattack_type = CreateConVar("sm_respawn_final_counterattack_type", "2", "Respawn during final counterattack? (0: no, 1: yes, 2: infinite)");
  735.     sm_respawn_security_on_counter = CreateConVar("sm_respawn_security_on_counter", "1", "0/1 When a counter attack starts, spawn all dead players and teleport them to point to defend");
  736.     sm_respawn_min_counter_dur_sec = CreateConVar("sm_respawn_min_counter_dur_sec", "66", "Minimum randomized counter attack duration");
  737.     sm_respawn_max_counter_dur_sec = CreateConVar("sm_respawn_max_counter_dur_sec", "126", "Maximum randomized counter attack duration");
  738.     sm_respawn_final_counter_dur_sec = CreateConVar("sm_respawn_final_counter_dur_sec", "180", "Final counter attack duration");
  739.     sm_respawn_counterattack_vanilla = CreateConVar("sm_respawn_counterattack_vanilla", "0", "Use vanilla counter attack mechanics? (0: no, 1: yes)");
  740.    
  741.     //Dynamic respawn mechanics
  742.     sm_respawn_dynamic_distance_multiplier = CreateConVar("sm_respawn_dynamic_distance_multiplier", "2", "This multiplier is used to make bot distance from points on/off counter attacks more dynamic by making distance closer/farther when bots respawn");
  743.     sm_respawn_dynamic_spawn_counter_percent = CreateConVar("sm_respawn_dynamic_spawn_counter_percent", "40", "Percent of bots that will spawn farther away on a counter attack (basically their more ideal normal spawns)");
  744.     sm_respawn_dynamic_spawn_percent = CreateConVar("sm_respawn_dynamic_spawn_percent", "5", "Percent of bots that will spawn farther away NOT on a counter (basically their more ideal normal spawns)");
  745.    
  746.     // Misc
  747.     sm_respawn_reset_type = CreateConVar("sm_respawn_reset_type", "0", "Set type of resetting player respawn counts: each round or each objective (0: each round, 1: each objective)");
  748.     sm_respawn_enable_track_ammo = CreateConVar("sm_respawn_enable_track_ammo", "1", "0/1 Track ammo on death to revive (may be buggy if using a different theatre that modifies ammo)");
  749.    
  750.     // Reinforcements
  751.     sm_respawn_reinforce_time = CreateConVar("sm_respawn_reinforce_time", "200", "When enemy forces are low on lives, how much time til they get reinforcements?");
  752.     sm_respawn_reinforce_time_subsequent = CreateConVar("sm_respawn_reinforce_time_subsequent", "140", "When enemy forces are low on lives and already reinforced, how much time til they get reinforcements on subsequent reinforcement?");
  753.     sm_respawn_reinforce_multiplier = CreateConVar("sm_respawn_reinforce_multiplier", "4", "Division multiplier to determine when to start reinforce timer for bots based on team pool lives left over");
  754.     sm_respawn_reinforce_multiplier_base = CreateConVar("sm_respawn_reinforce_multiplier_base", "10", "This is the base int number added to the division multiplier, so (10 * reinforce_mult + base_mult)");
  755.  
  756.     // Control static enemy
  757.     //sm_respawn_check_static_enemy = CreateConVar("sm_respawn_check_static_enemy", "120", "Seconds amount to check if an AI has moved probably stuck");
  758.     //sm_respawn_check_static_enemy_counter = CreateConVar("sm_respawn_check_static_enemy_counter", "10", "Seconds amount to check if an AI has moved during counter");
  759.    
  760.     // Donor tag
  761.     sm_respawn_enable_donor_tag = CreateConVar("sm_respawn_enable_donor_tag", "1", "If player has an access to reserved slot, add [DONOR] tag.");
  762.    
  763.     // Related to 'RoundEnd_Protector' plugin
  764.     //sm_remaininglife = CreateConVar("sm_remaininglife", "-1", "Returns total remaining life.");
  765.    
  766.     // Medic Revive
  767.     sm_revive_seconds = CreateConVar("sm_revive_seconds", "5", "Time in seconds medic needs to stand over body to revive");
  768.     //sm_revive_bonus = CreateConVar("sm_revive_bonus", "1", "Bonus revive score(kill count) for medic");
  769.     sm_revive_distance_metric = CreateConVar("sm_revive_distance_metric", "1", "Distance metric (0: meters / 1: feet)");
  770.     //sm_heal_bonus = CreateConVar("sm_heal_bonus", "1", "Bonus heal score(kill count) for medic");
  771.     sm_heal_cap_for_bonus = CreateConVar("sm_heal_cap_for_bonus", "5000", "Amount of health given to other players to gain a life");
  772.     sm_revive_cap_for_bonus = CreateConVar("sm_revive_cap_for_bonus", "50", "Amount of revives before medic gains a life");
  773.     sm_reward_medics_enabled = CreateConVar("sm_reward_medics_enabled", "1", "Enabled rewarding medics with lives? 0 = no, 1 = yes");
  774.     sm_heal_amount_medpack = CreateConVar("sm_heal_amount_medpack", "5", "Heal amount per 0.5 seconds when using medpack");
  775.     sm_heal_amount_paddles = CreateConVar("sm_heal_amount_paddles", "3", "Heal amount per 0.5 seconds when using paddles");
  776.     sm_non_medic_heal_amt = CreateConVar("sm_non_medic_heal_amt", "2", "Heal amount per 0.5 seconds when non-medic");
  777.     sm_non_medic_revive_hp = CreateConVar("sm_non_medic_revive_hp", "10", "Health given to target revive when non-medic reviving");
  778.     sm_medic_minor_revive_hp = CreateConVar("sm_medic_minor_revive_hp", "75", "Health given to target revive when medic reviving minor wound");
  779.     sm_medic_moderate_revive_hp = CreateConVar("sm_medic_moderate_revive_hp", "50", "Health given to target revive when medic reviving moderate wound");
  780.     sm_medic_critical_revive_hp = CreateConVar("sm_medic_critical_revive_hp", "25", "Health given to target revive when medic reviving critical wound");
  781.     sm_minor_wound_dmg = CreateConVar("sm_minor_wound_dmg", "100", "Any amount of damage <= to this is considered a minor wound when killed");
  782.     sm_moderate_wound_dmg = CreateConVar("sm_moderate_wound_dmg", "200", "Any amount of damage <= to this is considered a minor wound when killed.  Anything greater is CRITICAL");
  783.     sm_medic_heal_self_max = CreateConVar("sm_medic_heal_self_max", "75", "Max medic can heal self to with med pack");
  784.     sm_non_medic_heal_self_max = CreateConVar("sm_non_medic_heal_self_max", "25", "Max non-medic can heal self to with med pack");
  785.     sm_non_medic_max_heal_other = CreateConVar("sm_non_medic_max_heal_other", "25", "Heal amount per 0.5 seconds when using paddles");
  786.     sm_minor_revive_time = CreateConVar("sm_minor_revive_time", "4", "Seconds it takes medic to revive minor wounded");
  787.     sm_moderate_revive_time = CreateConVar("sm_moderate_revive_time", "7", "Seconds it takes medic to revive moderate wounded");
  788.     sm_critical_revive_time = CreateConVar("sm_critical_revive_time", "10", "Seconds it takes medic to revive critical wounded");
  789.     sm_non_medic_revive_time = CreateConVar("sm_non_medic_revive_time", "30", "Seconds it takes non-medic to revive minor wounded, requires medpack");
  790.     //sm_medpack_health_amount = CreateConVar("sm_medpack_health_amount", "500", "Amount of health a deployed healthpack has");
  791.     //sm_bombers_only = CreateConVar("sm_bombers_only", "0", "bombers ONLY?");
  792.     //sm_multi_loadout_enabled = CreateConVar("sm_multi_loadout_enabled", "0", "Use Sernix Variety Bot Loadout? - Default OFF");
  793.     //sm_ammo_resupply_range = CreateConVar("sm_ammo_resupply_range", "80", "Range to resupply near ammo cache");
  794.     sm_resupply_delay = CreateConVar("sm_resupply_delay", "5", "Delay loop for resupply ammo");
  795.     sm_jammer_required = CreateConVar("sm_jammer_required", "1", "Require deployable jammer for enemy reports? 0 = Disabled 1 = Enabled");
  796.     sm_elite_counter_attacks = CreateConVar("sm_elite_counter_attacks", "1", "Enable increased bot skills, numbers on counters?");
  797.     sm_enable_bonus_lives = CreateConVar("sm_enable_bonus_lives", "1", "Give bonus lives based on X condition? 0|1 ");
  798.    
  799.  
  800.     //Specialized Counter
  801.     sm_finale_counter_spec_enabled = CreateConVar("sm_finale_counter_spec_enabled", "0", "Enable specialized finale spawn percent? 1|0");
  802.     sm_finale_counter_spec_percent = CreateConVar("sm_finale_counter_spec_percent", "40", "What specialized finale counter percent for this map?");
  803.     //sm_cqc_map_enabled = CreateConVar("sm_cqc_map_enabled", "0", "Is this a cqc map? 0|1 no|yes");
  804.  
  805.     //sm_enable_squad_spawning = CreateConVar("sm_enable_squad_spawning", "0", "Enable squad spawning SERNIX SPECIFIC? 1|0");
  806.     //AI Director cvars
  807.     sm_ai_director_setdiff_chance_base = CreateConVar("sm_ai_director_setdiff_chance_base", "10", "Base AI Director Set Hard Difficulty Chance");
  808.  
  809.     //Respawn Modes
  810.     sm_respawn_mode_team_sec = CreateConVar("sm_respawn_mode_team_sec", "1", "Security: 0 = Individual spawning | 1 = Wave based spawning");
  811.     sm_respawn_mode_team_ins = CreateConVar("sm_respawn_mode_team_ins", "0", "Insurgents: 0 = Individual spawning | 1 = Wave based spawning");
  812.  
  813.     //Wave interval for insurgents only
  814.     sm_respawn_wave_int_team_ins = CreateConVar("sm_respawn_wave_int_team_ins", "1", "Time in seconds bots will respawn in waves");
  815.    
  816.     // cvars
  817.     sm_roundendblock_enabled = CreateConVar("sm_roundendblock_enabled", "1", "Coop bot Enabled", FCVAR_NOTIFY);
  818.     sm_roundendblock_times = CreateConVar("sm_roundendblock_times", "1", "How many times block rounds.");
  819.     sm_roundendblock_revive_delay = CreateConVar("sm_roundendblock_revive_delay", "10", "When blocks RoundEnd, wait for reviving players.");
  820.     sm_roundendblock_reset_each_round = CreateConVar("sm_roundendblock_reset_each_round", "1", "Reset block counter each round. (1 is reset / 0 is don't reset)");
  821.     sm_roundendblock_debug = CreateConVar("sm_roundendblock_debug", "0", "1: Turn on debug mode, 0: Turn off");
  822.  
  823.     CreateConVar("Lua_Ins_Healthkit", PLUGIN_VERSION, PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD);
  824.    
  825.     if ((m_hMyWeapons = FindSendPropInfo("CBasePlayer", "m_hMyWeapons")) == -1)
  826.         SetFailState("Fatal Error: Unable to find property offset \"CBasePlayer::m_hMyWeapons\" !");
  827.    
  828.     if ((m_flNextPrimaryAttack = FindSendPropInfo("CBaseCombatWeapon", "m_flNextPrimaryAttack")) == -1)
  829.         SetFailState("Fatal Error: Unable to find property offset \"CBaseCombatWeapon::m_flNextPrimaryAttack\" !");
  830.    
  831.     if ((m_flNextSecondaryAttack = FindSendPropInfo("CBaseCombatWeapon", "m_flNextSecondaryAttack")) == -1)    
  832.         SetFailState("Fatal Error: Unable to find property offset \"CBaseCombatWeapon::m_flNextSecondaryAttack\" !");
  833.  
  834.     // Add admin respawn console command
  835.     RegAdminCmd("sm_respawn", Command_Respawn, ADMFLAG_SLAY, "sm_respawn <#userid|name>");
  836.     // Add reload config console command for admin
  837.     RegAdminCmd("sm_respawn_reload", Command_Reload, ADMFLAG_SLAY, "sm_respawn_reload");
  838.     // register roundend admin commands
  839.     RegAdminCmd("sm_botcount", Command_BotCount, ADMFLAG_SLAY, "sm_botcount"); 
  840.    
  841.     //g_iCollOff = FindSendPropInfo("CBaseEntity", "m_CollisionGroup"); - roundendblock
  842.  
  843.     // Event hooking
  844.     //Lua Specific
  845.     //HookEvent("grenade_thrown", Event_GrenadeThrown);
  846.     //For ins_spawnpoint spawning
  847.     HookEvent("player_spawn", Event_Spawn);
  848.     HookEvent("player_spawn", Event_SpawnPost, EventHookMode_Post);
  849.     HookEvent("player_hurt", Event_PlayerHurt_Pre, EventHookMode_Pre);
  850.     HookEvent("player_death", Event_PlayerDeath_Pre, EventHookMode_Pre);
  851.     HookEvent("player_death", Event_PlayerDeath);
  852.     HookEvent("round_start", Event_RoundStart);
  853.     HookEvent("round_end", Event_RoundEnd);
  854.     HookEvent("round_end", Event_RoundEnd_Pre, EventHookMode_Pre);
  855.     HookEvent("game_start", Event_GameStart, EventHookMode_PostNoCopy);
  856.     HookEvent("game_end", Event_GameEnd, EventHookMode_PostNoCopy);
  857.     HookEvent("player_pick_squad", Event_PlayerPickSquad_Post, EventHookMode_Post);
  858.     HookEvent("object_destroyed", Event_ObjectDestroyed_Pre, EventHookMode_Pre);
  859.     HookEvent("object_destroyed", Event_ObjectDestroyed);
  860.     HookEvent("object_destroyed", Event_ObjectDestroyed_Post, EventHookMode_Post);
  861.     HookEvent("controlpoint_captured", Event_ControlPointCaptured_Pre, EventHookMode_Pre);
  862.     HookEvent("controlpoint_captured", Event_ControlPointCaptured);
  863.     HookEvent("controlpoint_captured", Event_ControlPointCaptured_Post, EventHookMode_Post);
  864.     HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Pre);
  865.     HookEvent("player_connect", Event_PlayerConnect);
  866.     //HookEvent("player_team", Event_PlayerTeam);
  867.     HookEvent("weapon_reload", Event_PlayerReload_Pre, EventHookMode_Pre);
  868.  
  869.     //AddCommandListener(ResupplyListener, "inventory_resupply");
  870.  
  871.     // NavMesh Botspawn Specific Start
  872.     cvarSpawnMode.AddChangeHook(CvarChange);
  873.     // NavMesh Botspawn Specific End
  874.    
  875.     // Revive/Heal specific
  876.     sm_revive_seconds.AddChangeHook(CvarChange);
  877.     sm_heal_amount_medpack.AddChangeHook(CvarChange);
  878.  
  879.     sm_non_medic_heal_amt.AddChangeHook(CvarChange);
  880.     sm_non_medic_revive_hp.AddChangeHook(CvarChange);
  881.     sm_medic_minor_revive_hp.AddChangeHook(CvarChange);
  882.     sm_medic_moderate_revive_hp.AddChangeHook(CvarChange);
  883.     sm_medic_critical_revive_hp.AddChangeHook(CvarChange);
  884.     sm_minor_wound_dmg.AddChangeHook(CvarChange);
  885.     sm_moderate_wound_dmg.AddChangeHook(CvarChange);
  886.     sm_medic_heal_self_max.AddChangeHook(CvarChange);
  887.     sm_non_medic_heal_self_max.AddChangeHook(CvarChange);
  888.     sm_non_medic_max_heal_other.AddChangeHook(CvarChange);
  889.     sm_minor_revive_time.AddChangeHook(CvarChange);
  890.     sm_moderate_revive_time.AddChangeHook(CvarChange);
  891.     sm_critical_revive_time.AddChangeHook(CvarChange);
  892.     sm_non_medic_revive_time.AddChangeHook(CvarChange);
  893.     sm_medpack_health_amount.AddChangeHook(CvarChange);
  894.     //sm_medpack_health_amount.AddChangeHook(CvarChange);
  895.    
  896.     // Respawn specific
  897.     sm_respawn_enabled.AddChangeHook(EnableChanged);
  898.     sm_revive_enabled.AddChangeHook(EnableChanged);
  899.     sm_respawn_delay_team_sec.AddChangeHook(CvarChange);
  900.     sm_respawn_delay_team_ins.AddChangeHook(CvarChange);
  901.     sm_respawn_delay_team_ins_special.AddChangeHook(CvarChange);
  902.     sm_respawn_lives_team_sec.AddChangeHook(CvarChange);
  903.     sm_respawn_lives_team_ins.AddChangeHook(CvarChange);
  904.     sm_respawn_reset_type.AddChangeHook(CvarChange);
  905.     sm_respawn_type_team_sec.AddChangeHook(CvarChange);
  906.     sm_respawn_type_team_ins.AddChangeHook(CvarChange);
  907.     cvarMinPlayerDistance.AddChangeHook(CvarChange);
  908.     cvarBackSpawnIncrease.AddChangeHook(CvarChange);
  909.     cvarMaxPlayerDistance.AddChangeHook(CvarChange);
  910.     cvarCanSeeVectorMultiplier.AddChangeHook(CvarChange);
  911.     cvarMinObjectiveDistance.AddChangeHook(CvarChange);
  912.     cvarMaxObjectiveDistance.AddChangeHook(CvarChange);
  913.     cvarMaxObjectiveDistanceNav.AddChangeHook(CvarChange);
  914.     sm_enable_bonus_lives.AddChangeHook(CvarChange);
  915.  
  916.     //Dynamic respawning
  917.     sm_respawn_dynamic_distance_multiplier.AddChangeHook(CvarChange);
  918.     sm_respawn_dynamic_spawn_counter_percent.AddChangeHook(CvarChange);
  919.     sm_respawn_dynamic_spawn_percent.AddChangeHook(CvarChange);
  920.  
  921.      //Reinforce Timer
  922.     sm_respawn_reinforce_time.AddChangeHook(CvarChange);
  923.     sm_respawn_reinforce_time_subsequent.AddChangeHook(CvarChange);
  924.     sm_respawn_reinforce_multiplier.AddChangeHook(CvarChange);
  925.     sm_respawn_reinforce_multiplier_base.AddChangeHook(CvarChange);
  926.  
  927.     // Tags
  928.     FindConVar("sv_tags").AddChangeHook(TagsChanged);
  929.  
  930.     //roundendblock
  931.     sm_roundendblock_enabled.AddChangeHook(CvarChange);
  932.     sm_roundendblock_times.AddChangeHook(CvarChange);
  933.     sm_roundendblock_reset_each_round.AddChangeHook(CvarChange);
  934.     sm_roundendblock_debug.AddChangeHook(CvarChange);
  935.     sm_roundendblock_revive_delay.AddChangeHook(CvarChange);
  936.  
  937.     //roundendblock
  938.     sm_roundendblock_enabled.AddChangeHook(CvarChange);
  939.     sm_roundendblock_times.AddChangeHook(CvarChange);
  940.     sm_roundendblock_reset_each_round.AddChangeHook(CvarChange);
  941.     sm_roundendblock_debug.AddChangeHook(CvarChange);
  942.     sm_roundendblock_revive_delay.AddChangeHook(CvarChange);
  943.  
  944.     //Other
  945.     sm_jammer_required.AddChangeHook(CvarChange);
  946.     sm_elite_counter_attacks.AddChangeHook(CvarChange);
  947.     sm_finale_counter_spec_enabled.AddChangeHook(CvarChange);
  948.     sm_ai_director_setdiff_chance_base.AddChangeHook(CvarChange);
  949.     sm_respawn_mode_team_sec.AddChangeHook(CvarChange);
  950.     sm_respawn_mode_team_ins.AddChangeHook(CvarChange);
  951.     sm_respawn_wave_int_team_ins.AddChangeHook(CvarChange);
  952.     sm_finale_counter_spec_percent.AddChangeHook(CvarChange);
  953.    
  954.     // Init respawn function
  955.     // Next 14 lines of text are taken from Andersso's DoDs respawn plugin. Thanks :)
  956.     //g_hGameConfig;
  957.    
  958.     //Handle g_hGameConfig;
  959.     //Handle g_hForceRespawn;
  960.    
  961.     g_hGameConfig = LoadGameConfigFile("insurgency.games");
  962.    
  963.     if (g_hGameConfig == null)
  964.         SetFailState("Fatal Error: Missing File \"insurgency.games\"!");
  965.  
  966.     StartPrepSDKCall(SDKCall_Player);
  967.     char game[40];
  968.     GetGameFolderName(game, sizeof(game));
  969.     g_hPlayerRespawn = EndPrepSDKCall();
  970.     if (StrEqual(game, "insurgency"))
  971.     {
  972.         PrepSDKCall_SetFromConf(g_hGameConfig, SDKConf_Signature, "ForceRespawn");
  973.     }
  974.    
  975.     g_hForceRespawn = EndPrepSDKCall();
  976.     if (g_hForceRespawn == INVALID_HANDLE)
  977.     {
  978.         SetFailState("Fatal Error: Unable to find signature for \"ForceRespawn\"!");
  979.     }
  980.  
  981.     //Load localization file
  982.     LoadTranslations("common.phrases");
  983.     LoadTranslations("respawn.phrases");
  984.     LoadTranslations("nearest_player.phrases.txt");
  985.     AutoExecConfig(true, "respawn");
  986.  
  987.     // create config file
  988.     //AutoExecConfig(true, "plugin.roundendblock");
  989.  
  990.     // init var - roundendblock
  991.  
  992.     g_iRoundEndBlockEnabled = GetConVarInt(sm_roundendblock_enabled);
  993.     g_iRoundEndBlockTimes = GetConVarInt(sm_roundendblock_times);
  994.     g_iRoundEndBlockReviveDelay = GetConVarInt(sm_roundendblock_revive_delay);
  995.     g_iRoundEndBlockResetRound = GetConVarInt(sm_roundendblock_reset_each_round);
  996.     g_iRoundEndBlockDebug = GetConVarInt(sm_roundendblock_debug);
  997. }
  998.  
  999. // When cvar changed
  1000. public void EnableChanged(ConVar convar, const char[] oldValue, const char[] newValue)
  1001. {
  1002.     int intNewValue = StringToInt(newValue);
  1003.     int intOldValue = StringToInt(oldValue);
  1004.  
  1005.     if(intNewValue == 1 && intOldValue == 0)
  1006.     {
  1007.         TagsCheck("respawntimes");
  1008.         //HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
  1009.     }
  1010.     else if(intNewValue == 0 && intOldValue == 1)
  1011.     {
  1012.         TagsCheck("respawntimes", true);
  1013.         //UnhookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
  1014.     }
  1015. }
  1016.  
  1017. // When cvar changed
  1018. public void CvarChange(ConVar cvar, const char[] oldvalue, const char[] newvalue)
  1019. {
  1020. (g_iRoundEndBlockEnabled = sm_roundendblock_enabled.IntValue);
  1021. (g_iRoundEndBlockTimes = sm_roundendblock_times.IntValue);
  1022. (g_iRoundEndBlockReviveDelay = sm_roundendblock_revive_delay.IntValue);
  1023. (g_iRoundEndBlockResetRound = sm_roundendblock_reset_each_round.IntValue);
  1024. (g_iRoundEndBlockDebug = sm_roundendblock_debug.IntValue); 
  1025. UpdateRespawnCvars();
  1026. }
  1027.  
  1028. // Update cvars
  1029. void UpdateRespawnCvars()
  1030. {
  1031.     //Counter attack chance based on number of points
  1032.     g_respawn_counter_chance = sm_respawn_counter_chance.FloatValue;
  1033.     g_counterAttack_min_dur_sec = sm_respawn_min_counter_dur_sec.IntValue;
  1034.     g_counterAttack_max_dur_sec = sm_respawn_max_counter_dur_sec.IntValue;
  1035.  
  1036.     // The number of control points
  1037.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  1038.     if (ncp < 6)
  1039.     {
  1040.         //Add to minimum dur as well.
  1041.         int fRandomInt = GetRandomInt(15, 30);
  1042.         int fRandomInt2 = GetRandomInt(6, 12);
  1043.         g_counterAttack_min_dur_sec += fRandomInt;
  1044.         g_counterAttack_max_dur_sec += fRandomInt2;
  1045.         g_respawn_counter_chance += 0.2;
  1046.     }
  1047.     else if (ncp >= 6 && ncp <= 8)
  1048.     {
  1049.         //Add to minimum dur as well.
  1050.         int fRandomInt = GetRandomInt(10, 20);
  1051.         int fRandomInt2 = GetRandomInt(4, 8);
  1052.         g_counterAttack_min_dur_sec += fRandomInt;
  1053.         g_counterAttack_max_dur_sec += fRandomInt2;
  1054.         g_respawn_counter_chance += 0.1;
  1055.     }
  1056.  
  1057. //  g_jammerRequired = GetConVarInt(sm_jammer_required);
  1058.     g_elite_counter_attacks = sm_elite_counter_attacks.IntValue;
  1059.     g_finale_counter_spec_enabled = sm_finale_counter_spec_enabled.IntValue;
  1060.     g_finale_counter_spec_percent = sm_finale_counter_spec_percent.IntValue;
  1061.  
  1062.     //Ai Director UpdateCvar
  1063.     g_AIDir_DiffChanceBase = sm_ai_director_setdiff_chance_base.IntValue;
  1064.  
  1065.     //Wave Based Spawning
  1066.     g_respawn_mode_team_sec = sm_respawn_mode_team_sec.IntValue;
  1067.    
  1068.     // Respawn type 1 //TEAM_1_SEC == Index 2 and TEAM_2_INS == Index 3
  1069.     g_iRespawnCount[2] = sm_respawn_lives_team_sec.IntValue;
  1070.     g_iRespawnCount[3] = sm_respawn_lives_team_ins.IntValue;
  1071.     g_GiveBonusLives = sm_enable_bonus_lives.IntValue;
  1072.  
  1073.     //Give bonus lives if lives are added per round
  1074.     if (g_GiveBonusLives && g_iCvar_respawn_reset_type == 0)
  1075.         SecTeamLivesBonus();
  1076.    
  1077.    
  1078.     // Type of resetting respawn token, Non-checkpoint modes get set to 0 automatically
  1079.     g_iCvar_respawn_reset_type = sm_respawn_reset_type.IntValue;
  1080.  
  1081.     if (g_isCheckpoint == 0)
  1082.         g_iCvar_respawn_reset_type = 0;
  1083.    
  1084.  
  1085.     // Update Cvars
  1086.     g_iCvar_respawn_enable = sm_respawn_enabled.IntValue;
  1087.     g_iCvar_revive_enable = sm_revive_enabled.IntValue;
  1088.     // Bot spawn mode
  1089.  
  1090.     g_iReinforce_Mult = sm_respawn_reinforce_multiplier.IntValue;
  1091.     g_iReinforce_Mult_Base = sm_respawn_reinforce_multiplier_base.IntValue;
  1092.  
  1093.     // Tracking ammo
  1094.     g_iCvar_enable_track_ammo = sm_respawn_enable_track_ammo.IntValue;
  1095.  
  1096.     // Respawn type
  1097.     g_iCvar_respawn_type_team_ins = sm_respawn_type_team_ins.IntValue;
  1098.     g_iCvar_respawn_type_team_sec = sm_respawn_type_team_sec.IntValue;
  1099.  
  1100.  
  1101.     //Dynamic Respawns
  1102.     g_DynamicRespawn_Distance_mult = sm_respawn_dynamic_distance_multiplier.IntValue;
  1103.     g_dynamicSpawnCounter_Perc = sm_respawn_dynamic_spawn_counter_percent.IntValue;
  1104.     g_dynamicSpawn_Perc = sm_respawn_dynamic_spawn_percent.IntValue;
  1105.  
  1106.     //Revive counts
  1107.  
  1108.     // Heal Amount
  1109.     g_iHeal_amount_medPack = sm_heal_amount_medpack.IntValue;
  1110.     g_iHeal_amount_paddles = sm_heal_amount_paddles.IntValue;
  1111.     g_nonMedicHeal_amount = sm_non_medic_heal_amt.IntValue;
  1112.  
  1113.     //HP when revived from wound
  1114.     g_nonMedicRevive_hp = sm_non_medic_revive_hp.IntValue;
  1115.     g_minorWoundRevive_hp = sm_medic_minor_revive_hp.IntValue;
  1116.     g_modWoundRevive_hp = sm_medic_moderate_revive_hp.IntValue;
  1117.     g_critWoundRevive_hp = sm_medic_critical_revive_hp.IntValue;
  1118.  
  1119.     //New Revive Mechanics
  1120.     g_minorWound_dmg = sm_minor_wound_dmg.IntValue;
  1121.     g_moderateWound_dmg = sm_moderate_wound_dmg.IntValue;
  1122.     g_medicHealSelf_max = sm_medic_heal_self_max.IntValue;
  1123.     g_nonMedicHealSelf_max = sm_non_medic_heal_self_max.IntValue;
  1124.     g_nonMedic_maxHealOther = sm_non_medic_max_heal_other.IntValue;
  1125.     g_minorRevive_time = sm_minor_revive_time.IntValue;
  1126.     g_modRevive_time = sm_moderate_revive_time.IntValue;
  1127.     g_critRevive_time = sm_critical_revive_time.IntValue;
  1128.     g_nonMedRevive_time = sm_non_medic_revive_time.IntValue;
  1129.     //g_medpack_health_amt = sm_medpack_health_amount.IntValue;
  1130.     // Fatal dead
  1131.     g_fCvar_fatal_chance = sm_respawn_fatal_chance.FloatValue;
  1132.     g_fCvar_fatal_head_chance = sm_respawn_fatal_head_chance.FloatValue;
  1133.     g_iCvar_fatal_limb_dmg = sm_respawn_fatal_limb_dmg.IntValue;
  1134.     g_iCvar_fatal_head_dmg = sm_respawn_fatal_head_dmg.IntValue;
  1135.     g_iCvar_fatal_burn_dmg = sm_respawn_fatal_burn_dmg.IntValue;
  1136.     g_iCvar_fatal_explosive_dmg = sm_respawn_fatal_explosive_dmg.IntValue;
  1137.     g_iCvar_fatal_chest_stomach = sm_respawn_fatal_chest_stomach.IntValue;
  1138.  
  1139.     // Nearest body distance metric
  1140.     g_iUnitMetric = sm_revive_distance_metric.IntValue;
  1141.    
  1142.     // Set respawn delay time
  1143.     g_iRespawnSeconds = -1;
  1144.     switch (GetTeamSecCount())
  1145.     {
  1146.         case 0: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_01.IntValue;
  1147.         case 1: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_01.IntValue;
  1148.         case 2: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_02.IntValue;
  1149.         case 3: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_03.IntValue;
  1150.         case 4: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_04.IntValue;
  1151.         case 5: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_05.IntValue;
  1152.         case 6: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_06.IntValue;
  1153.         case 7: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_07.IntValue;
  1154.         case 8: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_08.IntValue;
  1155.         case 9: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_09.IntValue;
  1156.         case 10: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_10.IntValue;
  1157.         case 11: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_11.IntValue;
  1158.         case 12: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_12.IntValue;
  1159.         case 13: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_13.IntValue;
  1160.         case 14: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_14.IntValue;
  1161.         case 15: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_15.IntValue;
  1162.         case 16: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_16.IntValue;
  1163.         case 17: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_17.IntValue;
  1164.         case 18: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_18.IntValue;
  1165.         case 19: g_iRespawnSeconds = sm_respawn_delay_team_sec_player_count_19.IntValue;
  1166.     }
  1167.     // If not set use default
  1168.     if (g_iRespawnSeconds == -1)
  1169.         g_iRespawnSeconds = sm_respawn_delay_team_sec.IntValue;
  1170.    
  1171.  
  1172.     // Respawn type 2 for players
  1173.     if (g_iCvar_respawn_type_team_sec == 2)
  1174.     {
  1175.         g_iRespawn_lives_team_sec = sm_respawn_lives_team_sec.IntValue;
  1176.     }
  1177.     // Respawn type 2 for bots
  1178.     else if (g_iCvar_respawn_type_team_ins == 2)
  1179.     {
  1180.         // Set base value of remaining lives for team insurgent
  1181.         g_iRespawn_lives_team_ins = -1;
  1182.         switch (GetTeamSecCount())
  1183.         {
  1184.             case 0: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_01.IntValue;
  1185.             case 1: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_01.IntValue;
  1186.             case 2: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_02.IntValue;
  1187.             case 3: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_03.IntValue;
  1188.             case 4: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_04.IntValue;
  1189.             case 5: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_05.IntValue;
  1190.             case 6: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_06.IntValue;
  1191.             case 7: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_07.IntValue;
  1192.             case 8: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_08.IntValue;
  1193.             case 9: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_09.IntValue;
  1194.             case 10: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_10.IntValue;
  1195.             case 11: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_11.IntValue;
  1196.             case 12: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_12.IntValue;
  1197.             case 13: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_13.IntValue;
  1198.             case 14: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_14.IntValue;
  1199.             case 15: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_15.IntValue;
  1200.             case 16: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_16.IntValue;
  1201.             case 17: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_17.IntValue;
  1202.             case 18: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_18.IntValue;
  1203.             case 19: g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins_player_count_19.IntValue;
  1204.         }
  1205.        
  1206.         // If not set, use default
  1207.         if (g_iRespawn_lives_team_ins == -1)
  1208.             g_iRespawn_lives_team_ins = sm_respawn_lives_team_ins.IntValue;
  1209.        
  1210.     }
  1211.    
  1212.     // Counter attack
  1213.     g_flCanSeeVectorMultiplier = cvarCanSeeVectorMultiplier.FloatValue;
  1214.     g_iCvar_counterattack_type = sm_respawn_counterattack_type.IntValue;
  1215.     g_iCvar_counterattack_vanilla = sm_respawn_counterattack_vanilla.IntValue;
  1216.     g_iCvar_final_counterattack_type = sm_respawn_final_counterattack_type.IntValue;
  1217.     g_flMinPlayerDistance = cvarMinPlayerDistance.FloatValue;
  1218.     g_flBackSpawnIncrease = cvarBackSpawnIncrease.FloatValue;
  1219.     g_flMaxPlayerDistance = cvarMaxPlayerDistance.FloatValue;
  1220.     g_flMinObjectiveDistance = cvarMinObjectiveDistance.FloatValue;
  1221.     g_flSpawnAttackDelay = cvarSpawnAttackDelay.FloatValue;
  1222. }
  1223.  
  1224. // When tags changed
  1225. public void TagsChanged(ConVar convar, const char[] oldValue, const char[] newValue)
  1226. {
  1227.     if (sm_respawn_enabled.BoolValue)
  1228.         TagsCheck("respawntimes");
  1229.     else
  1230.         TagsCheck("respawntimes", true);
  1231. }
  1232.  
  1233. // On map starts, call initalizing function
  1234. public OnMapStart()
  1235. {  
  1236.     //Clear player array
  1237.     ClearArray(g_playerArrayList);
  1238.    
  1239.     //roundendblock
  1240.     g_iSecBotID = 0;
  1241.     g_announceTick = g_max_AnnounceTime;
  1242.     g_isCheckpoint = 1;
  1243.     //end roundendblock
  1244.  
  1245.     //Materials for Medic Beams
  1246.     g_iBeaconBeam = PrecacheModel("sprites/laserbeam.vmt");
  1247.     g_iBeaconHalo = PrecacheModel("sprites/halo01.vmt");
  1248.    
  1249.     //Wait until players ready to enable spawn checking
  1250.     g_playersReady = false;
  1251.     g_botsReady = 0;
  1252.  
  1253.     // Wait for navmesh
  1254.     CreateTimer(2.0, Timer_MapStart);
  1255.     g_preRoundInitial = true;
  1256.  
  1257.     CreateTimer(1.0, Timer_AnnounceSaves, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1258. }
  1259.  
  1260. // Init config
  1261. public void OnConfigsExecuted()
  1262. {
  1263.     ServerCommand("exec betterbots.cfg");
  1264.     if (sm_respawn_enabled.BoolValue)
  1265.     {
  1266.         TagsCheck("respawntimes");
  1267.     }
  1268.     else
  1269.     {
  1270.         TagsCheck("respawntimes", true);
  1271.     }
  1272. }
  1273.  
  1274. public OnMapEnd()
  1275. {
  1276.     // Reset respawn token
  1277.     ResetSecurityLives();
  1278.     ResetInsurgencyLives();
  1279.     (g_isMapInit = 0) && (g_botsReady = 0) && (g_iRoundStatus = 0) && (g_iEnableRevive = 0);
  1280. }
  1281.  
  1282. //End Plugin
  1283. public OnPluginEnd()
  1284. {
  1285.     int ent = -1;
  1286.     while ((ent = FindEntityByClassname(ent, "healthkit")) > MaxClients && IsValidEntity(ent))
  1287.         AcceptEntityInput(ent, "Kill");
  1288. }
  1289.  
  1290. // When player connected server, intialize variable
  1291. public void OnClientPutInServer(int client)
  1292. {
  1293.         playerPickSquad[client] = 0;
  1294.         g_trackKillDeaths[client] = 0;
  1295.         g_iHurtFatal[client] = -1;
  1296.         g_playerFirstJoin[client] = 1;
  1297.         g_iPlayerRespawnTimerActive[client] = 0;
  1298.  
  1299.     //SDKHook(client, SDKHook_PreThinkPost, SHook_OnPreThink);
  1300.         char sNickname[64];
  1301.         Format(sNickname, sizeof(sNickname), "%N", client);
  1302.         g_client_org_nickname[client] = sNickname;
  1303. }
  1304.  
  1305. // Initializing
  1306.  
  1307. public Action Timer_MapStart(Handle Timer)
  1308. {
  1309.     // Check is map initialized
  1310.     if (g_isMapInit == 1) return;
  1311.     g_isMapInit = 1;
  1312.  
  1313.     //AI Directory Reset
  1314.     g_AIDir_ReinforceTimer_Orig = FindConVar("sm_respawn_reinforce_time").IntValue;
  1315.     g_AIDir_ReinforceTimer_SubOrig = sm_respawn_reinforce_time_subsequent.IntValue;
  1316.  
  1317.     // Bot Reinforce Times
  1318.     g_iReinforceTime = sm_respawn_reinforce_time.IntValue;
  1319.  
  1320.     // Update cvars
  1321.     UpdateRespawnCvars();
  1322.     g_isCheckpoint = 0;
  1323.    
  1324.     // Reset hiding spot
  1325.     int iEmptyArray[MAX_OBJECTIVES];
  1326.     g_iCPHidingSpotCount = iEmptyArray;
  1327.    
  1328.     // Check gamemode
  1329.     char sGameMode[32];
  1330.     FindConVar("mp_gamemode").GetString(sGameMode, sizeof(sGameMode));
  1331.  
  1332.     if (StrEqual(sGameMode,"checkpoint"))
  1333.     {
  1334.         g_isCheckpoint = 1;
  1335.     }
  1336.  
  1337.     g_iEnableRevive = 0;
  1338.    
  1339.     // Reset respawn token
  1340.     ResetSecurityLives();
  1341.     ResetInsurgencyLives();
  1342.    
  1343.     // Enemy reinforcement announce timer
  1344.     CreateTimer(1.0, Timer_EnemyReinforce, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1345.  
  1346.     // Enemy remaining announce timer
  1347.     CreateTimer(30.0, Timer_Enemies_Remaining, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1348.    
  1349.     // Player status check timer
  1350.     //CreateTimer(1.0, Timer_PlayerStatus, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1351.    
  1352.     // Revive monitor
  1353.     CreateTimer(1.0, Timer_ReviveMonitor, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1354.    
  1355.     // Heal monitor
  1356.     CreateTimer(0.5, Timer_MedicMonitor, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1357.    
  1358.     // Display nearest body for medics
  1359.     CreateTimer(0.1, Timer_NearestBody, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1360.  
  1361.     // Display nearest body for medics
  1362.     CreateTimer(60.0, Timer_AmbientRadio, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1363.  
  1364.     // Monitor ammo resupply
  1365.     //CreateTimer(1.0, Timer_AmmoResupply, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1366.  
  1367.     // AI Director Tick
  1368.     CreateTimer(1.0, Timer_AIDirector_Main, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1369.  
  1370.     // Squad Spawn Notify Leader
  1371.     //if (GetConVarInt(sm_enable_squad_spawning) == 1)
  1372.     //CreateTimer(1.0, Timer_SquadSpawn_Notify, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1373.  
  1374.     // Elite Period
  1375.     //CreateTimer(1.0, Timer_ElitePeriodTick, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1376.    
  1377.     // Static enemy check timer
  1378.     //g_checkStaticAmt = sm_respawn_check_static_enemy.IntValue;
  1379.     //g_checkStaticAmtCntr = sm_respawn_check_static_enemy_counter.IntValue;
  1380.    
  1381.     //Temp testing
  1382.     //g_checkStaticAmtAway = 30;
  1383.     //g_checkStaticAmtCntrAway = 12;
  1384.    
  1385.     //Elite Bot cvar multipliers (used to minus off top of original cvars)
  1386.     g_bot_attack_aimtolerance_newthreat_amt_mult = 0.8;
  1387.     g_bot_attack_aimpenalty_amt_close_mult = 15;
  1388.     g_bot_attack_aimpenalty_amt_far_mult = 40;
  1389.     g_bot_attackdelay_frac_difficulty_impossible_mult = 0.03;
  1390.     g_bot_attack_aimpenalty_time_close_mult = 0.15;
  1391.     g_bot_attack_aimpenalty_time_far_mult = 2.0;
  1392.     g_coop_delay_penalty_base = 800;
  1393.     g_bot_aim_aimtracking_base = 0.05;
  1394.     g_bot_aim_aimtracking_frac_impossible =  0.05;
  1395.     g_bot_aim_angularvelocity_frac_impossible =  0.05;
  1396.     g_bot_aim_angularvelocity_frac_sprinting_target =  0.05;
  1397.     g_bot_aim_attack_aimtolerance_frac_impossible =  0.05;
  1398.  
  1399.     //Get Originals
  1400.     g_ins_bot_count_checkpoint_max_org = FindConVar("ins_bot_count_checkpoint_max").IntValue;
  1401.     g_mp_player_resupply_coop_delay_max_org = FindConVar("mp_player_resupply_coop_delay_max").IntValue;
  1402.     g_mp_player_resupply_coop_delay_penalty_org = FindConVar("mp_player_resupply_coop_delay_penalty").IntValue;
  1403.     g_mp_player_resupply_coop_delay_base_org = FindConVar("mp_player_resupply_coop_delay_base").IntValue;
  1404.     g_bot_attack_aimpenalty_amt_close_org = FindConVar("bot_attack_aimpenalty_amt_close").IntValue;
  1405.     g_bot_attack_aimpenalty_amt_far_org = FindConVar("bot_attack_aimpenalty_amt_far").IntValue;
  1406.     g_bot_attack_aimpenalty_time_close_org = FindConVar("bot_attack_aimpenalty_time_close").FloatValue;
  1407.     g_bot_attack_aimpenalty_time_far_org = FindConVar("bot_attack_aimpenalty_time_far").FloatValue;
  1408.     g_bot_attack_aimtolerance_newthreat_amt_org = FindConVar("bot_attack_aimtolerance_newthreat_amt").FloatValue;
  1409.     g_bot_attackdelay_frac_difficulty_impossible_org = FindConVar("bot_attackdelay_frac_difficulty_impossible").FloatValue;
  1410.     g_bot_aim_aimtracking_base_org = FindConVar("bot_aim_aimtracking_base").FloatValue;
  1411.     g_bot_aim_aimtracking_frac_impossible_org = FindConVar("bot_aim_aimtracking_frac_impossible").FloatValue;
  1412.     g_bot_aim_angularvelocity_frac_impossible_org = FindConVar("bot_aim_angularvelocity_frac_impossible").FloatValue;
  1413.     g_bot_aim_angularvelocity_frac_sprinting_target_org = FindConVar("bot_aim_angularvelocity_frac_sprinting_target").FloatValue;
  1414.     g_bot_aim_attack_aimtolerance_frac_impossible_org = FindConVar("bot_aim_attack_aimtolerance_frac_impossible").FloatValue;
  1415.  
  1416.     //CreateTimer(1.0, Timer_CheckEnemyStatic, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1417.     //CreateTimer(1.0, Timer_CheckEnemyAway, _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  1418. }
  1419.  
  1420. // When player connected server, intialize variables
  1421. public Action Event_PlayerConnect(Event event, const char[] name, bool dontBroadcast) {
  1422.     int client = GetClientOfUserId(event.GetInt("userid"));
  1423.  
  1424.     playerPickSquad[client] = 0;
  1425.     g_iHurtFatal[client] = -1;
  1426.     g_playerFirstJoin[client] = 1;
  1427.     g_iPlayerRespawnTimerActive[client] = 0;
  1428.  
  1429.     //g_fPlayerLastChat[client] = GetGameTime();
  1430.  
  1431.     //Update RespawnCvars when players join
  1432.     UpdateRespawnCvars();
  1433. }
  1434.  
  1435. // When player disconnected server, intialize variables
  1436. public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast)
  1437. {
  1438.     int client = GetClientOfUserId(event.GetInt("userid"));
  1439.     if (client > 0)
  1440.     {
  1441.         g_squadSpawnEnabled[client] = 0;
  1442.         playerPickSquad[client] = 0;
  1443.    
  1444.         // Reset player status
  1445.         //reset his class model
  1446.         g_client_last_classstring[client] = "";
  1447.    
  1448.         // Remove network ragdoll associated with player
  1449.         int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  1450.         if (playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  1451.         {
  1452.             RemoveRagdoll(client);
  1453.         }
  1454.  
  1455.         // Update cvar
  1456.         UpdateRespawnCvars();
  1457.     }
  1458.     g_LastButtons[client] = 0;
  1459.     return Plugin_Continue;
  1460. }
  1461.  
  1462. public Action Timer_AnnounceSaves(Handle timer, any data)
  1463. {
  1464.  
  1465.     g_announceTick--;
  1466.     if (g_announceTick <= 0)
  1467.     {
  1468.         //char textToPrint[64];
  1469.         char textToHint[64];
  1470.         //Format(textToPrint, sizeof(textToPrint), "\x03[INTEL] Remaining Security Reinforcements: %d", g_iRoundBlockCount);
  1471.         Format(textToHint, sizeof(textToHint), "\x03[INTEL] Remaining Security Reinforcements: %d", g_iRoundBlockCount);
  1472.         //PrintToChatAll(textToPrint);
  1473.         PrintHintTextToAll(textToHint);
  1474.         g_announceTick = g_max_AnnounceTime;
  1475.     }
  1476. }
  1477.  
  1478.  
  1479. // Console command for reload config
  1480. public Action Command_Reload(int client, int args)
  1481. {
  1482.     ServerCommand("exec sourcemod/respawn.cfg");
  1483.  
  1484.     //Reset respawn token
  1485.     ResetSecurityLives();
  1486.     ResetInsurgencyLives();
  1487.    
  1488.     //PrintToServer("[RESPAWN] %N reloaded respawn config.", client);
  1489.     ReplyToCommand(client, "[SM] Reloaded 'sourcemod/respawn.cfg' file.");
  1490. }
  1491.  
  1492.  
  1493.  
  1494. // Respawn function for console command
  1495. public Action Command_Respawn(int client, int args) {
  1496.     // Check argument
  1497.     if (args < 1) {
  1498.         ReplyToCommand(client, "[SM] Usage: sm_player_respawn <#userid|name>");
  1499.         return Plugin_Handled;
  1500.     }
  1501.  
  1502.     // Retrive argument
  1503.     char arg[65];
  1504.     GetCmdArg(1, arg, sizeof(arg));
  1505.     char target_name[MAX_TARGET_LENGTH];
  1506.     int[] target_list = new int[MaxClients];
  1507.     int target_count;
  1508.     bool tn_is_ml;
  1509.  
  1510.     // Get target count
  1511.     target_count = ProcessTargetString(
  1512.                     arg,
  1513.                     client,
  1514.                     target_list,
  1515.                     MaxClients,
  1516.                     COMMAND_FILTER_DEAD,
  1517.                     target_name,
  1518.                     sizeof(target_name),
  1519.                     tn_is_ml);
  1520.  
  1521.     // Check target count
  1522.     // If we don't have dead players
  1523.     if (target_count <= COMMAND_TARGET_NONE)  {
  1524.         ReplyToTargetError(client, target_count);
  1525.         return Plugin_Handled;
  1526.     }
  1527.  
  1528.     // Team filter dead players, re-order target_list array with new_target_count
  1529.     int target;
  1530.     int team;
  1531.  
  1532.     int new_target_count;
  1533.  
  1534.  
  1535.     // Check team
  1536.     for (int i = 0; i < target_count; i++) {
  1537.         target = target_list[i];
  1538.         team = GetClientTeam(target);
  1539.  
  1540.         if (team >= 2) {
  1541.             // re-order
  1542.             target_list[new_target_count] = target;
  1543.             new_target_count++;
  1544.         }
  1545.     }
  1546.  
  1547.     // Check target count
  1548.     // No dead players from  team 2 and 3
  1549.     if (new_target_count == COMMAND_TARGET_NONE)  {
  1550.         ReplyToTargetError(client, new_target_count);
  1551.         return Plugin_Handled;
  1552.     }
  1553.     // re-set new value.
  1554.     target_count = new_target_count;
  1555.  
  1556.     // If target exists
  1557.     if (tn_is_ml) {
  1558.         ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", target_name);
  1559.     }
  1560.     else {
  1561.         ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", "_s", target_name);
  1562.     }
  1563.  
  1564.     // Process respawn
  1565.     for (int i = 0; i < target_count; i++) {
  1566.         RespawnPlayer(client, target_list[i]);
  1567.     }
  1568.  
  1569.     return Plugin_Handled;
  1570. }
  1571.  
  1572. Action Timer_EliteBots(Handle Timer)
  1573. {
  1574.     // Get the number of control points
  1575.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  1576.     // Get active push point
  1577.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  1578.     if (Ins_InCounterAttack())
  1579.     {      
  1580.         if ((acp+1) == ncp)
  1581.             g_isEliteCounter = 1;
  1582.         else
  1583.             g_isEliteCounter = 1;
  1584.     }
  1585. }
  1586.  
  1587. // Respawn player
  1588. void RespawnPlayer(int client, int target)
  1589. {
  1590.     int team = GetClientTeam(target);
  1591.     if(IsClientInGame(target) && !IsClientTimingOut(target) && g_client_last_classstring[target][0]
  1592.         && playerPickSquad[target] == 1 && !IsPlayerAlive(target) && team == TEAM_1_SEC)
  1593.    
  1594.     // Write a log
  1595.     {
  1596.         LogAction(client, target, "\"%L\" respawned \"%L\"", client, target);
  1597.  
  1598.         // Call force respawn function
  1599.         SDKCall(g_hForceRespawn, target);
  1600.     }
  1601. }
  1602.  
  1603. // ForceRespawnPlayer player
  1604. void ForceRespawnPlayer(int client, int target)
  1605. {
  1606.     int team = GetClientTeam(target);
  1607.     if(IsClientInGame(target) && !IsClientTimingOut(target) && g_client_last_classstring[target][0]
  1608.         && playerPickSquad[target] == 1 && team == TEAM_1_SEC)
  1609.     {
  1610.         // Write a log
  1611.         LogAction(client, target, "\"%L\" respawned \"%L\"", client, target);
  1612.        
  1613.         // Call force respawn fucntion
  1614.         SDKCall(g_hForceRespawn, target);
  1615.     }
  1616. }
  1617.  
  1618. // Announce enemies remaining
  1619. Action Timer_Enemies_Remaining(Handle Timer)
  1620. {
  1621.     // Check round state
  1622.     if (g_iRoundStatus == 0) return Plugin_Continue;
  1623.  
  1624.     // Check enemy count
  1625.     int alive_insurgents;
  1626.     for (int i = 1; i <= MaxClients; i++)
  1627.     {
  1628.         if (IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && IsFakeClient(i))
  1629.             alive_insurgents++;
  1630.     }
  1631.     //sm_medpack_health_amount new validAntenna = -1;
  1632.     //validAntenna = FindValid_Antenna();
  1633.     //if (validAntenna != -1 || g_jammerRequired == 0)
  1634.     // Announce
  1635.     //decl String:textToPrintChat[64];
  1636.     char textToPrint[32];
  1637.     //Format(textToPrintChat, sizeof(textToPrintChat), "[INTEL]Enemies alive: %d | Enemy reinforcements left: %d", alive_insurgents, g_iRemaining_lives_team_ins);
  1638.     Format(textToPrint, sizeof(textToPrint), "[INTEL]Enemies alive: %d", alive_insurgents);
  1639.     PrintHintTextToAll(textToPrint);
  1640.         //PrintToChatAll(textToPrintChat);
  1641.  
  1642.     int timeReduce = (GetTeamSecCount() / 3);
  1643.     if (timeReduce <= 0)
  1644.         timeReduce = 3;
  1645.     return Plugin_Continue;
  1646. }
  1647.  
  1648. void AI_Director_RandomEnemyReinforce()
  1649. {
  1650.     char textToPrint[64];
  1651.     //Only add more reinforcements if under certain amount so its not endless.
  1652.     if (g_iRemaining_lives_team_ins > 0)
  1653.     {
  1654.             // Get bot count
  1655.             int minBotCount = (g_iRespawn_lives_team_ins / 5);
  1656.             g_iRemaining_lives_team_ins = g_iRemaining_lives_team_ins + minBotCount;
  1657.             Format(textToPrint, sizeof(textToPrint), "[INTEL]Ambush Reinforcements Added to Existing Reinforcements!");
  1658.            
  1659.             //AI Director Reinforcement START
  1660.             g_AIDir_BotReinforceTriggered = true;
  1661.             g_AIDir_TeamStatus -= 5;
  1662.             g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  1663.             //AI Director Reinforcement END
  1664.  
  1665.             PrintHintTextToAll(textToPrint);
  1666.             g_iReinforceTime = g_iReinforceTimeSubsequent_AD_Temp;
  1667.  
  1668.             //Lower Bot Flank spawning on reinforcements
  1669.             g_dynamicSpawn_Perc = 0;
  1670.  
  1671.             // Add bots
  1672.             for (int client = 1; client <= MaxClients; client++)
  1673.             {
  1674.                 if (client > 0 && IsClientInGame(client))
  1675.                 {
  1676.                     int m_iTeam = GetClientTeam(client);
  1677.                     if (IsFakeClient(client) && !IsPlayerAlive(client) && m_iTeam == TEAM_2_INS)
  1678.                     {
  1679.                         g_iRemaining_lives_team_ins++;
  1680.                         CreateBotRespawnTimer(client);
  1681.                     }
  1682.                 }
  1683.             }
  1684.            
  1685.             //Reset bot back spawning to default
  1686.             CreateTimer(45.0, Timer_ResetBotFlankSpawning, _);
  1687.     }
  1688.     else
  1689.     {
  1690.         // Get bot count
  1691.         int minBotCount = (g_iRespawn_lives_team_ins / 5);
  1692.         g_iRemaining_lives_team_ins = g_iRemaining_lives_team_ins + minBotCount;
  1693.  
  1694.         //Lower Bot Flank spawning on reinforcements
  1695.         g_dynamicSpawn_Perc = 0;
  1696.  
  1697.         // Add bots
  1698.         for (int client = 1; client <= MaxClients; client++)
  1699.         {
  1700.             if (client > 0 && IsClientInGame(client))
  1701.             {
  1702.                 int m_iTeam = GetClientTeam(client);
  1703.                 if (IsFakeClient(client) && !IsPlayerAlive(client) && m_iTeam == TEAM_2_INS)
  1704.                 {
  1705.                     g_iRemaining_lives_team_ins++;
  1706.                     CreateBotRespawnTimer(client);
  1707.                 }
  1708.             }
  1709.         }
  1710.         g_iReinforceTime = g_iReinforceTimeSubsequent_AD_Temp;
  1711.  
  1712.         //Reset bot back spawning to default
  1713.         CreateTimer(45.0, Timer_ResetBotFlankSpawning, _);
  1714.  
  1715.         // Get random duration
  1716.         //new fRandomInt = GetRandomInt(1, 4);
  1717.  
  1718.         Format(textToPrint, sizeof(textToPrint), "[INTEL]Enemy Ambush Reinforcement Incoming!");
  1719.  
  1720.         //AI Director Reinforcement START
  1721.         g_AIDir_BotReinforceTriggered = true;
  1722.         g_AIDir_TeamStatus -= 5;
  1723.         g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  1724.  
  1725.         //AI Director Reinforcement END
  1726.  
  1727.         PrintHintTextToAll(textToPrint);
  1728.     }
  1729. }
  1730.  
  1731. // This timer reinforces bot team if you do not capture point
  1732. Action Timer_EnemyReinforce(Handle Timer)
  1733. {
  1734.     // Check round state
  1735.     if (g_iRoundStatus == 0) return Plugin_Continue;
  1736.    
  1737.     // Check enemy remaining
  1738.     if (g_iRemaining_lives_team_ins <= (g_iRespawn_lives_team_ins / g_iReinforce_Mult) + g_iReinforce_Mult_Base)
  1739.     {
  1740.         g_iReinforceTime--;
  1741.         char textToPrint[64];
  1742.         // Announce every 10 seconds
  1743.         if (g_iReinforceTime % 10 == 0 && g_iReinforceTime > 10)
  1744.         {
  1745.                 Format(textToPrint, sizeof(textToPrint), "Allied forces spawn on counter-attacks, capture the point!");
  1746.                 PrintHintTextToAll(textToPrint);
  1747.         }
  1748.         // Announce every 1 second
  1749.         if (g_iReinforceTime <= 10)
  1750.         {
  1751.             Format(textToPrint, sizeof(textToPrint), "ISIS reinforce in %d seconds | capture point soon!", g_iReinforceTime);
  1752.             PrintHintTextToAll(textToPrint);
  1753.         }
  1754.         // Process reinforcement
  1755.         if (g_iReinforceTime <= 0)
  1756.         {
  1757.             // If enemy reinforcement is not over, add it
  1758.             if (g_iRemaining_lives_team_ins > 0)
  1759.             {
  1760.                 //Only add more reinforcements if under certain amount so its not endless.
  1761.                 if (g_iRemaining_lives_team_ins < (g_iRespawn_lives_team_ins / g_iReinforce_Mult) + g_iReinforce_Mult_Base)
  1762.                 {
  1763.                     // Get bot count
  1764.                     int minBotCount = (g_iRespawn_lives_team_ins / 4);
  1765.                     g_iRemaining_lives_team_ins = g_iRemaining_lives_team_ins + minBotCount;
  1766.                     Format(textToPrint, sizeof(textToPrint), "ISIS terrorists have arrived!");
  1767.                    
  1768.                     //AI Director Reinforcement START
  1769.                     g_AIDir_BotReinforceTriggered = true;
  1770.                     g_AIDir_TeamStatus -= 5;
  1771.                     g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  1772.                     //AI Director Reinforcement END
  1773.  
  1774.                     PrintHintTextToAll(textToPrint);
  1775.                     g_iReinforceTime = g_iReinforceTimeSubsequent_AD_Temp;
  1776.  
  1777.                     //Lower Bot Flank spawning on reinforcements
  1778.                     g_dynamicSpawn_Perc = 0;
  1779.  
  1780.                     // Add bots
  1781.                     for (int client = 1; client <= MaxClients; client++)
  1782.                     {
  1783.                         if (client > 0 && IsClientInGame(client))
  1784.                         {
  1785.                             int m_iTeam = GetClientTeam(client);
  1786.                             if (IsFakeClient(client) && !IsPlayerAlive(client) && m_iTeam == TEAM_2_INS)
  1787.                             {
  1788.                                 g_iRemaining_lives_team_ins++;
  1789.                                 CreateBotRespawnTimer(client);
  1790.                             }
  1791.                         }
  1792.                     }
  1793.                    
  1794.                     //Reset bot back spawning to default
  1795.                     CreateTimer(45.0, Timer_ResetBotFlankSpawning, _);
  1796.                 }
  1797.                 else
  1798.                 {
  1799.                
  1800.                     // Reset reinforce time
  1801.                     g_iReinforceTime = g_iReinforceTime_AD_Temp;
  1802.                 }
  1803.             }
  1804.  
  1805.             // Respawn enemies
  1806.             else
  1807.             {
  1808.                 // Get bot count
  1809.                 int minBotCount = (g_iRespawn_lives_team_ins / 4);
  1810.                 g_iRemaining_lives_team_ins = g_iRemaining_lives_team_ins + minBotCount;
  1811.                
  1812.                 //Lower Bot Flank spawning on reinforcements
  1813.                 g_dynamicSpawn_Perc = 0;
  1814.  
  1815.                 // Add bots
  1816.                 for (int client = 1; client <= MaxClients; client++)
  1817.                 {
  1818.                     if (client > 0 && IsClientInGame(client))
  1819.                     {
  1820.                         int m_iTeam = GetClientTeam(client);
  1821.                         if (IsFakeClient(client) && !IsPlayerAlive(client) && m_iTeam == TEAM_2_INS)
  1822.                         {
  1823.                             g_iRemaining_lives_team_ins++;
  1824.                             CreateBotRespawnTimer(client);
  1825.                         }
  1826.                     }
  1827.                 }
  1828.                 g_iReinforceTime = g_iReinforceTimeSubsequent_AD_Temp;
  1829.  
  1830.                 //Reset bot back spawning to default
  1831.                 CreateTimer(45.0, Timer_ResetBotFlankSpawning, _);
  1832.  
  1833.                 // Get random duration
  1834.                 //new fRandomInt = GetRandomInt(1, 4);
  1835.                
  1836.                 Format(textToPrint, sizeof(textToPrint), "ISIS terrorists have now arrived!");
  1837.  
  1838.                 //AI Director Reinforcement START
  1839.                 g_AIDir_BotReinforceTriggered = true;
  1840.                 g_AIDir_TeamStatus -= 5;
  1841.                 g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  1842.  
  1843.                 //AI Director Reinforcement END
  1844.                 PrintHintTextToAll(textToPrint);
  1845.             }
  1846.         }
  1847.     }
  1848.     return Plugin_Continue;
  1849. }
  1850.  
  1851. //Reset bot flank spawning X seconds after reinforcement
  1852. Action Timer_ResetBotFlankSpawning(Handle timer)
  1853. {
  1854.     //Reset bot back spawning to default
  1855.     g_dynamicSpawn_Perc = sm_respawn_dynamic_spawn_percent.IntValue;
  1856.     return Plugin_Continue;
  1857. }
  1858.  
  1859. /*
  1860. // Check enemy is stuck
  1861. public Action Timer_CheckEnemyStatic(Handle timer) {
  1862.     //Remove bot weapons when static killed to reduce server performance on dropped items.
  1863.     int primaryRemove = 1;
  1864.     int secondaryRemove ;
  1865.      grenadesRemove = 1;
  1866.  
  1867.     // Check round state
  1868.     if (g_iRoundStatus == 0) {
  1869.         return Plugin_Continue;
  1870.     }
  1871.  
  1872.     if (Ins_InCounterAttack()) {
  1873.         g_checkStaticAmtCntr = g_checkStaticAmtCntr - 1;
  1874.         if (g_checkStaticAmtCntr <= 0) {
  1875.             for (int enemyBot = 1; enemyBot <= MaxClients; enemyBot++) {
  1876.                 if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot)) {
  1877.                     int m_iTeam = GetClientTeam(enemyBot);
  1878.                     if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS) {
  1879.                         // Get current position
  1880.                         float enemyPos[3];
  1881.                         GetClientAbsOrigin(enemyBot, float enemyPos);
  1882.  
  1883.                         // Get distance
  1884.                         float tDistance;
  1885.                         float capDistance;
  1886.                         tDistance = GetVectorDistance(enemyPos, g_enemyTimerPos[enemyBot]);
  1887.                         if (g_isCheckpoint == 1) {
  1888.                             int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  1889.                             if (0 <= m_nActivePushPointIndex < sizeof(m_vCPPositions))
  1890.                             Ins_ObjectiveResource_GetPropVector(" ", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  1891.                             capDistance = GetVectorDistance(enemyPos, m_vCPPositions[m_nActivePushPointIndex]);
  1892.                         }
  1893.                         else {
  1894.                             capDistance = 801.0;
  1895.                         }
  1896.                         // If enemy position is static, kill him
  1897.                         if (tDistance <= 150 && Check_NearbyPlayers(enemyBot) && (capDistance > 800 || g_botStaticGlobal[enemyBot] > 120)) {
  1898.                             RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
  1899.                             ForcePlayerSuicide(enemyBot);
  1900.                             AddLifeForStaticKilling(enemyBot);
  1901.                             //PrintToServer("ENEMY STATIC - KILLING");
  1902.                             g_badSpawnPos_Track[enemyBot] = enemyPos;
  1903.                             //PrintToServer("Add to g_badSpawnPos_Array | enemyPos: (%f, %f, %f) | g_badSpawnPos_Array Size: %d", enemyPos[0], enemyPos[1], enemyPos[2], g_badSpawnPos_Array.Length);
  1904.                             //g_badSpawnPos_Array.PushArray(enemyPos, sizeof(enemyPos));
  1905.                         }
  1906.                         // Update current position
  1907.                         else {
  1908.                             g_enemyTimerPos[enemyBot] = enemyPos;
  1909.                             g_botStaticGlobal[enemyBot]++;
  1910.                         }
  1911.                     }
  1912.                 }
  1913.             }
  1914.             g_checkStaticAmtCntr = sm_respawn_check_static_enemy_counter.IntValue;
  1915.         }
  1916.     }
  1917.     else {
  1918.         g_checkStaticAmt = g_checkStaticAmt - 1;
  1919.         if (g_checkStaticAmt <= 0) {
  1920.             for (int enemyBot = 1; enemyBot <= MaxClients; enemyBot++) {
  1921.                 if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot)) {
  1922.                     int m_iTeam = GetClientTeam(enemyBot);
  1923.                     if (enemyBot > 0 && IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS) {
  1924.                         // Get current position
  1925.                         float enemyPos[3];
  1926.                         GetClientAbsOrigin(enemyBot, float enemyPos);
  1927.  
  1928.                         // Get distance
  1929.                         float tDistance;
  1930.                         float capDistance;
  1931.                         tDistance = GetVectorDistance(enemyPos, g_enemyTimerPos[enemyBot]);
  1932.                         //Check point distance
  1933.                         if (g_isCheckpoint == 1) {
  1934.                             int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  1935.                             if (0 <= m_nActivePushPointIndex < sizeof(m_vCPPositions))
  1936.                             Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  1937.                             capDistance = GetVectorDistance(enemyPos, m_vCPPositions[m_nActivePushPointIndex]);
  1938.                         }
  1939.                         else {
  1940.                             capDistance = 801.0;
  1941.                         }
  1942.                         // If enemy position is static, kill him
  1943.                         // || g_botStaticGlobal[enemyBot] > 120))
  1944.                         if (tDistance <= 150 && (capDistance > 800) && Check_NearbyPlayers(enemyBot))  {
  1945.                             //PrintToServer("ENEMY STATIC - KILLING");
  1946.                             RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
  1947.                             ForcePlayerSuicide(enemyBot);
  1948.                             AddLifeForStaticKilling(enemyBot);
  1949.                         }
  1950.                         // Update current position
  1951.                         else {
  1952.                             g_enemyTimerPos[enemyBot] = enemyPos;
  1953.                             //g_botStaticGlobal[enemyBot]++;
  1954.                         }
  1955.                     }
  1956.                 }
  1957.             }
  1958.             g_checkStaticAmt = sm_respawn_check_static_enemy.IntValue;
  1959.         }
  1960.     }
  1961.  
  1962.     return Plugin_Continue;
  1963. }
  1964. // Check enemy is stuck
  1965. public Action Timer_CheckEnemyAway(Handle timer) {
  1966.     //Remove bot weapons when static killed to reduce server performance on dropped items.
  1967.     int primaryRemove = 1;
  1968.     int secondaryRemove ;
  1969.      grenadesRemove = 1;
  1970.     // Check round state
  1971.     if (g_iRoundStatus == 0) {
  1972.         return Plugin_Continue;
  1973.     }
  1974.  
  1975.     if (Ins_InCounterAttack()) {
  1976.         g_checkStaticAmtCntrAway = g_checkStaticAmtCntrAway - 1;
  1977.         if (g_checkStaticAmtCntrAway <= 0) {
  1978.             for (int enemyBot = 1; enemyBot <= MaxClients; enemyBot++) {
  1979.                 if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot)) {
  1980.                     int m_iTeam = GetClientTeam(enemyBot);
  1981.                     if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS) {
  1982.                         // Get current position
  1983.                         float enemyPos[3];
  1984.                         GetClientAbsOrigin(enemyBot, float enemyPos);
  1985.  
  1986.                         // Get distance
  1987.                         float tDistance;
  1988.                         float capDistance;
  1989.                         tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
  1990.                         if (g_isCheckpoint == 1) {
  1991.                             int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  1992.                             Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  1993.                             capDistance = GetVectorDistance(enemyPos, m_vCPPositions[m_nActivePushPointIndex]);
  1994.                         }
  1995.                         else {
  1996.                             capDistance = 801.0;
  1997.                         }
  1998.                         // If enemy position is static, kill him
  1999.                         if (tDistance <= 150 && capDistance > 2500) {
  2000.                             //PrintToServer("ENEMY STATIC - KILLING");
  2001.                             RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
  2002.                             ForcePlayerSuicide(enemyBot);
  2003.                             AddLifeForStaticKilling(enemyBot);
  2004.                         }
  2005.                         // Update current position
  2006.                         else {
  2007.                             g_enemyTimerAwayPos[enemyBot] = enemyPos;
  2008.                         }
  2009.                     }
  2010.                 }
  2011.             }
  2012.             g_checkStaticAmtCntrAway = 12;
  2013.         }
  2014.     }
  2015.     else {
  2016.         g_checkStaticAmtAway = g_checkStaticAmtAway - 1;
  2017.         if (g_checkStaticAmtAway <= 0) {
  2018.             for (int enemyBot = 1; enemyBot <= MaxClients; enemyBot++) {
  2019.                 if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot)) {
  2020.                     int m_iTeam = GetClientTeam(enemyBot);
  2021.                     if (enemyBot > 0 && IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS) {
  2022.                         // Get current position
  2023.                         float enemyPos[3];
  2024.                         GetClientAbsOrigin(enemyBot, float enemyPos);
  2025.  
  2026.                         // Get distance
  2027.                         float tDistance;
  2028.                         float capDistance;
  2029.                         tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
  2030.                         //Check point distance
  2031.                         if (g_isCheckpoint == 1) {
  2032.                             int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2033.                             if (0 <= m_nActivePushPointIndex < sizeof(m_vCPPositions))
  2034.                             Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2035.                             capDistance = GetVectorDistance(enemyPos, m_vCPPositions[m_nActivePushPointIndex]);
  2036.                         }
  2037.                         // If enemy position is static, kill him
  2038.                         if (tDistance <= 150 && capDistance > 1200) {
  2039.                             //PrintToServer("ENEMY STATIC - KILLING");
  2040.                             RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
  2041.                             ForcePlayerSuicide(enemyBot);
  2042.                             AddLifeForStaticKilling(enemyBot);
  2043.                         }
  2044.                         // Update current position
  2045.                         else {
  2046.                             g_enemyTimerAwayPos[enemyBot] = enemyPos;
  2047.                         }
  2048.                     }
  2049.                 }
  2050.             }
  2051.             g_checkStaticAmtAway = 30;
  2052.         }
  2053.     }
  2054.  
  2055.     return Plugin_Continue;
  2056. }
  2057.  
  2058. void AddLifeForStaticKilling(int client) {
  2059.     // Respawn type 1
  2060.     int team = GetClientTeam(client);
  2061.     if (g_iCvar_respawn_type_team_ins == 1 && team == TEAM_2_INS && g_iRespawn_lives_team_ins > 0) {
  2062.         g_iSpawnTokens[client]++;
  2063.     }
  2064.     else if (g_iCvar_respawn_type_team_ins == 2 && team == TEAM_2_INS && g_iRespawn_lives_team_ins > 0) {
  2065.         g_iRemaining_lives_team_ins++;
  2066.     }
  2067. }
  2068. */
  2069.  
  2070. // Update player's gear
  2071. void SetPlayerAmmo(int client)
  2072. {
  2073.     if (IsClientInGame(client) && !IsFakeClient(client))
  2074.     {
  2075.         int primaryWeapon = GetPlayerWeaponSlot(client, 0);
  2076.         int secondaryWeapon = GetPlayerWeaponSlot(client, 1);
  2077.         int playerGrenades = GetPlayerWeaponSlot(client, 3);
  2078.    
  2079.         //Check primary weapon
  2080.         if (primaryWeapon != -1 && IsValidEntity(primaryWeapon))
  2081.         {
  2082.             SetPrimaryAmmo(client, primaryWeapon, playerClip[client][0], 0); //primary clip
  2083.             Client_SetWeaponPlayerAmmoEx(client, primaryWeapon, playerAmmo[client][0]); //primary
  2084.         }
  2085.        
  2086.         // Check secondary weapon
  2087.         if (secondaryWeapon != -1 && IsValidEntity(secondaryWeapon))
  2088.         {
  2089.             SetPrimaryAmmo(client, secondaryWeapon, playerClip[client][1], 1); //secondary clip
  2090.             Client_SetWeaponPlayerAmmoEx(client, secondaryWeapon, playerAmmo[client][1]); //secondary
  2091.         }
  2092.        
  2093.         // Check grenades
  2094.         if (playerGrenades != -1 && IsValidEntity(playerGrenades)) // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 13
  2095.         {
  2096.             while (playerGrenades != -1 && IsValidEntity(playerGrenades)) // since we only have 3 slots in current theate
  2097.             {
  2098.                 playerGrenades = GetPlayerWeaponSlot(client, 3);
  2099.                 if (playerGrenades != -1 && IsValidEntity(playerGrenades)) // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 1
  2100.                 {
  2101.                    
  2102.  
  2103.                     // Remove grenades but not pistols
  2104.                     char weapon[32];
  2105.                     GetEntityClassname(playerGrenades, weapon, sizeof(weapon));
  2106.                     RemovePlayerItem(client,playerGrenades);
  2107.                     AcceptEntityInput(playerGrenades, "kill");
  2108.                    
  2109.                 }
  2110.             }
  2111.         }
  2112.         if (!IsFakeClient(client))
  2113.             playerRevived[client] = false;
  2114.     }
  2115. }
  2116.  
  2117. public Action Event_PlayerReload_Pre(Event event, const char[] name, bool dontBroadcast)
  2118. {
  2119.     int client = GetClientOfUserId(event.GetInt("userid"));
  2120.     if (IsFakeClient(client) && playerInRevivedState[client] == false) return Plugin_Continue;
  2121.     g_playerActiveWeapon[client] = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  2122.     return Plugin_Continue;
  2123. }
  2124.  
  2125. /*
  2126. #####################################################################
  2127. #####################################################################
  2128. #####################################################################
  2129. # Jballous INS_SPAWNPOINT SPAWNING START ############################
  2130. # Jballous INS_SPAWNPOINT SPAWNING START ############################
  2131. #####################################################################
  2132. #####################################################################
  2133. #####################################################################
  2134. */
  2135.  
  2136.  
  2137.  
  2138. int CheckSpawnPoint(float vecSpawn[3], int client, float tObjectiveDistance, int m_nActivePushPointIndex) {
  2139. //Ins_InCounterAttack
  2140.     int m_iTeam = GetClientTeam(client);
  2141.     float distance;
  2142.     float furthest;
  2143.     float closest=-1.0;
  2144.     float vecOrigin[3];
  2145.     //float tBadPos[3];
  2146.  
  2147.     GetClientAbsOrigin(client, vecOrigin);
  2148.     float tMinPlayerDistMult = 0.0;
  2149.  
  2150.     int acp = (Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex") - 1);
  2151.     int acp2 = m_nActivePushPointIndex;
  2152.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  2153.     if (acp == acp2 && !Ins_InCounterAttack()) {
  2154.         tMinPlayerDistMult = g_flBackSpawnIncrease;
  2155.         //PrintToServer("INCREASE SPAWN DISTANCE | acp: %d acp2 %d", acp, acp2);
  2156.     }
  2157.  
  2158.     //Update player spawns before we check against them
  2159.     UpdatePlayerOrigins();
  2160.     //Lets go through checks to find a valid spawn point
  2161.     for (int iTarget = 1; iTarget < MaxClients; iTarget++) {
  2162.         if (!IsValidClient(iTarget)) {
  2163.             continue;
  2164.         }
  2165.         if (!IsClientInGame(iTarget)) {
  2166.             continue;
  2167.         }
  2168.         if (!IsPlayerAlive(iTarget)) {
  2169.             continue;
  2170.         }
  2171.         int tTeam = GetClientTeam(iTarget);
  2172.         if (tTeam != TEAM_1_SEC) {
  2173.             continue;
  2174.         }
  2175.         ////InsLog(DEBUG, "Distance from %N to iSpot %d is %f", iTarget, iSpot, distance);
  2176.         distance = GetVectorDistance(vecSpawn, g_vecOrigin[iTarget]);
  2177.         if (distance > furthest) {
  2178.             furthest = distance;
  2179.         }
  2180.         if ((distance < closest) || (closest < 0)) {
  2181.             closest = distance;
  2182.         }
  2183.  
  2184.         if (GetClientTeam(iTarget) != m_iTeam) {
  2185.             // If we are too close
  2186.             if (distance < (g_flMinPlayerDistance + tMinPlayerDistMult)) {
  2187.                  return 0;
  2188.             }
  2189.             // If the player can see the spawn point (divided CanSeeVector to slightly reduce strictness)
  2190.             //(IsVectorInSightRange(iTarget, vecSpawn, 120.0)) ||  / g_flCanSeeVectorMultiplier
  2191.             if (ClientCanSeeVector(iTarget, vecSpawn, (g_flMinPlayerDistance * g_flCanSeeVectorMultiplier))) {
  2192.                 return 0;
  2193.             }
  2194.             //If any player is too far
  2195.             if (closest > g_flMaxPlayerDistance) {
  2196.                 return 0;
  2197.             }
  2198.             else if (closest > 2000 && g_cacheObjActive == 1 && Ins_InCounterAttack()) {
  2199.                 return 0;
  2200.             }
  2201.         }
  2202.     }
  2203.  
  2204.     Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2205.     distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2206.     if (distance > (tObjectiveDistance) && (((acp+1) != ncp) || !Ins_InCounterAttack())) {
  2207.         return 0;
  2208.     }
  2209.     else if (distance > (tObjectiveDistance * g_DynamicRespawn_Distance_mult) &&
  2210.     (((acp+1) != ncp) || !Ins_InCounterAttack())) {
  2211.         return 0;
  2212.     }
  2213.  
  2214.  
  2215. //  if ((0 >= client || client > MaxClients) || !IsClientInGame(client)) return 0;
  2216.     if ((0 < client <= MaxClients) || !IsClientInGame(client)) {
  2217.         return 0;
  2218.     }
  2219.  
  2220.     int fRandomInt = GetRandomInt(1, 100);
  2221.     //If final point respawn around last point, not final point
  2222.     if ((((acp+1) == ncp) || Ins_InCounterAttack()) && fRandomInt <= 10) {
  2223.         int m_nActivePushPointIndexFinal = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2224.         m_nActivePushPointIndexFinal -= 1;
  2225.         distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndexFinal]);
  2226.         if (distance > (tObjectiveDistance)) {
  2227.              return 0;
  2228.         }
  2229.         else if (distance > (tObjectiveDistance * g_DynamicRespawn_Distance_mult)) {
  2230.              return 0;
  2231.         }
  2232.     }
  2233.         //PrintToServer("CHECKSPAWN | m_nActivePushPointIndex: %d", m_nActivePushPointIndex);
  2234.     return 1;
  2235. }
  2236.  
  2237.  
  2238.  
  2239. int CheckSpawnPointPlayers(float vecSpawn[3], int client, float tObjectiveDistance) {
  2240. //Ins_InCounterAttack
  2241.     int m_iTeam = GetClientTeam(client);
  2242.     float distance;
  2243.     float furthest;
  2244.     float closest=-1.0;
  2245.     float vecOrigin[3];
  2246.     GetClientAbsOrigin(client, vecOrigin);
  2247.     //Update player spawns before we check against them
  2248.     UpdatePlayerOrigins();
  2249.  
  2250.     int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2251.     float objDistance;
  2252.  
  2253.     //Lets go through checks to find a valid spawn point
  2254.     for (int iTarget = 1; iTarget < MaxClients; iTarget++) {
  2255.         if (!IsValidClient(iTarget)) {
  2256.             continue;
  2257.         }
  2258.         if (!IsClientInGame(iTarget)) {
  2259.             continue;
  2260.         }
  2261.         if (!IsPlayerAlive(iTarget)) {
  2262.             continue;
  2263.         }
  2264.         int tTeam = GetClientTeam(iTarget);
  2265.         if (tTeam != TEAM_1_SEC) {
  2266.             continue;
  2267.         }
  2268.  
  2269.         m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2270.  
  2271.         //If in counter
  2272.         if (Ins_InCounterAttack() && m_nActivePushPointIndex > 0) {
  2273.             m_nActivePushPointIndex -= 1;
  2274.         }
  2275.  
  2276.         Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2277.  
  2278.         objDistance = GetVectorDistance(g_vecOrigin[iTarget], m_vCPPositions[m_nActivePushPointIndex]);
  2279.         distance = GetVectorDistance(vecSpawn, g_vecOrigin[iTarget]);
  2280.         if (distance > furthest) {
  2281.             furthest = distance;
  2282.         }
  2283.         if ((distance < closest) || (closest < 0)) {
  2284.             closest = distance;
  2285.         }
  2286.  
  2287.         if (GetClientTeam(iTarget) != m_iTeam) {
  2288.             // If we are too close
  2289.             if (distance < g_flMinPlayerDistance) {
  2290.                  return 0;
  2291.             }
  2292.             int fRandomInt = GetRandomInt(1, 100);
  2293.  
  2294.             // If the player can see the spawn point (divided CanSeeVector to slightly reduce strictness)
  2295.             //(IsVectorInSightRange(iTarget, vecSpawn, 120.0)) ||  / g_flCanSeeVectorMultiplier
  2296.             if (ClientCanSeeVector(iTarget, vecSpawn, (g_flMinPlayerDistance * g_flCanSeeVectorMultiplier))) {
  2297.                 return 0;
  2298.             }
  2299.  
  2300.             //Check if players are getting close to point when assaulting
  2301.             if (objDistance < 2500 && fRandomInt < 30 && !Ins_InCounterAttack()) {
  2302.                 return 0;
  2303.             }
  2304.         }
  2305.     }
  2306.  
  2307.  
  2308.     // Get the number of control points
  2309.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  2310.  
  2311.     // Get active push point
  2312.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2313.  
  2314.     //If any player is too far
  2315.     if (closest > g_flMaxPlayerDistance) {
  2316.         return 0;
  2317.     }
  2318.     else if (closest > 2000 && g_cacheObjActive == 1 && Ins_InCounterAttack()) {
  2319.         return 0;
  2320.     }
  2321.  
  2322.     m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2323.  
  2324.     int fRandomInt = GetRandomInt(1, 100);
  2325.     //Check against back spawn if in counter
  2326.     if (Ins_InCounterAttack() && m_nActivePushPointIndex > 0)
  2327.     {
  2328.         m_nActivePushPointIndex -= 1;
  2329.     }
  2330.  
  2331.     Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2332.     objDistance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2333.     // && (fRandomFloat <= g_dynamicSpawn_Perc))
  2334.     if (objDistance > (tObjectiveDistance) && (((acp+1) != ncp) || !Ins_InCounterAttack()) && fRandomInt < 25)
  2335.     {
  2336.          return 0;
  2337.     }
  2338.     else if (objDistance > (tObjectiveDistance * g_DynamicRespawn_Distance_mult) && (((acp+1) != ncp) || !Ins_InCounterAttack()) && fRandomInt < 25) {
  2339.          return 0;
  2340.     }
  2341.  
  2342.     fRandomInt = GetRandomInt(1, 100);
  2343.  
  2344.     //if ((0 >= client || client > MaxClients) || !IsClientInGame(client)) return 0;
  2345.     if ((0 < client <= MaxClients) || !IsClientInGame(client))
  2346.     {
  2347.         return 0;
  2348.     }
  2349.  
  2350.     //If final point respawn around last point, not final point
  2351.     if ((((acp+1) == ncp) || Ins_InCounterAttack()) && fRandomInt < 25) {
  2352.         int m_nActivePushPointIndexFinal = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2353.         if (m_nActivePushPointIndexFinal < 0) {
  2354.             return 0;
  2355.         }
  2356.         m_nActivePushPointIndexFinal -= 1;
  2357.         objDistance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndexFinal]);
  2358.         // && (fRandomFloat <= g_dynamicSpawn_Perc))
  2359.         if (objDistance > (tObjectiveDistance)) {
  2360.              return 0;
  2361.         }
  2362.         if (objDistance > (tObjectiveDistance * g_DynamicRespawn_Distance_mult)) {
  2363.              return 0;
  2364.         }
  2365.     }
  2366.     return 1;
  2367. }
  2368.  
  2369. int GetPushPointIndex(float fRandomFloat, int client) {
  2370.     // Get the number of control points
  2371.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  2372.  
  2373.     // Get active push point
  2374.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2375.  
  2376.     int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2377.     //Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2378.     //float distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2379.     //Check last point
  2380.  
  2381.     if (((acp+1) == ncp && Ins_InCounterAttack()) || g_spawnFrandom[client] < g_dynamicSpawnCounter_Perc ||
  2382.         (Ins_InCounterAttack()) || (m_nActivePushPointIndex > 1)) {
  2383.         //PrintToServer("###POINT_MOD### | fRandomFloat: %f | g_dynamicSpawnCounter_Perc %f ", fRandomFloat, g_dynamicSpawnCounter_Perc);
  2384.         if ((acp+1) == ncp && Ins_InCounterAttack()) {
  2385.             if (g_spawnFrandom[client] < g_dynamicSpawnCounter_Perc) {
  2386.                 m_nActivePushPointIndex--;
  2387.             }
  2388.         }
  2389.         else {
  2390.             if (Ins_InCounterAttack() && (acp+1) != ncp) {
  2391.                 if (fRandomFloat <= 0.5 && m_nActivePushPointIndex > 0) {
  2392.                     m_nActivePushPointIndex--;
  2393.                 }
  2394.                 else {
  2395.                     m_nActivePushPointIndex++;
  2396.                 }
  2397.             }
  2398.             else if (!Ins_InCounterAttack()) {
  2399.                 if (m_nActivePushPointIndex > 0) {
  2400.                     if (g_spawnFrandom[client] < g_dynamicSpawn_Perc) {
  2401.                         m_nActivePushPointIndex--;
  2402.                     }
  2403.                 }
  2404.             }
  2405.         }
  2406.  
  2407.     }
  2408.     return m_nActivePushPointIndex;
  2409. }
  2410.  
  2411.  
  2412.  
  2413. float GetSpawnPoint_SpawnPoint(int client) {
  2414. //  int m_iTeam = GetClientTeam(client);
  2415. //  int m_iTeamNum;
  2416.     float vecSpawn[3];
  2417.     float vecOrigin[3];
  2418.     //float distance;
  2419.  
  2420.     GetClientAbsOrigin(client, vecOrigin);
  2421.     float fRandomFloat = GetRandomFloat(0.0, 1.0);
  2422.  
  2423.     //PrintToServer("GetSpawnPoint_SpawnPoint Call");
  2424.     // Get the number of control points
  2425.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  2426.  
  2427.     // Get active push point
  2428.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2429.  
  2430.     int m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2431.     if (((acp+1) == ncp) || (Ins_InCounterAttack() &&
  2432.         g_spawnFrandom[client] < g_dynamicSpawnCounter_Perc) ||
  2433.         (!Ins_InCounterAttack() && g_spawnFrandom[client] < g_dynamicSpawn_Perc &&
  2434.         acp > 1))
  2435.         m_nActivePushPointIndex = GetPushPointIndex(fRandomFloat, client);
  2436.  
  2437.     int point = FindEntityByClassname(-1, "ins_spawnpoint");
  2438.     float tObjectiveDistance = g_flMinObjectiveDistance;
  2439.  
  2440.     //if ((0 >= client || client > MaxClients) || !IsClientInGame(client))
  2441.     if ((0 < client <= MaxClients) || !IsClientInGame(client))
  2442.  
  2443.     while (point != -1) {
  2444.         //m_iTeamNum = GetEntProp(point, Prop_Send, "m_iTeamNum");
  2445.         //if (m_iTeamNum == m_iTeam) {
  2446.  
  2447.  
  2448.     GetEntPropVector(point, Prop_Send, "m_vecOrigin", vecSpawn);
  2449.     Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2450.     //distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2451.     if (CheckSpawnPoint(vecSpawn, client, tObjectiveDistance, m_nActivePushPointIndex)) {
  2452.         vecSpawn = GetInsSpawnGround(point, vecSpawn);
  2453.         //new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2454.         //PrintToServer("FOUND! m_nActivePushPointIndex: %d %N (%d) spawnpoint %d Distance: %f tObjectiveDistance: %f g_flMinObjectiveDistance %f RAW ACP: %d", m_nActivePushPointIndex, client, client, point, distance, tObjectiveDistance, g_flMinObjectiveDistance, acp);
  2455.         return vecSpawn;
  2456.     }
  2457.     else {
  2458.         tObjectiveDistance += 4.0;
  2459.     }
  2460.     point = FindEntityByClassname(point, "ins_spawnpoint");
  2461.     }
  2462.     //PrintToServer("1st Pass: Could not find acceptable ins_spawnzone for %N (%d)", client, client);
  2463.     //Lets try again but wider range
  2464.     int point2 = FindEntityByClassname(-1, "ins_spawnpoint");
  2465.     tObjectiveDistance = ((g_flMinObjectiveDistance + 100) * 4);
  2466.     while (point2 != -1) {
  2467.         //m_iTeamNum = GetEntProp(point2, Prop_Send, "m_iTeamNum");
  2468.         //if (m_iTeamNum == m_iTeam) {
  2469.         GetEntPropVector(point2, Prop_Send, "m_vecOrigin", vecSpawn);
  2470.  
  2471.         Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2472.         //distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2473.         if (CheckSpawnPoint(vecSpawn, client, tObjectiveDistance, m_nActivePushPointIndex)) {
  2474.         vecSpawn = GetInsSpawnGround(point2, vecSpawn);
  2475.         //new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2476.         //PrintToServer("FOUND! m_nActivePushPointIndex: %d %N (%d) spawnpoint %d Distance: %f tObjectiveDistance: %f g_flMinObjectiveDistance %f RAW ACP: %d", m_nActivePushPointIndex, client, client, point2, distance, tObjectiveDistance, g_flMinObjectiveDistance, acp);
  2477.         return vecSpawn;
  2478.         }
  2479.             else {
  2480.         tObjectiveDistance += 4.0;
  2481.     }
  2482.     //}
  2483.         point2 = FindEntityByClassname(point2, "ins_spawnpoint");
  2484.     }
  2485.     //PrintToServer("2nd Pass: Could not find acceptable ins_spawnzone for %N (%d)", client, client);
  2486.     //Lets try again but wider range
  2487.     int point3 = FindEntityByClassname(-1, "ins_spawnpoint");
  2488.     tObjectiveDistance = ((g_flMinObjectiveDistance + 100) * 10);
  2489.     while (point3 != -1) {
  2490.         //m_iTeamNum = GetEntProp(point3, Prop_Send, "m_iTeamNum");
  2491.         //if (m_iTeamNum == m_iTeam) {
  2492.         GetEntPropVector(point3, Prop_Send, "m_vecOrigin", vecSpawn);
  2493.         Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2494.         //distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2495.         if (CheckSpawnPoint(vecSpawn, client, tObjectiveDistance, m_nActivePushPointIndex)) {
  2496.             vecSpawn = GetInsSpawnGround(point3, vecSpawn);
  2497.             //new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2498.             //PrintToServer("FOUND! m_nActivePushPointIndex: %d %N (%d) spawnpoint %d Distance: %f tObjectiveDistance: %f g_flMinObjectiveDistance %f RAW ACP: %d", m_nActivePushPointIndex, client, client, point3, distance, tObjectiveDistance, g_flMinObjectiveDistance, acp);
  2499.             return vecSpawn;
  2500.         }
  2501.         else {
  2502.             tObjectiveDistance += 4.0;
  2503.         }
  2504.         //}
  2505.         point3 = FindEntityByClassname(point3, "ins_spawnpoint");
  2506.     }
  2507.     //PrintToServer("3rd Pass: Could not find acceptable ins_spawnzone for %N (%d)", client, client);
  2508.     int pointFinal = FindEntityByClassname(-1, "ins_spawnpoint");
  2509.     tObjectiveDistance = ((g_flMinObjectiveDistance + 100) * 4);
  2510.     m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2511.     //m_nActivePushPointIndex = GetPushPointIndex(fRandomFloat);
  2512.     if (m_nActivePushPointIndex > 1) {
  2513.         if ((acp+1) >= ncp) {
  2514.             m_nActivePushPointIndex--;
  2515.         }
  2516.         else {
  2517.             m_nActivePushPointIndex++;
  2518.         }
  2519.     }
  2520.  
  2521.     while (pointFinal != -1) {
  2522.         //m_iTeamNum = GetEntProp(pointFinal, Prop_Send, "m_iTeamNum");
  2523.         //if (m_iTeamNum == m_iTeam) {
  2524.         GetEntPropVector(pointFinal, Prop_Send, "m_vecOrigin", vecSpawn);
  2525.         Ins_ObjectiveResource_GetPropVector("m_vCPPositions", m_vCPPositions[m_nActivePushPointIndex], m_nActivePushPointIndex);
  2526.         //distance = GetVectorDistance(vecSpawn, m_vCPPositions[m_nActivePushPointIndex]);
  2527.         if (CheckSpawnPoint(vecSpawn, client, tObjectiveDistance, m_nActivePushPointIndex)) {
  2528.             vecSpawn = GetInsSpawnGround(pointFinal, vecSpawn);
  2529.             //new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2530.             //PrintToServer("FINAL PASS FOUND! m_nActivePushPointIndex: %d %N (%d) spawnpoint %d Distance: %f tObjectiveDistance: %f g_flMinObjectiveDistance: %f RAW ACP: %d", m_nActivePushPointIndex, client, client, pointFinal, distance, tObjectiveDistance, g_flMinObjectiveDistance, acp);
  2531.             return vecSpawn;
  2532.             }
  2533.             else {
  2534.                 tObjectiveDistance += 4.0;
  2535.         }
  2536.         pointFinal = FindEntityByClassname(pointFinal, "ins_spawnpoint");
  2537.     }
  2538.     //PrintToServer("Final Pass: Could not find acceptable ins_spawnzone for %N (%d)", client, client);
  2539.     return vecOrigin;
  2540. }
  2541.  
  2542. float GetSpawnPoint(int client)
  2543. {
  2544.  
  2545.     float vecSpawn[3];
  2546. /*
  2547.     if ((g_iHidingSpotCount) && (g_iSpawnMode == _:SpawnMode_HidingSpots)) {
  2548.         vecSpawn = GetSpawnPoint_HidingSpot(client);
  2549.     } else {
  2550. */
  2551.     vecSpawn = GetSpawnPoint_SpawnPoint(client);
  2552. //  }
  2553.     //InsLog(DEBUG, "Could not find spawn point for %N (%d)", client, client);
  2554.     return vecSpawn;
  2555. }
  2556.  
  2557. //Lets begin to find a valid spawnpoint after spawned
  2558. void TeleportClient(int client) {
  2559.     float vecSpawn[3];
  2560.     vecSpawn = GetSpawnPoint(client);
  2561.     if ((0 < client <= MaxClients) && IsClientInGame(client)) {
  2562.         TeleportEntity(client, vecSpawn, NULL_VECTOR, NULL_VECTOR);
  2563.         SetNextAttack(client);
  2564.     }
  2565. }
  2566.  
  2567. public Action Event_Spawn(Event event, const char[] name, bool dontBroadcast) {
  2568.     //Redirect all bot spawns
  2569.     /*int client = GetClientOfUserId(event.GetInt("userid"));
  2570.     if (0 < client <= MaxClients && IsClientInGame (client)) {
  2571.         if (!IsFakeClient(client)) {
  2572.             g_iPlayerRespawnTimerActive[client] = 0;
  2573.             int iRagDoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
  2574.  
  2575.             if (!IsValidEntity(iRagDoll)) {
  2576.                 return Plugin_Stop;
  2577.             }
  2578.  
  2579.             AcceptEntityInput(iRagDoll, "kill");
  2580.  
  2581.             return Plugin_Stop;
  2582.         }
  2583.         g_iHurtFatal[client] = 0;
  2584.     }*/
  2585.  
  2586.     int client = GetClientOfUserId(event.GetInt("userid"));
  2587.     // char sNewNickname[64];
  2588.     // Format(sNewNickname, sizeof(sNewNickname), "%N", client);
  2589.     // if (StrEqual(sNewNickname, "[INS] RoundEnd Protector"))
  2590.     //  return Plugin_Continue;
  2591.  
  2592.     if (client > 0 && IsClientInGame(client)) {
  2593.         if (!IsFakeClient(client)) {
  2594.             g_iPlayerRespawnTimerActive[client] = 0;
  2595.  
  2596.             //remove network ragdoll associated with player
  2597.             int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  2598.             if (playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag)) {
  2599.                 RemoveRagdoll(client);
  2600.             }
  2601.  
  2602.             g_iHurtFatal[client] = 0;
  2603.         }
  2604.     }
  2605.  
  2606.     g_resupplyCounter[client] = sm_resupply_delay.IntValue;
  2607.     //For first joining players
  2608.     if (g_playerFirstJoin[client] == 1 && !IsFakeClient(client)) {
  2609.         g_playerFirstJoin[client] = 0;
  2610.         // Get SteamID to verify is player has connected before.
  2611.         char steamId[64];
  2612.         //GetClientAuthId(client, AuthId_Steam2, steamId, sizeof(steamId));
  2613.         GetClientAuthId(client, AuthId_Steam3, steamId, sizeof(steamId));
  2614.         int isPlayerNew = g_playerArrayList.FindString(steamId);
  2615.  
  2616.         if (isPlayerNew == -1) {
  2617.             g_playerArrayList.PushString(steamId);
  2618.             //PrintToServer("SPAWN: Player %N is new! | SteamID: %s | PlayerArrayList Size: %d", client, steamId, g_playerArrayList.Length);
  2619.         }
  2620.     }
  2621.     if (!g_iCvar_respawn_enable) {
  2622.         return Plugin_Continue;
  2623.     }
  2624.     if (!IsClientConnected(client)) {
  2625.         return Plugin_Continue;
  2626.     }
  2627.     if (!IsClientInGame(client)) {
  2628.         return Plugin_Continue;
  2629.     }
  2630.     if (!IsValidClient(client)) {
  2631.         return Plugin_Continue;
  2632.     }
  2633.     if (!IsFakeClient(client)) {
  2634.         return Plugin_Continue;
  2635.     }
  2636.     if (g_isCheckpoint == 0) {
  2637.         return Plugin_Continue;
  2638.     }
  2639.  
  2640.     if ((StrContains(g_client_last_classstring[client], "juggernaut") > -1) && !Ins_InCounterAttack()) {
  2641.              return Plugin_Handled;
  2642.         }
  2643.  
  2644.     //PrintToServer("Eventspawn Call");
  2645.     //Reset this global timer everytime a bot spawns
  2646.     g_botStaticGlobal[client] = 0;
  2647.  
  2648.     // Get the number of control points
  2649.     //new ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  2650.  
  2651.     // Get active push point
  2652.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  2653.     float vecOrigin[3];
  2654.     GetClientAbsOrigin(client, vecOrigin);
  2655.  
  2656.     //if ((0 >= client || client > MaxClients) || !IsClientInGame(client))
  2657.     if ((0 < client <= MaxClients) || !IsClientInGame(client))
  2658.  
  2659.     if  (g_playersReady && g_botsReady == 1) {
  2660.         float vecSpawn[3];
  2661.         GetClientAbsOrigin(client, vecOrigin);
  2662.         int point = FindEntityByClassname(-1, "ins_spawnpoint");
  2663.         float tObjectiveDistance = g_flMinObjectiveDistance;
  2664.         int iCanSpawn = CheckSpawnPointPlayers(vecOrigin, client, tObjectiveDistance);
  2665.         while (point != -1) {
  2666.                 if (iCanSpawn < 0) {
  2667.                     return Plugin_Continue;
  2668.                 }
  2669.                 GetEntPropVector(point, Prop_Send, "m_vecOrigin", vecSpawn);
  2670.                 iCanSpawn = CheckSpawnPointPlayers(vecOrigin, client, tObjectiveDistance);
  2671.                 if (iCanSpawn == 1) {
  2672.                     break;
  2673.                 }
  2674.                 else {
  2675.                     tObjectiveDistance += 6.0;
  2676.                 }
  2677.             //}
  2678.                 point = FindEntityByClassname(point, "ins_spawnpoint");
  2679.         }
  2680.         //Global random for spawning
  2681.         g_spawnFrandom[client] = GetRandomInt(0, 100);
  2682.         //InsLog(DEBUG, "Event_Spawn iCanSpawn %d", iCanSpawn);
  2683.         if (iCanSpawn == 0 || (Ins_InCounterAttack() && g_spawnFrandom[client] < g_dynamicSpawnCounter_Perc) ||
  2684.             (!Ins_InCounterAttack() && g_spawnFrandom[client] < g_dynamicSpawn_Perc && acp > 1)) {
  2685.             //PrintToServer("TeleportClient Call");
  2686.             TeleportClient(client);
  2687.             if (client > 0 && IsClientInGame(client) && IsPlayerAlive(client) && IsClientConnected(client)) {
  2688.                 StuckCheck[client] = 0;
  2689.                 StartStuckDetection(client);
  2690.             }
  2691.         }
  2692.     }
  2693.  
  2694.     return Plugin_Continue;
  2695. }
  2696.  
  2697. public Action Event_SpawnPost(Event event, const char[] name, bool dontBroadcast) {
  2698.     int client = GetClientOfUserId(event.GetInt("userid"));
  2699.     ////InsLog(DEBUG, "Event_Spawn called");
  2700.     // char sNewNickname[64];
  2701.     // Format(sNewNickname, sizeof(sNewNickname), "%N", client);
  2702.     // if (StrEqual(sNewNickname, "[INS] RoundEnd Protector"))
  2703.     //  return Plugin_Continue;
  2704.  
  2705.  
  2706.     //Bots only below this
  2707.     if (!IsFakeClient(client)) {
  2708.         return Plugin_Continue;
  2709.     }
  2710.     SetNextAttack(client);
  2711.     //float fRandom = GetRandomFloat(0.0, 1.0);
  2712.     int fRandom = GetRandomInt(1, 100);
  2713.     //Check grenades
  2714.     if (fRandom < g_removeBotGrenadeChance && !Ins_InCounterAttack()) {
  2715.         int botGrenades = GetPlayerWeaponSlot(client, 3);
  2716.         // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 13
  2717.         if (botGrenades != -1 && IsValidEntity(botGrenades))  {
  2718.             // since we only have 3 slots in current theate
  2719.             while (botGrenades != -1 && IsValidEntity(botGrenades))  {
  2720.                 botGrenades = GetPlayerWeaponSlot(client, 3);
  2721.                 // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 1
  2722.                 if (botGrenades != -1 && IsValidEntity(botGrenades))  {
  2723.                     // Remove grenades but not pistols
  2724.                     char weapon[32];
  2725.                     GetEntityClassname(botGrenades, weapon, sizeof(weapon));
  2726.                     RemovePlayerItem(client, botGrenades);
  2727.                     AcceptEntityInput(botGrenades, "kill");
  2728.                 }
  2729.             }
  2730.         }
  2731.     }
  2732.     if (!g_iCvar_respawn_enable) {
  2733.         return Plugin_Continue;
  2734.     }
  2735.     return Plugin_Continue;
  2736. }
  2737.  
  2738. //This delays bot from attacking once spawned
  2739. void SetNextAttack(int client)
  2740. {
  2741.     float flTime = GetGameTime();
  2742.     float flDelay = g_flSpawnAttackDelay;
  2743.  
  2744. // Loop through entries in m_hMyWeapons.
  2745.     for (int offset = 0; offset < 128; offset += 4)
  2746.     {
  2747.         int weapon = GetEntDataEnt2(client, m_hMyWeapons + offset);
  2748.         if (weapon < 0)
  2749.         {
  2750.             continue;
  2751.         }
  2752. //      //InsLog(DEBUG, "SetNextAttack weapon %d", weapon);
  2753.         SetEntDataFloat(weapon, m_flNextPrimaryAttack, flTime + flDelay);
  2754.         SetEntDataFloat(weapon, m_flNextSecondaryAttack, flTime + flDelay);
  2755.     }
  2756. }
  2757.  
  2758. void UpdatePlayerOrigins()
  2759. {
  2760.     for (int i = 1; i < MaxClients; i++) {
  2761.         if (IsValidClient(i)) {
  2762.             GetClientAbsOrigin(i, g_vecOrigin[i]);
  2763.         }
  2764.     }
  2765. }
  2766.  
  2767. /*
  2768. #####################################################################
  2769. #####################################################################
  2770. #####################################################################
  2771. # Jballous INS_SPAWNPOINT SPAWNING END ##############################
  2772. # Jballous INS_SPAWNPOINT SPAWNING END ##############################
  2773. #####################################################################
  2774. #####################################################################
  2775. #####################################################################
  2776. */
  2777.  
  2778.  
  2779. public Action Command_BotCount(client, args)
  2780. {
  2781.     int mc = MaxClients;
  2782.     for(int i = 1; i < mc; i++ )
  2783.     {
  2784.         //if( IsClientInGame(i) && IsFakeClient(i)){
  2785.         if(IsClientInGame(i))
  2786.         {
  2787.             char target_name[50];
  2788.             GetClientName(i, target_name, sizeof(target_name));
  2789.             if (StrContains(target_name, g_sSecBot, false) >= 0)
  2790.             {
  2791.                 //KickClient(i);
  2792.             }
  2793.         }
  2794.     }
  2795.    
  2796.     return Plugin_Handled;
  2797. }
  2798.  
  2799. public Action Event_PlayerDeathPre(Handle event, const char[] name, bool dontBroadcast)
  2800. {
  2801.     if (g_iRoundEndBlockEnabled == 0) return Plugin_Continue;
  2802.  
  2803.     int teamSecCount = GetSecTeamBotCount();
  2804.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  2805.     if (client > 0 && IsClientInGame(client) && !IsFakeClient(client))
  2806.     {
  2807.         if (g_iIsRoundStarted == 1 && g_iIsRoundStartedPost == 1 && g_iIsGameEnded == 0)
  2808.         {
  2809.             //new iRemainingLife = GetRemainingLife();
  2810.             int iAlivePlayers = GetAlivePlayers();
  2811.             int iAliveAllowed = 5;
  2812.             if (teamSecCount <= 6)
  2813.                 iAliveAllowed = GetRandomInt(1, 2);
  2814.             if (teamSecCount > 6 && teamSecCount <= 10)
  2815.                 iAliveAllowed = GetRandomInt(1, 4);
  2816.             else
  2817.                 iAliveAllowed = GetRandomInt(2, 5);
  2818.  
  2819.             //Create buffer for counter attacks
  2820.             if (Ins_InCounterAttack())
  2821.             {
  2822.                 if (teamSecCount <= 6)
  2823.                     iAliveAllowed += GetRandomInt(1, 2);
  2824.                 if (teamSecCount > 6 && teamSecCount <= 10)
  2825.                     iAliveAllowed += GetRandomInt(1, 4);
  2826.                 else
  2827.                     iAliveAllowed += GetRandomInt(2, 4);
  2828.             }
  2829.  
  2830.             if (iAlivePlayers < iAliveAllowed && g_iRoundBlockCount > 0)
  2831.             {
  2832.                 g_iRoundBlockCount--;
  2833.                 char textToHint[64];
  2834.                 Format(textToHint, sizeof(textToHint), "Security Reinforcements remaining: %d", g_iRoundBlockCount);
  2835.                 PrintHintTextToAll(textToHint);
  2836.                 //ShowPanelAll(textToHint);
  2837.                
  2838.                 g_iReviveCount = g_iRoundEndBlockReviveDelay;
  2839.                 // if (g_iAnnounceActive == 0)
  2840.                 // {
  2841.                 //  g_iAnnounceActive = 1;
  2842.                 //  g_iReviveCount = g_iRoundEndBlockReviveDelay;
  2843.                 //  CreateTimer(1.0, Timer_Announce, _, TIMER_REPEAT);
  2844.                 // }
  2845.                
  2846.                 // if (Ins_InCounterAttack())
  2847.                 // {
  2848.                 //  // Get capture point speed cvar values
  2849.                 //  g_iCPSpeedUp = GetConVarInt(g_hCvarCPSpeedUp);
  2850.                 //  g_iCPSpeedUpMax = GetConVarInt(g_hCvarCPSpeedUpMax);
  2851.                 //  g_iCPSpeedUpRate = GetConVarInt(g_hCvarCPSpeedUpRate);
  2852.                    
  2853.                 //  // Prevent round end
  2854.                 //  SetConVarInt(g_hCvarCPSpeedUp, -1, true, false);
  2855.                 //  SetConVarInt(g_hCvarCPSpeedUpMax, 0, true, false);
  2856.                 //  SetConVarInt(g_hCvarCPSpeedUpRate, 0, true, false);
  2857.                 // }
  2858.                 RevivePlayers();
  2859.             }
  2860.             else if (iAlivePlayers == 1 && g_iRoundBlockCount <= 0)
  2861.             {
  2862.                 char textToHint[64];
  2863.                 Format(textToHint, sizeof(textToHint), "There's no more Security Reinforcements.");
  2864.                 PrintHintTextToAll(textToHint);
  2865.                 //ShowPanelAll(textToHint);
  2866.             }
  2867.         }
  2868.     }
  2869.    
  2870.     return Plugin_Continue;
  2871. }
  2872.  
  2873. public Action Timer_Announce(Handle Timer)
  2874. {
  2875.     if (g_iIsGameEnded == 0 && g_iIsRoundStarted == 1 && g_iIsRoundStartedPost == 1 && g_iSecBotID > 0)
  2876.     {
  2877.         if (g_iReviveCount >= 0)
  2878.         {
  2879.             for (int client = 1; client <= MaxClients; client++)
  2880.             {
  2881.                 if (IsClientConnected(client) && !IsFakeClient(client))
  2882.                 {
  2883.                     Handle hPanel = CreatePanel(null);
  2884.                     char buffer[128];
  2885.                    
  2886.                     SetPanelTitle(hPanel, "Security Reinforce");
  2887.                     DrawPanelItem(hPanel, "", ITEMDRAW_SPACER);
  2888.                    
  2889.                     DrawPanelItem(hPanel, "Waiting to revive players.", ITEMDRAW_DEFAULT);
  2890.                     //DrawPanelText(hPanel, "Waiting for reviving player.");
  2891.                     DrawPanelItem(hPanel, "", ITEMDRAW_SPACER);
  2892.                    
  2893.                     Format(buffer, sizeof(buffer), "Team Reinforcement arrives in: %d", g_iReviveCount);
  2894.                     DrawPanelItem(hPanel, buffer, ITEMDRAW_DEFAULT);
  2895.                     //DrawPanelText(hPanel, buffer);
  2896.                    
  2897.                     Format(buffer, sizeof(buffer), "Team Reinforcements remaining: %d", g_iRoundBlockCount);
  2898.                     DrawPanelItem(hPanel, buffer, ITEMDRAW_DEFAULT);
  2899.                     //DrawPanelText(hPanel, buffer);
  2900.                    
  2901.                     SetPanelCurrentKey(hPanel, 10);
  2902.                     SendPanelToClient(hPanel, client, NullMenuHandler, 1);
  2903.                     CloseHandle(hPanel);
  2904.                 }
  2905.             }
  2906.             g_iReviveCount--;
  2907.         }
  2908.         else
  2909.         {
  2910.             RevivePlayers();
  2911.             //g_iAnnounceActive = 0;
  2912.             return Plugin_Stop;
  2913.         }
  2914.     }
  2915.     else
  2916.     {
  2917.     //  g_iAnnounceActive = 0;
  2918.         return Plugin_Stop;
  2919.     }
  2920.     return Plugin_Continue;
  2921. }
  2922.  
  2923. public NullMenuHandler(Handle menu, MenuAction action, param1, param2) {}
  2924.  
  2925. void RevivePlayers()
  2926. {
  2927.     if (GetRealClientCount() <= 0) return;
  2928.     static iIsReviving = 0;
  2929.    
  2930.     if (iIsReviving == 1)
  2931.         return;
  2932.     else
  2933.         iIsReviving = 1;
  2934.    
  2935.     for (int client = 1; client <= MaxClients; client++)
  2936.     if (client > 0 && IsClientInGame(client) && !IsFakeClient(client) && !IsPlayerAlive(client))
  2937.     {
  2938.         int iTeam = GetClientTeam(client);
  2939.         if (iTeam == TEAM_1_SEC && playerPickSquad[client] == 1)
  2940.         {
  2941.             SDKCall(g_hPlayerRespawn, client);
  2942.             //if (g_fSpawnPoint[0] != 0.0 && g_fSpawnPoint[1] != 0.0 && g_fSpawnPoint[2] != 0.0)
  2943.             //  TeleportEntity(client, g_fSpawnPoint, NULL_VECTOR, NULL_VECTOR);
  2944.  
  2945.             // Get dead body
  2946.             int clientRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
  2947.             int primaryRemove = 0;
  2948.             int secondaryRemove = 0;
  2949.             int grenadesRemove = 0;
  2950.             RemoveWeapons(client, primaryRemove, secondaryRemove, grenadesRemove);
  2951.  
  2952.             //This timer safely removes client-side ragdoll
  2953.             if(clientRagdoll > 0 && IsValidEdict(clientRagdoll) && IsValidEntity(clientRagdoll))
  2954.             {
  2955.                 // Get dead body's entity
  2956.                 int ref = EntIndexToEntRef(clientRagdoll);
  2957.                 int entity = EntRefToEntIndex(ref);
  2958.                 if(entity != INVALID_ENT_REFERENCE && IsValidEntity(entity))
  2959.                 {
  2960.                     // Remove dead body's entity
  2961.                     AcceptEntityInput(entity, "Kill");
  2962.                     clientRagdoll = INVALID_ENT_REFERENCE;
  2963.                 }
  2964.             }
  2965.         }
  2966.     }
  2967.     iIsReviving = 0;
  2968. }
  2969.  
  2970. // When round starts, intialize variables
  2971. public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
  2972. {
  2973.     // Respawn delay for team ins
  2974.     g_fCvar_respawn_delay_team_ins = sm_respawn_delay_team_ins.FloatValue;
  2975.     g_fCvar_respawn_delay_team_ins_spec = sm_respawn_delay_team_ins_special.FloatValue;
  2976.     g_AIDir_TeamStatus = 50;
  2977.     g_AIDir_BotReinforceTriggered = false;
  2978.     g_iReinforceTime = sm_respawn_reinforce_time.IntValue;
  2979.     //g_checkStaticAmt = GetConVarInt(sm_respawn_check_static_enemy);
  2980.     //g_checkStaticAmtCntr = GetConVarInt(sm_respawn_check_static_enemy_counter);
  2981.     g_secWave_Timer = g_iRespawnSeconds;
  2982.     //Round_Start CVAR Sets ------------------ END -- vs using HookConVarChange
  2983.  
  2984.     //Elite Bots Reset
  2985.     if (g_elite_counter_attacks == 1)
  2986.     {
  2987.         g_isEliteCounter = 0;
  2988.         EnableDisableEliteBotCvars(0, 0);
  2989.     }
  2990.  
  2991.     // Reset respawn position
  2992.     g_fRespawnPosition[0] = 0.0;
  2993.     g_fRespawnPosition[1] = 0.0;
  2994.     g_fRespawnPosition[2] = 0.0;
  2995.  
  2996.    
  2997.     // Reset remaining life
  2998.     // ConVar hCvar = null;
  2999.     // ConVar hCvar = FindConVar("sm_remaininglife");
  3000.     // hCvar.SetInt(-1);
  3001.  
  3002.     // Reset respawn token
  3003.     ResetInsurgencyLives();
  3004.     ResetSecurityLives();
  3005.  
  3006.     // Check gamemode
  3007.     char sGameMode[32];
  3008.     FindConVar("mp_gamemode").GetString(sGameMode, sizeof(sGameMode));
  3009.     //PrintToServer("[REVIVE_DEBUG] ROUND STARTED");
  3010.    
  3011.     // Warming up revive
  3012.     g_iEnableRevive = 0;
  3013.     int iPreRoundFirst = FindConVar("mp_timer_preround_first").IntValue;
  3014.     int iPreRound = FindConVar("mp_timer_preround").IntValue;
  3015.     if (g_preRoundInitial == true)
  3016.     {
  3017.         CreateTimer(float(iPreRoundFirst), PreReviveTimer);
  3018.         iPreRoundFirst = iPreRoundFirst + 5;
  3019.         CreateTimer(float(iPreRoundFirst), BotsReady_Timer);
  3020.         g_preRoundInitial = false;
  3021.     }
  3022.     else
  3023.     {
  3024.         CreateTimer(float(iPreRound), PreReviveTimer);
  3025.         iPreRoundFirst = iPreRound + 5;
  3026.         CreateTimer(float(iPreRound), BotsReady_Timer);
  3027.     }
  3028.  
  3029.     g_iIsRoundStarted = 1;
  3030.     g_iIsRoundStartedPost = 0;
  3031.     g_iRoundStatus = 0;
  3032.    
  3033.     if (g_iRoundEndBlockResetRound == 1)
  3034.         g_iRoundBlockCount = g_iRoundEndBlockTimes;
  3035.  
  3036.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  3037.     if (ncp < 6)
  3038.     {
  3039.         g_iRoundBlockCount -= 1;
  3040.         if (g_iRoundBlockCount < 1)
  3041.             g_iRoundBlockCount = 1;
  3042.     }
  3043.  
  3044.     CreateTimer(float(iPreRound),Timer_RoundStartPost);
  3045.     return Plugin_Continue;
  3046. }
  3047.  
  3048. void SecTeamLivesBonus()
  3049. {
  3050.     int secTeamCount = GetTeamSecCount();
  3051.     if (secTeamCount <= 9)
  3052.     {
  3053.         g_iRespawnCount[2] += 1;
  3054.     }
  3055. }
  3056.  
  3057. //Adjust Lives Per Point Based On Players
  3058. void SecDynLivesPerPoint()
  3059. {
  3060.     int secTeamCount = GetTeamSecCount();
  3061.     if (secTeamCount <= 9)
  3062.     {
  3063.         g_iRespawnCount[2] += 1;
  3064.     }
  3065. }
  3066.  
  3067. // Round starts
  3068. Action PreReviveTimer(Handle timer)
  3069. {
  3070.     g_iRoundStatus = 1;
  3071.     g_iEnableRevive = 1;
  3072.  
  3073.     // Update remaining life cvar
  3074.     //Handle hCvar = null;
  3075.     //int iRemainingLife = GetRemainingLife();
  3076.     //hCvar = FindConVar("sm_remaininglife");
  3077.     //SetConVarInt(hCvar, iRemainingLife);
  3078. }
  3079.  
  3080. // Botspawn trigger
  3081. Action BotsReady_Timer(Handle timer)
  3082. {
  3083.     g_botsReady = 1;
  3084. }
  3085.  
  3086. public Action Timer_RoundStartPost(Handle Timer)
  3087. {
  3088.     g_iRoundStatus = 1;
  3089.     g_iIsRoundStartedPost = 1;
  3090. }
  3091.  
  3092. // When round ends, intialize variables
  3093. public Action Event_RoundEnd_Pre(Event event, const char[] name, bool dontBroadcast)
  3094. {
  3095.     for (int client = 1; client <= MaxClients; client++)
  3096.     {
  3097.         if (!IsValidClient(client) || !IsClientInGame(client) || IsFakeClient(client)) continue;
  3098.         int tTeam = GetClientTeam(client);
  3099.         if (tTeam != TEAM_1_SEC) continue;
  3100.         if ((g_iStatRevives[client] > 0 || g_iStatHeals[client] > 0) && StrContains(g_client_last_classstring[client], "medic") > -1)
  3101.         {
  3102.             char sBuf[255];
  3103.             // Hint to iMedic
  3104.             Format(sBuf, 255,"[MEDIC STATS] for %N: HEALS: %d | REVIVES: %d", client, g_iStatHeals[client], g_iStatRevives[client]);
  3105.             PrintHintText(client, "%s", sBuf);
  3106.             //PrintToChatAll("%s", sBuf);
  3107.         }
  3108.  
  3109.         playerInRevivedState[client] = false;
  3110.     }
  3111.  
  3112.     g_fSpawnPoint[0] = 0.0;
  3113.     g_fSpawnPoint[1] = 0.0;
  3114.     g_fSpawnPoint[2] = 0.0;
  3115.     g_iIsRoundStarted = 0;
  3116.     g_iIsRoundStartedPost = 0;
  3117.     g_iRoundStatus = 0;
  3118.  
  3119.     //Reset Variables
  3120.     g_removeBotGrenadeChance = 50;
  3121. }
  3122.  
  3123. public Action Event_RoundEnd_Post(Handle event, const char[] name, bool dontBroadcast)
  3124. {
  3125.     // Kick blocker client
  3126.     //KickBlockerClient();
  3127.     //KickBlocker(); //Just resets cvars now
  3128.     // Reset respawn position
  3129.     g_fSpawnPoint[0] = 0.0;
  3130.     g_fSpawnPoint[1] = 0.0;
  3131.     g_fSpawnPoint[2] = 0.0;
  3132.    
  3133.     g_iIsRoundStarted = 0;
  3134.     g_iIsRoundStartedPost = 0;
  3135.     g_iRoundStatus = 0;
  3136.  
  3137.     if (g_iRoundEndBlockResetRound == 1)
  3138.         g_iRoundBlockCount = g_iRoundEndBlockTimes;
  3139. }
  3140.  
  3141. // When round ends, intialize variables
  3142. public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  3143. {
  3144.    
  3145.     //Lua Healing kill sound
  3146.     char ent = -1;
  3147.     while ((ent = FindEntityByClassname(ent, "healthkit")) > MaxClients && IsValidEntity(ent))
  3148.     {
  3149.         //StopSound(ent, SNDCHAN_STATIC, "Lua_sounds/healthkit_healing.wav");
  3150.         //PrintToServer("KILL HEALTHKITS");
  3151.         AcceptEntityInput(ent, "Kill");
  3152.     }
  3153.  
  3154.     //Elite Bots Reset
  3155.     if (g_elite_counter_attacks == 1)
  3156.     {
  3157.         g_isEliteCounter = 0;
  3158.         EnableDisableEliteBotCvars(0, 0);
  3159.     }
  3160.  
  3161.     // Reset respawn position
  3162.     g_fRespawnPosition[0] = 0.0;
  3163.     g_fRespawnPosition[1] = 0.0;
  3164.     g_fRespawnPosition[2] = 0.0;
  3165.  
  3166.     // Reset remaining life
  3167.     //Handle hCvar = FindConVar("sm_remaininglife");
  3168.     //SetConVarInt(hCvar, -1);
  3169.  
  3170.     //PrintToServer("[REVIVE_DEBUG] ROUND ENDED"); 
  3171.     // Cooldown revive
  3172.     g_iEnableRevive = 0;
  3173.     g_iRoundStatus = 0;
  3174.     g_botsReady = 0;
  3175.  
  3176.     // Reset respawn token
  3177.     ResetInsurgencyLives();
  3178.     ResetSecurityLives();
  3179. }
  3180.  
  3181. public Action Event_GameStart(Handle event, const char[] name, bool dontBroadcast)
  3182. {
  3183.     g_iIsGameEnded = 0;
  3184. }
  3185.  
  3186. public Action Event_GameEnd(Handle event, const char[] name, bool dontBroadcast)
  3187. {
  3188.     (g_iRoundStatus = 0) && (g_botsReady = 0) && (g_iEnableRevive = 0) && (g_iIsGameEnded = 1);
  3189. }
  3190.  
  3191. // Check occuring counter attack when control point captured
  3192. public Action Event_ControlPointCaptured_Pre(Event event, const char[] name, bool dontBroadcast)
  3193. {
  3194.     //roundendblock
  3195.     // Call counter-attack end timer
  3196.     int iTeam = GetEventInt(event, "team");
  3197.     if ((Ins_InCounterAttack()) && iTeam == 3)
  3198.     {
  3199.         if (!g_bIsCounterAttackTimerActive)
  3200.         {
  3201.             g_bIsCounterAttackTimerActive = true;
  3202.             CreateTimer(1.0, Timer_CounterAttackEnd, _, TIMER_REPEAT);
  3203.             //PrintToServer("[RESPAWN] Counter-attack timer started. (Normal counter-attack)");
  3204.         }
  3205.         return Plugin_Stop;
  3206.     }
  3207.    
  3208.  
  3209.     //Clear bad spawn array
  3210.     //ClearArray(g_badSpawnPos_Array);
  3211.     for (int client = 0; client < MaxClients; client++)
  3212.     {
  3213.         if (!IsValidClient(client) || client <= 0)
  3214.                 continue;
  3215.         if (!IsClientInGame(client))
  3216.             continue;
  3217.         int m_iTeam = GetClientTeam(client);
  3218.         if (IsFakeClient(client) && m_iTeam == TEAM_2_INS)
  3219.         {
  3220.             g_badSpawnPos_Track[client][0] = 0.0;
  3221.             g_badSpawnPos_Track[client][1] = 0.0;
  3222.             g_badSpawnPos_Track[client][2] = 0.0;
  3223.         }
  3224.     }
  3225.  
  3226.     //g_checkStaticAmt = GetConVarInt(sm_respawn_check_static_enemy);
  3227.     //g_checkStaticAmtCntr = GetConVarInt(sm_respawn_check_static_enemy_counter);
  3228.  
  3229.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints"); // Get the number of control points
  3230.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex"); // Get active push point
  3231.  
  3232.     //AI Director Status ###START###
  3233.     int secTeamCount = GetTeamSecCount();
  3234.     int secTeamAliveCount = Team_CountAlivePlayers(TEAM_1_SEC);
  3235.     if (g_iRespawn_lives_team_ins > 0)
  3236.         g_AIDir_TeamStatus += 10;
  3237.     if (secTeamAliveCount >= (secTeamCount * 0.8)) // If Alive Security >= 80%
  3238.         g_AIDir_TeamStatus += 10;
  3239.     else if (secTeamAliveCount >= (secTeamCount * 0.5)) // If Alive Security >= 50%
  3240.         g_AIDir_TeamStatus += 5;
  3241.     else if (secTeamAliveCount <= (secTeamCount * 0.2)) // If Dead Security <= 20%
  3242.         g_AIDir_TeamStatus -= 10;
  3243.     else if (secTeamAliveCount <= (secTeamCount * 0.5)) // If Dead Security <= 50%
  3244.         g_AIDir_TeamStatus -= 5;
  3245.  
  3246.     if (g_AIDir_BotReinforceTriggered)
  3247.         g_AIDir_TeamStatus -= 5;
  3248.     else
  3249.         g_AIDir_TeamStatus += 10;
  3250.  
  3251.     g_AIDir_BotReinforceTriggered = false;
  3252.     //AI Director Status ###END###
  3253.  
  3254.     // Get gamemode
  3255.     char sGameMode[32];
  3256.     FindConVar("mp_gamemode").GetString(sGameMode, sizeof(sGameMode));
  3257.  
  3258.     // Init variables
  3259.     ConVar cvar;
  3260.  
  3261.     // Set minimum and maximum counter attack duration time
  3262.     g_counterAttack_min_dur_sec = sm_respawn_min_counter_dur_sec.IntValue;
  3263.     g_counterAttack_max_dur_sec = sm_respawn_max_counter_dur_sec.IntValue;
  3264.     int final_ca_dur = sm_respawn_final_counter_dur_sec.IntValue;
  3265.  
  3266.     // Get random duration
  3267.     int fRandomInt = GetRandomInt(g_counterAttack_min_dur_sec, g_counterAttack_max_dur_sec);
  3268.     int fRandomIntCounterLarge = GetRandomInt(1, 100);
  3269.     int largeCounterEnabled = false;
  3270.     if (fRandomIntCounterLarge <= 15)
  3271.     {
  3272.         fRandomInt = (fRandomInt * 2);
  3273.         int fRandomInt2 = GetRandomInt(60, 90);
  3274.         final_ca_dur = (final_ca_dur + fRandomInt2);
  3275.         largeCounterEnabled = true;
  3276.     }
  3277.  
  3278.     // Set counter attack duration to server
  3279.     ConVar cvar_ca_dur;
  3280.  
  3281.     // Final counter attack
  3282.     if ((acp+1) == ncp)
  3283.     {
  3284.         g_iRemaining_lives_team_ins = 0;
  3285.         for (int i = 1; i <= MaxClients; i++)
  3286.         {
  3287.             if (i > 0 && IsClientInGame(i))
  3288.             {
  3289.                 if(IsFakeClient(i))        
  3290.                     ForcePlayerSuicide(i);
  3291.             }
  3292.         }
  3293.  
  3294.         //g_AIDir_TeamStatus -= 10;
  3295.  
  3296.         cvar_ca_dur = FindConVar("mp_checkpoint_counterattack_duration_finale");
  3297.         cvar_ca_dur.SetInt(final_ca_dur, true, false);
  3298.         g_dynamicSpawnCounter_Perc += 10;
  3299.  
  3300.         if (g_finale_counter_spec_enabled == 1)
  3301.                 g_dynamicSpawnCounter_Perc = g_finale_counter_spec_percent;
  3302.  
  3303.         //If endless spawning on final counter attack, add lives on finale counter on a delay
  3304.         if (g_iCvar_final_counterattack_type == 2)
  3305.         {
  3306.             float tCvar_CounterDelayValue = FindConVar("mp_checkpoint_counterattack_delay_finale").FloatValue;
  3307.             CreateTimer((tCvar_CounterDelayValue),Timer_FinaleCounterAssignLives);
  3308.         }
  3309.     }
  3310.  
  3311.     // Normal counter attack
  3312.     else
  3313.     {
  3314.         g_AIDir_TeamStatus -= 5;
  3315.         cvar_ca_dur = FindConVar("mp_checkpoint_counterattack_duration");
  3316.         cvar_ca_dur.SetInt(fRandomInt, true, false);
  3317.     }
  3318.  
  3319.     // Get random value for occuring counter attack
  3320.     float fRandom = GetRandomFloat(0.0, 1.0);
  3321.     //PrintToServer("Counter Chance = %f", g_respawn_counter_chance);
  3322.     // Occurs counter attack
  3323.     if (fRandom < g_respawn_counter_chance && ((acp+1) != ncp))
  3324.     {
  3325.         cvar = null;
  3326.         //PrintToServer("COUNTER YES");
  3327.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3328.         cvar.SetInt(0, true, false);
  3329.         cvar = FindConVar("mp_checkpoint_counterattack_always");
  3330.         cvar.SetInt(1, true, false);
  3331.         if (largeCounterEnabled)
  3332.         {
  3333.             PrintHintTextToAll("[INTEL]: Enemy forces are sending a large counter-attack your way!  Get ready to defend!");
  3334.             //PrintToChatAll("[INTEL]: Enemy forces are sending a large counter-attack your way!  Get ready to defend!");
  3335.         }
  3336.  
  3337.         g_AIDir_TeamStatus -= 5;
  3338.         // Call music timer
  3339.         //CreateTimer(COUNTER_ATTACK_MUSIC_DURATION, Timer_CounterAttackSound);
  3340.  
  3341.         //Create Counter End Timer
  3342.         g_isEliteCounter = 1;
  3343.         CreateTimer(cvar_ca_dur.FloatValue + 1.0, Timer_CounterAttackEnd);
  3344.         if (g_elite_counter_attacks == 1)
  3345.         {
  3346.             EnableDisableEliteBotCvars(1, 0);
  3347.             ConVar tCvar = FindConVar("ins_bot_count_checkpoint_max");
  3348.             int tCvarIntValue = FindConVar("ins_bot_count_checkpoint_max").IntValue;
  3349.             tCvarIntValue += 3;
  3350.             tCvar.SetInt(tCvarIntValue, true, false);
  3351.         }
  3352.     }
  3353.     // If last capture point
  3354.     else if (g_isCheckpoint == 1 && ((acp+1) == ncp))
  3355.     {
  3356.         cvar = null;
  3357.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3358.         cvar.SetInt(0, true, false);
  3359.         cvar = FindConVar("mp_checkpoint_counterattack_always");
  3360.         cvar.SetInt(1, true, false);
  3361.  
  3362.         // Call music timer
  3363.         //CreateTimer(COUNTER_ATTACK_MUSIC_DURATION, Timer_CounterAttackSound);
  3364.  
  3365.         //Create Counter End Timer
  3366.         g_isEliteCounter = 1;
  3367.         CreateTimer((cvar_ca_dur.FloatValue + 1.0), Timer_CounterAttackEnd);
  3368.  
  3369.         if (g_elite_counter_attacks == 1)
  3370.         {
  3371.             EnableDisableEliteBotCvars(1, 1);
  3372.             ConVar tCvar = FindConVar("ins_bot_count_checkpoint_max");
  3373.             int tCvarIntValue = FindConVar("ins_bot_count_checkpoint_max").IntValue;
  3374.             tCvarIntValue += 3;
  3375.             tCvar.SetInt(tCvarIntValue, true, false);
  3376.         }
  3377.     }
  3378.     // Not occurs counter attack
  3379.     else
  3380.     {
  3381.         cvar = null;
  3382.         //PrintToServer("COUNTER NO");
  3383.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3384.         cvar.SetInt(1, true, false);
  3385.     }
  3386.     g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  3387.    
  3388.     return Plugin_Continue;
  3389. }
  3390.  
  3391. // When control point captured, reset variables
  3392. public Action Event_ControlPointCaptured(Event event, const char[] name, bool dontBroadcast)
  3393. {
  3394.     // Reset reinforcement time
  3395.     g_iReinforceTime = g_iReinforceTime_AD_Temp;
  3396.    
  3397.     // Reset respawn tokens
  3398.     ResetInsurgencyLives();
  3399.     if (g_iCvar_respawn_reset_type && g_isCheckpoint)
  3400.         ResetSecurityLives();
  3401.  
  3402.     //PrintToServer("CONTROL POINT CAPTURED");
  3403.    
  3404.     return Plugin_Continue;
  3405. }
  3406.  
  3407. // When control point captured, update respawn point and respawn all players
  3408. public Action Event_ControlPointCaptured_Post(Event event, const char[] name, bool dontBroadcast)
  3409. {
  3410.     if (sm_respawn_security_on_counter.IntValue == 1)
  3411.     {
  3412.         // Get client who captured control point.
  3413.         char cappers[512];
  3414.         event.GetString("cappers", cappers, sizeof(cappers));
  3415.         int cappersLength = strlen(cappers);
  3416.         for (int i = 0 ; i < cappersLength; i++) {
  3417.             int clientCapper = cappers[i];
  3418.             if (clientCapper > 0 && IsClientInGame(clientCapper) && IsClientConnected(clientCapper) && IsPlayerAlive(clientCapper) && !IsFakeClient(clientCapper)) {
  3419.                 // Get player's position
  3420.                 float capperPos[3];
  3421.                 GetClientAbsOrigin(clientCapper, capperPos);
  3422.  
  3423.                 // Update respawn position
  3424.                 g_fRespawnPosition = capperPos;
  3425.  
  3426.                 break;
  3427.             }
  3428.         }
  3429.  
  3430.         // Respawn all players
  3431.         for (int client = 1; client <= MaxClients; client++)
  3432.         {
  3433.             if (IsClientInGame(client))
  3434.             {
  3435.                 int team = GetClientTeam(client);
  3436.                 float clientPos[3];
  3437.                 GetClientAbsOrigin(client, clientPos);
  3438.                 if (playerPickSquad[client] == 1 && !IsPlayerAlive(client) && team == TEAM_1_SEC)
  3439.                 {
  3440.                     if (!IsFakeClient(client))
  3441.                     {
  3442.                         if (!IsClientTimingOut(client))
  3443.                             CreateCounterRespawnTimer(client);
  3444.                     }
  3445.                     else
  3446.                     {
  3447.                         CreateCounterRespawnTimer(client);
  3448.                     }
  3449.                 }
  3450.             }
  3451.         }
  3452.     }
  3453.         // //Elite Bots Reset
  3454.         // if (g_elite_counter_attacks == 1)
  3455.         //  CreateTimer(5.0, Timer_EliteBots);
  3456.  
  3457.         // Update cvars
  3458.     UpdateRespawnCvars();
  3459.  
  3460.     //Reset security team wave counter
  3461.     g_secWave_Timer = g_iRespawnSeconds;
  3462.     // Get the number of control points
  3463.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  3464.    
  3465.     // Get active push point
  3466.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  3467.     // If last capture point
  3468.     if (((acp+1) == ncp))
  3469.     {
  3470.         g_secWave_Timer = g_iRespawnSeconds;
  3471.         g_secWave_Timer += (GetTeamSecCount() * 4);
  3472.     }
  3473.     else if (Ins_InCounterAttack())
  3474.             g_secWave_Timer += (GetTeamSecCount() * 3);
  3475.     return Plugin_Continue;
  3476. }
  3477.  
  3478. // When ammo cache destroyed, update respawn position and reset variables
  3479. public Action Event_ObjectDestroyed_Pre(Event event, const char[] name, bool dontBroadcast)
  3480. {
  3481.     //Clear bad spawn array
  3482.     //ClearArray(g_badSpawnPos_Array);
  3483.     for (int client = 0; client < MaxClients; client++)
  3484.     {
  3485.         if (!IsValidClient(client) || client <= 0 || !IsClientInGame(client)) continue;
  3486.         int m_iTeam = GetClientTeam(client);
  3487.         if (IsFakeClient(client) && m_iTeam == TEAM_2_INS)
  3488.         {
  3489.             g_badSpawnPos_Track[client][0] = 0.0;
  3490.             g_badSpawnPos_Track[client][1] = 0.0;
  3491.             g_badSpawnPos_Track[client][2] = 0.0;
  3492.         }
  3493.     }
  3494.  
  3495.     //g_checkStaticAmt = sm_respawn_check_static_enemy.IntValue;
  3496.     //g_checkStaticAmtCntr = sm_respawn_check_static_enemy_counter.IntValue;
  3497.  
  3498.    
  3499.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints"); // Get the number of control points
  3500.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex"); // Get active push point
  3501.  
  3502.     //AI Director Status ###START###
  3503.     int secTeamCount = GetTeamSecCount();
  3504.     int secTeamAliveCount = Team_CountAlivePlayers(TEAM_1_SEC);
  3505.  
  3506.     if (g_iRespawn_lives_team_ins > 0)
  3507.         g_AIDir_TeamStatus += 10;
  3508.     if (secTeamAliveCount >= (secTeamCount * 0.8)) // If Alive Security >= 80%
  3509.         g_AIDir_TeamStatus += 10;
  3510.     else if (secTeamAliveCount >= (secTeamCount * 0.5)) // If Alive Security >= 50%
  3511.         g_AIDir_TeamStatus += 5;
  3512.     else if (secTeamAliveCount <= (secTeamCount * 0.2)) // If Dead Security <= 20%
  3513.         g_AIDir_TeamStatus -= 10;
  3514.     else if (secTeamAliveCount <= (secTeamCount * 0.5)) // If Dead Security <= 50%
  3515.         g_AIDir_TeamStatus -= 5;
  3516.  
  3517.     if (g_AIDir_BotReinforceTriggered)
  3518.         g_AIDir_TeamStatus += 10;
  3519.     else
  3520.         g_AIDir_TeamStatus -= 5;
  3521.  
  3522.     g_AIDir_BotReinforceTriggered = false;
  3523.  
  3524.     //AI Director Status ###END###
  3525.  
  3526.     // Get gamemode
  3527.     char sGameMode[32];
  3528.     GetConVarString(FindConVar("mp_gamemode"), sGameMode, sizeof(sGameMode));
  3529.    
  3530.     // Init variables
  3531.     ConVar cvar;
  3532.    
  3533.     // Set minimum and maximum counter attack duration time
  3534.     g_counterAttack_min_dur_sec = sm_respawn_min_counter_dur_sec.IntValue;
  3535.     g_counterAttack_max_dur_sec = sm_respawn_max_counter_dur_sec.IntValue;
  3536.     int final_ca_dur = sm_respawn_final_counter_dur_sec.IntValue;
  3537.  
  3538.     // Get random duration
  3539.     int fRandomInt = GetRandomInt(g_counterAttack_min_dur_sec, g_counterAttack_max_dur_sec);
  3540.     int fRandomIntCounterLarge = GetRandomInt(1, 100);
  3541.     int largeCounterEnabled = false;
  3542.     if (fRandomIntCounterLarge <= 15)
  3543.     {
  3544.         fRandomInt = (fRandomInt * 2);
  3545.         int fRandomInt2 = GetRandomInt(90, 180);
  3546.         final_ca_dur = (final_ca_dur + fRandomInt2);
  3547.         largeCounterEnabled = true;
  3548.     }
  3549.     // Set counter attack duration to server
  3550.     ConVar cvar_ca_dur;
  3551.  
  3552.     // Final counter attack
  3553.     if ((acp+1) == ncp)
  3554.     {
  3555.         cvar_ca_dur = FindConVar("mp_checkpoint_counterattack_duration_finale");
  3556.         cvar_ca_dur.SetInt(final_ca_dur, true, false);
  3557.         g_dynamicSpawnCounter_Perc += 10;
  3558.         //g_AIDir_TeamStatus -= 10;
  3559.         if (g_finale_counter_spec_enabled == 1)
  3560.         {
  3561.                 g_dynamicSpawnCounter_Perc = g_finale_counter_spec_percent;
  3562.         }
  3563.     }
  3564.     // Normal counter attack
  3565.     else
  3566.     {
  3567.         g_AIDir_TeamStatus -= 5;
  3568.         cvar_ca_dur = FindConVar("mp_checkpoint_counterattack_duration");
  3569.         cvar_ca_dur.SetInt(fRandomInt, true, false);
  3570.     }
  3571.  
  3572.     //Are we using vanilla counter attack?
  3573.     if (g_iCvar_counterattack_vanilla == 1) return Plugin_Continue;
  3574.  
  3575.     // Get random value for occuring counter attack
  3576.     float fRandom = GetRandomFloat(0.0, 1.0);
  3577.     //PrintToServer("Counter Chance = %f", g_respawn_counter_chance);
  3578.  
  3579.     // Occurs counter attack
  3580.     if (fRandom < g_respawn_counter_chance && ((acp+1) != ncp))
  3581.     {
  3582.         cvar = null;
  3583.         //PrintToServer("COUNTER YES");
  3584.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3585.         cvar.SetInt(0, true, false);
  3586.         cvar = FindConVar("mp_checkpoint_counterattack_always");
  3587.         cvar.SetInt(1, true, false);
  3588.         if (largeCounterEnabled)
  3589.         {
  3590.             PrintHintTextToAll("[INTEL]: Enemy forces are sending a large counter-attack your way!  Get ready to defend!");
  3591.             //PrintToChatAll("[INTEL]: Enemy forces are sending a large counter-attack your way!  Get ready to defend!");
  3592.         }
  3593.         g_AIDir_TeamStatus -= 5;
  3594.         // Call music timer
  3595.         //CreateTimer(COUNTER_ATTACK_MUSIC_DURATION, Timer_CounterAttackSound);
  3596.  
  3597.         //Create Counter End Timer
  3598.         g_isEliteCounter = 1;
  3599.         CreateTimer(cvar_ca_dur.FloatValue + 1.0, Timer_CounterAttackEnd);
  3600.         if (g_elite_counter_attacks == 1)
  3601.         {
  3602.             EnableDisableEliteBotCvars(1, 0);
  3603.             ConVar tCvar = FindConVar("ins_bot_count_checkpoint_max");
  3604.             int tCvarIntValue = FindConVar("ins_bot_count_checkpoint_max").IntValue;
  3605.             tCvarIntValue += 3;
  3606.             tCvar.SetInt(tCvarIntValue, true, false);
  3607.         }
  3608.     }
  3609.     // If last capture point
  3610.     else if (((acp+1) == ncp))
  3611.     {
  3612.         cvar = null;
  3613.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3614.         cvar.SetInt(0, true, false);
  3615.         cvar = FindConVar("mp_checkpoint_counterattack_always");
  3616.         cvar.SetInt(1, true, false);
  3617.  
  3618.         // Call music timer
  3619.         //CreateTimer(COUNTER_ATTACK_MUSIC_DURATION, Timer_CounterAttackSound);
  3620.  
  3621.         //Create Counter End Timer
  3622.         g_isEliteCounter = 1;
  3623.         CreateTimer(cvar_ca_dur.FloatValue + 1.0, Timer_CounterAttackEnd);
  3624.  
  3625.         if (g_elite_counter_attacks == 1) {
  3626.             EnableDisableEliteBotCvars(1, 1);
  3627.             ConVar tCvar = FindConVar("ins_bot_count_checkpoint_max");
  3628.             int tCvarIntValue = FindConVar("ins_bot_count_checkpoint_max").IntValue;
  3629.             tCvarIntValue += 3;
  3630.             tCvar.SetInt(tCvarIntValue, true, false);
  3631.         }
  3632.     }
  3633.     // Not occurs counter attack
  3634.     else
  3635.     {
  3636.         cvar = null;
  3637.         //PrintToServer("COUNTER NO");
  3638.         cvar = FindConVar("mp_checkpoint_counterattack_disable");
  3639.         cvar.SetInt(1, true, false);
  3640.     }
  3641.     g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  3642.     return Plugin_Continue;
  3643. }
  3644.  
  3645. // When ammo cache destroyed, update respawn position and reset variables
  3646. public Action Event_ObjectDestroyed(Event event, const char[] name, bool dontBroadcast)
  3647. {
  3648.     // Reset reinforcement time
  3649.     g_iReinforceTime = g_iReinforceTime_AD_Temp;
  3650.  
  3651.     // Reset respawn token
  3652.     ResetInsurgencyLives();
  3653.     if (g_iCvar_respawn_reset_type)
  3654.         ResetSecurityLives();
  3655.     return Plugin_Continue;
  3656. }
  3657.  
  3658. // When control point captured, update respawn point and respawn all players
  3659. public Action Event_ObjectDestroyed_Post(Event event, const char[] name, bool dontBroadcast)
  3660. {
  3661.  
  3662.     if (sm_respawn_security_on_counter.IntValue == 1)
  3663.     {
  3664.         // Get client who captured control point.
  3665.         char cappers[512];
  3666.         event.GetString("cappers", cappers, sizeof(cappers));
  3667.         int cappersLength = strlen(cappers);
  3668.         for (int i = 0 ; i < cappersLength; i++)
  3669.         {
  3670.             int clientCapper = cappers[i];
  3671.             if (clientCapper > 0 && IsClientInGame(clientCapper) && IsPlayerAlive(clientCapper) && !IsFakeClient(clientCapper))
  3672.             {
  3673.                 // Get player's position
  3674.                 float capperPos[3];
  3675.                 GetClientAbsOrigin(clientCapper, capperPos);
  3676.  
  3677.                 // Update respawn position
  3678.                 g_fRespawnPosition = capperPos;
  3679.                 break;
  3680.             }
  3681.         }
  3682.  
  3683.         // Respawn all players
  3684.         for (int client = 1; client <= MaxClients; client++)
  3685.         {
  3686.             if (IsClientInGame(client))
  3687.             {
  3688.                 int team = GetClientTeam(client);
  3689.                 float clientPos[3];
  3690.                 GetClientAbsOrigin(client, clientPos);
  3691.                 if (playerPickSquad[client] == 1 && !IsPlayerAlive(client) && team == TEAM_1_SEC)
  3692.                 {
  3693.                     if (!IsFakeClient(client))
  3694.                     {
  3695.                         if (!IsClientTimingOut(client))
  3696.                         {
  3697.                             CreateCounterRespawnTimer(client);
  3698.                         }
  3699.                     }
  3700.                     else
  3701.                     {
  3702.                         CreateCounterRespawnTimer(client);
  3703.                     }
  3704.                 }
  3705.             }
  3706.         }
  3707.     }
  3708.  
  3709.     // //Elite Bots Reset
  3710.     // if (g_elite_counter_attacks == 1)
  3711.     //  CreateTimer(5.0, Timer_EliteBots);
  3712.     //PrintToServer("CONTROL POINT CAPTURED POST");
  3713.  
  3714.     // Get the number of control points
  3715.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  3716.    
  3717.     // Get active push point
  3718.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  3719.     // If last capture point
  3720.     if (((acp+1) == ncp))
  3721.     {
  3722.         g_secWave_Timer = g_iRespawnSeconds;
  3723.         g_secWave_Timer += (GetTeamSecCount() * 4);
  3724.     }
  3725.     else if (Ins_InCounterAttack())
  3726.         g_secWave_Timer += (GetTeamSecCount() * 3);
  3727.  
  3728.     //Roundend Protection
  3729.     int attacker = GetEventInt(event, "attacker");
  3730.     if (attacker > 0 && IsValidClient(attacker))
  3731.     {
  3732.         float attackerPos[3];
  3733.         GetClientAbsOrigin(attacker, attackerPos);
  3734.         g_fSpawnPoint = attackerPos;
  3735.     }
  3736.     return Plugin_Continue;
  3737. }
  3738.  
  3739. //Enable/Disable Elite Bots
  3740. void EnableDisableEliteBotCvars(int tEnabled, int isFinale) {
  3741.     float tCvarFloatValue;
  3742.     int tCvarIntValue;
  3743.     ConVar tCvar;
  3744.     if (tEnabled == 1) {
  3745.         //PrintToServer("BOT_SETTINGS_APPLIED");
  3746.         if (isFinale == 1) {
  3747.             tCvar = FindConVar("mp_player_resupply_coop_delay_max");
  3748.             tCvar.SetInt(g_coop_delay_penalty_base, true, false);
  3749.             tCvar = FindConVar("mp_player_resupply_coop_delay_penalty");
  3750.             tCvar.SetInt(g_coop_delay_penalty_base, true, false);
  3751.             tCvar = FindConVar("mp_player_resupply_coop_delay_base");
  3752.             tCvar.SetInt(g_coop_delay_penalty_base, true, false);
  3753.         }
  3754.  
  3755.         tCvar = FindConVar("bot_attackdelay_frac_difficulty_impossible");
  3756.         tCvarFloatValue = FindConVar("bot_attackdelay_frac_difficulty_impossible").FloatValue;
  3757.         tCvarFloatValue = tCvarFloatValue - g_bot_attackdelay_frac_difficulty_impossible_mult;
  3758.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3759.  
  3760.         tCvar = FindConVar("bot_attack_aimpenalty_amt_close");
  3761.         tCvarIntValue = FindConVar("bot_attack_aimpenalty_amt_close").IntValue;
  3762.         tCvarIntValue = tCvarIntValue - g_bot_attack_aimpenalty_amt_close_mult;
  3763.         tCvar.SetInt(tCvarIntValue, true, false);
  3764.  
  3765.         tCvar = FindConVar("bot_attack_aimpenalty_amt_far");
  3766.         tCvarIntValue = FindConVar("bot_attack_aimpenalty_amt_far").IntValue;
  3767.         tCvarIntValue = tCvarIntValue - g_bot_attack_aimpenalty_amt_far_mult;
  3768.         tCvar.SetInt(tCvarIntValue, true, false);
  3769.  
  3770.         tCvar = FindConVar("bot_attack_aimpenalty_time_close");
  3771.         tCvarFloatValue = FindConVar("bot_attack_aimpenalty_time_close").FloatValue;
  3772.         tCvarFloatValue = tCvarFloatValue - g_bot_attack_aimpenalty_time_close_mult;
  3773.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3774.  
  3775.         tCvar = FindConVar("bot_attack_aimpenalty_time_far");
  3776.         tCvarFloatValue = FindConVar("bot_attack_aimpenalty_time_far").FloatValue;
  3777.         tCvarFloatValue = tCvarFloatValue - g_bot_attack_aimpenalty_time_far_mult;
  3778.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3779.  
  3780.         ConVar cv = FindConVar("bot_attack_aimtolerance_newthreat_amt");
  3781.         cv.FloatValue -= cv.FloatValue - g_bot_attack_aimtolerance_newthreat_amt_mult;
  3782.  
  3783.         /*
  3784.  
  3785.         tCvar = FindConVar("bot_attack_aimtolerance_newthreat_amt");
  3786.         tCvarIntValue = FindConVar("bot_attack_aimtolerance_newthreat_amt");
  3787.         tCvarIntValue = tCvarIntValue - g_bot_attack_aimtolerance_newthreat_amt_mult;
  3788.         tCvar.SetFloat(tCvarIntValue, true, false);
  3789.         */
  3790.  
  3791.         tCvar = FindConVar("bot_aim_aimtracking_base");
  3792.         tCvarFloatValue = FindConVar("bot_aim_aimtracking_base").FloatValue;
  3793.         tCvarFloatValue = tCvarFloatValue - g_bot_aim_aimtracking_base;
  3794.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3795.  
  3796.         tCvar = FindConVar("bot_aim_aimtracking_frac_impossible");
  3797.         tCvarFloatValue = FindConVar("bot_aim_aimtracking_frac_impossible").FloatValue;
  3798.         tCvarFloatValue = tCvarFloatValue - g_bot_aim_aimtracking_frac_impossible;
  3799.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3800.  
  3801.         tCvar = FindConVar("bot_aim_angularvelocity_frac_impossible");
  3802.         tCvarFloatValue = FindConVar("bot_aim_angularvelocity_frac_impossible").FloatValue;
  3803.         tCvarFloatValue = tCvarFloatValue + g_bot_aim_angularvelocity_frac_impossible;
  3804.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3805.  
  3806.         tCvar = FindConVar("bot_aim_angularvelocity_frac_sprinting_target");
  3807.         tCvarFloatValue = FindConVar("bot_aim_angularvelocity_frac_sprinting_target").FloatValue;
  3808.         tCvarFloatValue = tCvarFloatValue + g_bot_aim_angularvelocity_frac_sprinting_target;
  3809.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3810.  
  3811.         tCvar = FindConVar("bot_aim_attack_aimtolerance_frac_impossible");
  3812.         tCvarFloatValue = FindConVar("bot_aim_attack_aimtolerance_frac_impossible").FloatValue;
  3813.         tCvarFloatValue = tCvarFloatValue - g_bot_aim_attack_aimtolerance_frac_impossible;
  3814.         tCvar.SetFloat(tCvarFloatValue, true, false);
  3815.         //Make sure to check for FLOATS vs INTS and +/-!
  3816.     }
  3817.     else {
  3818.         //PrintToServer("BOT_SETTINGS_APPLIED_2");
  3819.         tCvar = FindConVar("ins_bot_count_checkpoint_max");
  3820.         tCvar.SetInt(g_ins_bot_count_checkpoint_max_org, true, false);
  3821.         tCvar = FindConVar("mp_player_resupply_coop_delay_max");
  3822.         tCvar.SetInt(g_mp_player_resupply_coop_delay_max_org, true, false);
  3823.         tCvar = FindConVar("mp_player_resupply_coop_delay_penalty");
  3824.         tCvar.SetInt(g_mp_player_resupply_coop_delay_penalty_org, true, false);
  3825.         tCvar = FindConVar("mp_player_resupply_coop_delay_base");
  3826.         tCvar.SetInt(g_mp_player_resupply_coop_delay_base_org, true, false);
  3827.         tCvar = FindConVar("bot_attackdelay_frac_difficulty_impossible");
  3828.         tCvar.SetFloat(g_bot_attackdelay_frac_difficulty_impossible_org, true, false);
  3829.         tCvar = FindConVar("bot_attack_aimpenalty_amt_close");
  3830.         tCvar.SetInt(g_bot_attack_aimpenalty_amt_close_org, true, false);
  3831.         tCvar = FindConVar("bot_attack_aimpenalty_amt_far");
  3832.         tCvar.SetInt(g_bot_attack_aimpenalty_amt_far_org, true, false);
  3833.         tCvar = FindConVar("bot_attack_aimpenalty_time_close");
  3834.         tCvar.SetFloat(g_bot_attack_aimpenalty_time_close_org, true, false);
  3835.         tCvar = FindConVar("bot_attack_aimpenalty_time_far");
  3836.         tCvar.SetFloat(g_bot_attack_aimpenalty_time_far_org, true, false);
  3837.         tCvar = FindConVar("bot_attack_aimtolerance_newthreat_amt");
  3838.         tCvar.SetFloat(g_bot_attack_aimtolerance_newthreat_amt_org, true, false);
  3839.         tCvar = FindConVar("bot_aim_aimtracking_base");
  3840.         tCvar.SetFloat(g_bot_aim_aimtracking_base_org, true, false);
  3841.         tCvar = FindConVar("bot_aim_aimtracking_frac_impossible");
  3842.         tCvar.SetFloat(g_bot_aim_aimtracking_frac_impossible_org, true, false);
  3843.         tCvar = FindConVar("bot_aim_angularvelocity_frac_impossible");
  3844.         tCvar.SetFloat(g_bot_aim_angularvelocity_frac_impossible_org, true, false);
  3845.         tCvar = FindConVar("bot_aim_angularvelocity_frac_sprinting_target");
  3846.         tCvar.SetFloat(g_bot_aim_angularvelocity_frac_sprinting_target_org, true, false);
  3847.         tCvar = FindConVar("bot_aim_attack_aimtolerance_frac_impossible");
  3848.         tCvar.SetFloat(g_bot_aim_attack_aimtolerance_frac_impossible_org, true, false);
  3849.     }
  3850. }
  3851.  
  3852. // On finale counter attack, add lives back to insurgents to trigger unlimited respawns (this is redundant code now and may use for something else)
  3853. Action Timer_FinaleCounterAssignLives(Handle timer)
  3854. {
  3855.     if (g_iCvar_final_counterattack_type == 2)
  3856.     {
  3857.             // Reset remaining lives for bots
  3858.             g_iRemaining_lives_team_ins = g_iRespawn_lives_team_ins;
  3859.     }
  3860. }
  3861.  
  3862. // When counter-attack end, reset reinforcement time
  3863. Action Timer_CounterAttackEnd(Handle timer) {
  3864.  
  3865.     //Disable elite bots when not in counter
  3866.     if (g_isEliteCounter == 1 && g_elite_counter_attacks == 1) {
  3867.         g_isEliteCounter = 0;
  3868.         EnableDisableEliteBotCvars(0, 0);
  3869.     }
  3870.  
  3871.     ResetInsurgencyLives();
  3872.     if (g_iCvar_respawn_reset_type && g_isCheckpoint) {
  3873.             ResetSecurityLives();
  3874.     }
  3875.  
  3876.         // Stop counter-attack music
  3877.         //StopCounterAttackMusic();
  3878.  
  3879.         // Reset variable
  3880.     //g_bIsCounterAttackTimerActive = false;
  3881.     ConVar cvar = null;
  3882.     cvar = FindConVar("mp_checkpoint_counterattack_always");
  3883.     cvar.SetInt(0, true, false);
  3884.  
  3885.     for (int client = 0; client < MaxClients; client++) {
  3886.             if (!IsValidClient(client) || client <= 0) {
  3887.                 continue;
  3888.             }
  3889.             if (!IsClientInGame(client)) {
  3890.                 continue;
  3891.             }
  3892.             int m_iTeam = GetClientTeam(client);
  3893.             if (IsFakeClient(client) && m_iTeam == TEAM_2_INS) {
  3894.                 g_badSpawnPos_Track[client][0] = 0.0;
  3895.                 g_badSpawnPos_Track[client][1] = 0.0;
  3896.                 g_badSpawnPos_Track[client][2] = 0.0;
  3897.             }
  3898.         }
  3899.  
  3900.         //PrintToServer("[RESPAWN] Counter-attack is over.");
  3901.     return Plugin_Stop;
  3902.     //}
  3903.  
  3904.     //return Plugin_Continue;
  3905. }
  3906.  
  3907. /*
  3908. // Stop counter-attack music
  3909. void StopCounterAttackMusic()
  3910. {
  3911.     for (new i = 1; i <= MaxClients; i++)
  3912.     {
  3913.         if (IsClientInGame(i) && IsClientConnected(i) && !IsFakeClient(i))
  3914.         {
  3915.             //ClientCommand(i, "snd_restart");
  3916.             //FakeClientCommand(i, "snd_restart");
  3917.             StopSound(i, SNDCHAN_STATIC, "*cues/INS_GameMusic_AboutToAttack_A.ogg");
  3918.         }
  3919.     }
  3920. }
  3921. */
  3922.  
  3923. //Run this to mark a bot as ready to spawn. Add tokens if you want them to be able to spawn.
  3924. void ResetSecurityLives()
  3925. {
  3926.     // Disable if counquer
  3927.     //if (g_isConquer == 1 || g_isOutpost == 1) return;
  3928.         // The number of control points
  3929.     //new ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  3930.     // Active control poin
  3931.     //new acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  3932.  
  3933.  
  3934.     // Return if respawn is disabled
  3935.     if (!g_iCvar_respawn_enable)
  3936.         return;
  3937.  
  3938.     // Update cvars
  3939.     UpdateRespawnCvars();
  3940.  
  3941.     //If spawned per point, give more per-point lives based on team count.
  3942.     if (g_iCvar_respawn_reset_type == 1)
  3943.     {
  3944.             SecDynLivesPerPoint();
  3945.     }
  3946.    
  3947.     // Individual lives
  3948.     if (g_iCvar_respawn_type_team_sec == 1)
  3949.     {
  3950.         for (int client = 1; client <= MaxClients; client++)
  3951.         {
  3952.             // Check valid player
  3953.             if (client > 0 && IsClientInGame(client))
  3954.             {
  3955.                 //Reset Medic Stats:
  3956.                 g_playerMedicRevivessAccumulated[client] = 0;
  3957.                 g_playerMedicHealsAccumulated[client] = 0;
  3958.                 g_playerNonMedicHealsAccumulated[client] = 0;
  3959.  
  3960.                 // Check Team
  3961.                 int iTeam = GetClientTeam(client);
  3962.                 if (iTeam != TEAM_1_SEC) continue;
  3963.  
  3964.                 // Individual SEC lives
  3965.                 if (g_iCvar_respawn_type_team_sec == 1)
  3966.                 {
  3967.                 // Reset remaining lives for player
  3968.                     g_iSpawnTokens[client] = g_iRespawnCount[iTeam];
  3969.                 }
  3970.             }
  3971.         }
  3972.     }
  3973.  
  3974.     // Team lives
  3975.     if (g_iCvar_respawn_type_team_sec == 2)
  3976.     {
  3977.         // Reset remaining lives for player
  3978.         g_iRemaining_lives_team_sec = g_iRespawn_lives_team_sec;
  3979.     }
  3980. }
  3981.  
  3982. //Run this to mark a bot as ready to spawn. Add tokens if you want them to be able to spawn.
  3983. void ResetInsurgencyLives()
  3984. {
  3985.     // Return if respawn is disabled
  3986.     if (!g_iCvar_respawn_enable) return;
  3987.  
  3988.     // Update cvars
  3989.     UpdateRespawnCvars();
  3990.  
  3991.     // Individual lives
  3992.     if (g_iCvar_respawn_type_team_ins == 1)
  3993.     {
  3994.         for (int client=1; client<=MaxClients; client++)
  3995.         {
  3996.             // Check valid player
  3997.             if (client > 0 && IsClientInGame(client))
  3998.             {
  3999.                 // Check Team
  4000.                 int iTeam = GetClientTeam(client);
  4001.                 if (iTeam != TEAM_2_INS)
  4002.                 {
  4003.                     continue;
  4004.                 }
  4005.                 g_iSpawnTokens[client] = g_iRespawnCount[iTeam];
  4006.             }
  4007.         }
  4008.     }
  4009.  
  4010.     // Team lives
  4011.     if (g_iCvar_respawn_type_team_ins == 2)
  4012.     {
  4013.         // Reset remaining lives for bots
  4014.         g_iRemaining_lives_team_ins = g_iRespawn_lives_team_ins;
  4015.     }
  4016. }
  4017.  
  4018. // When player picked squad, initialize variables
  4019. public Action Event_PlayerPickSquad_Post(Event event, const char[] name, bool dontBroadcast)
  4020. {
  4021.     //"squad_slot" "byte"
  4022.     //"squad" "byte"
  4023.     //"userid" "short"
  4024.     //"class_template" "string"
  4025.     //PrintToServer("##########PLAYER IS PICKING SQUAD!############");
  4026.  
  4027.     // Get client ID
  4028.     int client = GetClientOfUserId( GetEventInt( event, "userid" ) );
  4029.    
  4030.     if( client == 0 || !IsClientInGame(client) || IsFakeClient(client)) return;
  4031.    
  4032.     // Init variable
  4033.     playerPickSquad[client] = 1;
  4034.  
  4035.     // Get class name
  4036.     char class_template[64];
  4037.     event.GetString("class_template", class_template, sizeof(class_template));
  4038.  
  4039.     // Set class string
  4040.     g_client_last_classstring[client] = class_template;
  4041.     g_hintsEnabled[client] = true;
  4042.  
  4043.     // If player changed squad and remain ragdoll
  4044.     int team = GetClientTeam(client);
  4045.     if (client > 0 && IsClientInGame(client) && IsClientObserver(client) && !IsPlayerAlive(client) && g_iHurtFatal[client] == 0 && team == TEAM_1_SEC)
  4046.     {
  4047.         // Remove ragdoll
  4048.         int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  4049.         if(playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  4050.             RemoveRagdoll(client);
  4051.  
  4052.         // Init variable
  4053.         g_iHurtFatal[client] = -1;
  4054.     }
  4055.  
  4056.     g_fPlayerLastChat[client] = GetGameTime();
  4057.  
  4058.     // Get player nickname
  4059.     char sNewNickname[64];
  4060.  
  4061.     // Medic class
  4062.     if (StrContains(g_client_last_classstring[client], "medic") > -1)
  4063.     {
  4064.         // Admin medic
  4065.         if (GetConVarInt(sm_respawn_enable_donor_tag) == 1 && (GetUserFlagBits(client) & ADMFLAG_ROOT))
  4066.             Format(sNewNickname, sizeof(sNewNickname), "[ADMIN][MEDIC] %s", g_client_org_nickname[client]);
  4067.         // Donor medic
  4068.         else if (GetConVarInt(sm_respawn_enable_donor_tag) == 1 && (GetUserFlagBits(client) & ADMFLAG_RESERVATION))
  4069.             Format(sNewNickname, sizeof(sNewNickname), "[DONOR][MEDIC] %s", g_client_org_nickname[client]);
  4070.         // Normal medic
  4071.         else
  4072.             Format(sNewNickname, sizeof(sNewNickname), "[MEDIC] %s", g_client_org_nickname[client]);
  4073.     }
  4074.  
  4075.     // Set player nickname
  4076.     char sCurNickname[64];
  4077.     Format(sCurNickname, sizeof(sCurNickname), "%N", client);
  4078.     if (!StrEqual(sCurNickname, sNewNickname))
  4079.         SetClientName(client, sNewNickname);
  4080.  
  4081.     g_playersReady = true;
  4082.  
  4083.     //Allow new players to use lives to respawn on join
  4084.     if (g_iRoundStatus == 1 && g_playerFirstJoin[client] == 1 && !IsPlayerAlive(client) && team == TEAM_1_SEC)
  4085.     {
  4086.         // Get SteamID to verify is player has connected before.
  4087.         char steamId[64];
  4088.         //GetClientAuthString(client, steamId, sizeof(steamId));
  4089.         GetClientAuthId(client, AuthId_Steam3, steamId, sizeof(steamId));
  4090.         int isPlayerNew = g_playerArrayList.FindString(steamId);
  4091.  
  4092.         if (isPlayerNew != -1)
  4093.         {
  4094.             //PrintToServer("Player %N has reconnected! | SteamID: %s | Index: %d", client, steamId, isPlayerNew);
  4095.         }
  4096.         else
  4097.         {
  4098.             g_playerArrayList.PushString(steamId);
  4099.             //PrintToServer("Player %N is new! | SteamID: %s | PlayerArrayList Size: %d", client, steamId, g_playerArrayList.Length);
  4100.             // Give individual lives to new player (no longer just at beginning of round)
  4101.             if (g_iCvar_respawn_type_team_sec == 1) {
  4102.                 if (g_isCheckpoint && g_iCvar_respawn_reset_type == 0) {
  4103.                     // The number of control points
  4104.                     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  4105.                     // Active control poin
  4106.                     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  4107.                     int tLiveSec = sm_respawn_lives_team_sec.IntValue;
  4108.  
  4109.                     if (acp <= (ncp / 2)) {
  4110.                         g_iSpawnTokens[client] = tLiveSec;
  4111.                     }
  4112.                     else {
  4113.                         g_iSpawnTokens[client] = (tLiveSec / 2);
  4114.                     }
  4115.  
  4116.                     if (tLiveSec < 1) {
  4117.                         tLiveSec = 1;
  4118.                         g_iSpawnTokens[client] = tLiveSec;
  4119.                     }
  4120.                 }
  4121.                 else {
  4122.                     g_iSpawnTokens[client] = sm_respawn_lives_team_sec.IntValue;
  4123.                 }
  4124.  
  4125.             }
  4126.             CreatePlayerRespawnTimer(client);
  4127.         }
  4128.     }
  4129.  
  4130.     //Update RespawnCvars when player picks squad
  4131.     UpdateRespawnCvars();
  4132. }
  4133.  
  4134. // Triggers when player hurt
  4135. ppublic Action Event_PlayerHurt_Pre(Event event, const char[] name, bool dontBroadcast) {
  4136.     int victim = GetClientOfUserId(event.GetInt("userid"));
  4137.     if (IsClientInGame(victim) && IsFakeClient(victim)) {
  4138.         return Plugin_Continue;
  4139.     }
  4140.  
  4141.     int victimHealth = event.GetInt("health");
  4142.     int dmg_taken = event.GetInt("dmg_health");
  4143.     //PrintToServer("victimHealth: %d, dmg_taken: %d", victimHealth, dmg_taken);
  4144.     if (g_fCvar_fatal_chance > 0.0 && dmg_taken > victimHealth) {
  4145.         // Get information for event structure
  4146.         int attacker = GetClientOfUserId(event.GetInt("attacker"));
  4147.         int hitgroup = event.GetInt("hitgroup");
  4148.  
  4149.         // Update last damege (related to 'hurt_fatal')
  4150.         g_clientDamageDone[victim] = dmg_taken;
  4151.  
  4152.         // Get weapon
  4153.         char weapon[32];
  4154.         event.GetString("weapon", weapon, sizeof(weapon));
  4155.  
  4156.         //PrintToServer("[DAMAGE TAKEN] Weapon used: %s, Damage done: %i", weapon, dmg_taken);
  4157.  
  4158.         // Check is team attack
  4159.         int attackerTeam;
  4160.         if (attacker > 0 && IsClientInGame(attacker) && IsClientConnected(attacker)) {
  4161.             attackerTeam = GetClientTeam(attacker);
  4162.         }
  4163.  
  4164.         // Get fatal chance
  4165.         float fRandom = GetRandomFloat(0.0, 1.0);
  4166.  
  4167.         // Is client valid
  4168.         if (IsClientInGame(victim)) {
  4169.  
  4170.             // Explosive
  4171.             if (hitgroup == 0) {
  4172.                 //explosive list
  4173.                 //incens
  4174.                 //grenade_molotov, grenade_anm14
  4175.                 //PrintToServer("[HITGROUP HURT BURN]");
  4176.                 //grenade_m67, grenade_f1, grenade_ied, grenade_c4, rocket_rpg7, rocket_at4, grenade_gp25_he, grenade_m203_he
  4177.                 // flame
  4178.                 if (StrEqual(weapon, "grenade_anm14", false) || StrEqual(weapon, "grenade_molotov", false)) {
  4179.                     //PrintToServer("[SUICIDE] incen/molotov DETECTED!");
  4180.                     if (dmg_taken >= g_iCvar_fatal_burn_dmg && (fRandom <= g_fCvar_fatal_chance)) {
  4181.                         // Hurt fatally
  4182.                         g_iHurtFatal[victim] = 1;
  4183.  
  4184.                         //PrintToServer("[PLAYER HURT BURN]");
  4185.                     }
  4186.                 }
  4187.                 // explosive
  4188.                 else if (StrEqual(weapon, "grenade_m67", false) ||
  4189.                     StrEqual(weapon, "grenade_f1", false) ||
  4190.                     StrEqual(weapon, "grenade_ied", false) ||
  4191.                     StrEqual(weapon, "grenade_c4", false) ||
  4192.                     StrEqual(weapon, "rocket_rpg7", false) ||
  4193.                     StrEqual(weapon, "rocket_at4", false) ||
  4194.                     StrEqual(weapon, "grenade_gp25_he", false) ||
  4195.                     StrEqual(weapon, "grenade_m203_he", false)) {
  4196.                     //PrintToServer("[HITGROUP HURT EXPLOSIVE]");
  4197.                     if (dmg_taken >= g_iCvar_fatal_explosive_dmg && (fRandom <= g_fCvar_fatal_chance)) {
  4198.                         // Hurt fatally
  4199.                         g_iHurtFatal[victim] = 1;
  4200.  
  4201.                         //PrintToServer("[PLAYER HURT EXPLOSIVE]");
  4202.                     }
  4203.                 }
  4204.                 //PrintToServer("[SUICIDE] HITRGOUP 0 [GENERIC]");
  4205.             }
  4206.             // Headshot
  4207.             else if (hitgroup == 1) {
  4208.                 //PrintToServer("[PLAYER HURT HEAD]");
  4209.                 if (dmg_taken >= g_iCvar_fatal_head_dmg && (fRandom <= g_fCvar_fatal_head_chance) && attackerTeam != TEAM_1_SEC) {
  4210.                     // Hurt fatally
  4211.                     g_iHurtFatal[victim] = 1;
  4212.  
  4213.                     //PrintToServer("[BOTSPAWNS] BOOM HEADSHOT");
  4214.                 }
  4215.             }
  4216.             // Chest
  4217.             else if (hitgroup == 2 || hitgroup == 3) {
  4218.                 //PrintToServer("[HITGROUP HURT CHEST]");
  4219.                 if (dmg_taken >= g_iCvar_fatal_chest_stomach && (fRandom <= g_fCvar_fatal_chance)) {
  4220.                     // Hurt fatally
  4221.                     g_iHurtFatal[victim] = 1;
  4222.  
  4223.                     //PrintToServer("[PLAYER HURT CHEST]");
  4224.                 }
  4225.             }
  4226.             // Limbs
  4227.             else if (hitgroup == 4 || hitgroup == 5  || hitgroup == 6 || hitgroup == 7) {
  4228.                 //PrintToServer("[HITGROUP HURT LIMBS]");
  4229.                 if (dmg_taken >= g_iCvar_fatal_limb_dmg && (fRandom <= g_fCvar_fatal_chance)) {
  4230.                     // Hurt fatally
  4231.                     g_iHurtFatal[victim] = 1;
  4232.  
  4233.                     //PrintToServer("[PLAYER HURT LIMBS]");
  4234.                 }
  4235.             }
  4236.         }
  4237.     }
  4238.     //Track wound type (minor, moderate, critical)
  4239.     if (g_iHurtFatal[victim] != 1) {
  4240.         if (dmg_taken <= g_minorWound_dmg) {
  4241.             g_playerWoundTime[victim] = g_minorRevive_time;
  4242.             g_playerWoundType[victim] = 0;
  4243.         }
  4244.         else if (dmg_taken > g_minorWound_dmg && dmg_taken <= g_moderateWound_dmg) {
  4245.             g_playerWoundTime[victim] = g_modRevive_time;
  4246.             g_playerWoundType[victim] = 1;
  4247.         }
  4248.         else if (dmg_taken > g_moderateWound_dmg) {
  4249.             g_playerWoundTime[victim] = g_critRevive_time;
  4250.             g_playerWoundType[victim] = 2;
  4251.         }
  4252.     }
  4253.     else {
  4254.         g_playerWoundTime[victim] = -1;
  4255.         g_playerWoundType[victim] = -1;
  4256.     }
  4257.  
  4258.     ////////////////////////
  4259.     // Rank System
  4260.     int attackerId = event.GetInt("attacker");
  4261.     int hitgroup = event.GetInt("hitgroup");
  4262.  
  4263.     int attacker = GetClientOfUserId(attackerId);
  4264.  
  4265.     if (hitgroup == 1) {
  4266.         g_iStatHeadShots[attacker]++;
  4267.     }
  4268.     ////////////////////////
  4269.  
  4270.     return Plugin_Continue;
  4271. }
  4272.  
  4273. // Triggered when player die PRE
  4274. public Action Event_PlayerDeath_Pre(Event event, const char[] name, bool dontBroadcast)
  4275. {
  4276.         int client = GetClientOfUserId(event.GetInt("userid"));
  4277.         // Tracking ammo
  4278.         if (g_iEnableRevive == 1 && g_iRoundStatus == 1 && g_iCvar_enable_track_ammo == 1)
  4279.         {
  4280.             //PrintToChatAll("### GET PLAYER WEAPONS ###");
  4281.             //CONSIDER IF PLAYER CHOOSES DIFFERENT CLASS
  4282.             // Get weapons
  4283.             int primaryWeapon = GetPlayerWeaponSlot(client, 0);
  4284.             int secondaryWeapon = GetPlayerWeaponSlot(client, 1);
  4285.  
  4286.             // Set weapons to variables
  4287.             playerPrimary[client] = primaryWeapon;
  4288.             playerSecondary[client] = secondaryWeapon;
  4289.  
  4290.             //Get ammo left in clips for primary and secondary
  4291.             playerClip[client][0] = GetPrimaryAmmo(client, primaryWeapon, 0);
  4292.             playerClip[client][1] = GetPrimaryAmmo(client, secondaryWeapon, 1); // m_iClip2 for secondary if this doesnt work? would need GetSecondaryAmmo
  4293.  
  4294.             if (!playerInRevivedState[client])
  4295.             {
  4296.                 //Get Magazines left on player
  4297.                 if (primaryWeapon != -1 && IsValidEntity(primaryWeapon))
  4298.                      Client_GetWeaponPlayerAmmoEx(client, primaryWeapon, playerAmmo[client][0]); //primary
  4299.                 if (secondaryWeapon != -1 && IsValidEntity(secondaryWeapon))
  4300.                      Client_GetWeaponPlayerAmmoEx(client, secondaryWeapon, playerAmmo[client][1]); //secondary 
  4301.             }
  4302.             playerInRevivedState[client] = false;
  4303.         }
  4304. }
  4305.  
  4306. //Thanks to Headline for fixing part of this function
  4307. // Trigged when player die
  4308. public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
  4309.     ////////////////////////
  4310.     // Rank System
  4311.     int victimId = event.GetInt("userid");
  4312.     int attackerId = event.GetInt("attacker");
  4313.     int victim = GetClientOfUserId(victimId);
  4314.     int attacker = GetClientOfUserId(attackerId);
  4315.  
  4316.     if (victim != attacker) {
  4317.         g_iStatKills[attacker]++;
  4318.         g_iStatDeaths[victim]++;
  4319.     }
  4320.     else {
  4321.         g_iStatSuicides[victim]++;
  4322.         g_iStatDeaths[victim]++;
  4323.     }
  4324.  
  4325.     // Get player ID
  4326.     int client = GetClientOfUserId(event.GetInt("userid"));
  4327.     // Check client valid
  4328.     if (!(0 < attacker <= MaxClients) || !IsClientInGame(client)) {
  4329.         return Plugin_Continue;
  4330.     } {
  4331.         g_iPlayerBGroups[client] = GetEntProp(client, Prop_Send, "m_nBody");
  4332.     }
  4333.     //PrintToServer("BodyGroups: %d", g_iPlayerBGroups[client]);
  4334.  
  4335.     // Set variable
  4336.     int dmg_taken = event.GetInt("damagebits");
  4337.     if (dmg_taken <= 0) {
  4338.         g_playerWoundTime[client] = g_minorRevive_time;
  4339.         g_playerWoundType[client] = 0;
  4340.     }
  4341.  
  4342.     //PrintToServer("[PLAYERDEATH] Client %N has %d lives remaining", client, g_iSpawnTokens[client]);
  4343.  
  4344.     // Get gamemode
  4345.     char sGameMode[32];
  4346.     FindConVar("mp_gamemode").GetString(sGameMode, sizeof(sGameMode));
  4347.     int team = GetClientTeam(client);
  4348.     int attackerTeam = GetClientTeam(attacker);
  4349.  
  4350.     //AI Director START
  4351.     //Bot Team AD Status
  4352.     if (team == TEAM_2_INS && g_iRoundStatus == 1 && attackerTeam == TEAM_1_SEC) {
  4353.         //Bonus point for specialty bots
  4354.         if (AI_Director_IsSpecialtyBot(client)) {
  4355.             g_AIDir_TeamStatus += 1;
  4356.         }
  4357.         g_AIDir_BotsKilledCount++;
  4358.         if (g_AIDir_BotsKilledCount > (GetTeamSecCount() / g_AIDir_BotsKilledReq_mult)) {
  4359.             g_AIDir_BotsKilledCount = 0;
  4360.             g_AIDir_TeamStatus += 1;
  4361.         }
  4362.     }
  4363.         //Player Team AD STATUS
  4364.     if (team == TEAM_1_SEC && g_iRoundStatus == 1) {
  4365.         if (g_iHurtFatal[client] == 1) {
  4366.             g_AIDir_TeamStatus -= 3;
  4367.         }
  4368.         else {
  4369.             g_AIDir_TeamStatus -= 2;
  4370.         }
  4371.         if ((StrContains(g_client_last_classstring[client], "medic") > -1)) {
  4372.             g_AIDir_TeamStatus -= 3;
  4373.         }
  4374.     }
  4375.     g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  4376.  
  4377.     //AI Director END
  4378.     if (g_iCvar_revive_enable) {
  4379.         // Convert ragdoll
  4380.         if (team == TEAM_1_SEC) {
  4381.             // Get current position
  4382.             float vecPos[3];
  4383.             GetClientAbsOrigin(client, vecPos);
  4384.             g_fDeadPosition[client] = vecPos;
  4385.  
  4386.                 // Call ragdoll timer
  4387.             if (g_iEnableRevive == 1 && g_iRoundStatus == 1) {
  4388.                 CreateTimer(5.0, ConvertDeleteRagdoll, client);
  4389.             }
  4390.         }
  4391.     }
  4392.     // Check enables
  4393.     if (g_iCvar_respawn_enable) {
  4394.         // Client should be TEAM_1_SEC = HUMANS or TEAM_2_INS = BOTS
  4395.         if ((team == TEAM_1_SEC) || (team == TEAM_2_INS)) {
  4396.             // The number of control points
  4397.             int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  4398.  
  4399.             // Active control point
  4400.             int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  4401.  
  4402.             // Do not decrease life in counterattack
  4403.             if (g_isCheckpoint == 1 && Ins_InCounterAttack() &&
  4404.                 (((acp+1) == ncp &&  g_iCvar_final_counterattack_type == 2) ||
  4405.                 ((acp+1) != ncp && g_iCvar_counterattack_type == 2))) {
  4406.                 // Respawn type 1 bots
  4407.                 if ((g_iCvar_respawn_type_team_ins == 1 && team == TEAM_2_INS) &&
  4408.                 (((acp+1) == ncp &&  g_iCvar_final_counterattack_type == 2) ||
  4409.                 ((acp+1) != ncp && g_iCvar_counterattack_type == 2))) {
  4410.                     if ((g_iSpawnTokens[client] < g_iRespawnCount[team])) {
  4411.                         g_iSpawnTokens[client] = (g_iRespawnCount[team] + 1);
  4412.                     }
  4413.  
  4414.                     // Call respawn timer
  4415.                     CreateBotRespawnTimer(client);
  4416.                 }
  4417.                 // Respawn type 1 player (individual lives)
  4418.                 else if (g_iCvar_respawn_type_team_sec == 1 && team == TEAM_1_SEC) {
  4419.                     if (g_iSpawnTokens[client] > 0) {
  4420.                         if (team == TEAM_1_SEC) {
  4421.                             CreatePlayerRespawnTimer(client);
  4422.                         }
  4423.                     }
  4424.                     else if (g_iSpawnTokens[client] <= 0 && g_iRespawnCount[team] > 0) {
  4425.                         // Cannot respawn anymore
  4426.                         char sChat[128];
  4427.                         Format(sChat, 128,"You cannot be respawned anymore. (out of lives)");
  4428.                         PrintToChat(client, "%s", sChat);
  4429.                     }
  4430.                 }
  4431.                 // Respawn type 2 for players
  4432.                 else if (team == TEAM_1_SEC && g_iCvar_respawn_type_team_sec == 2 && g_iRespawn_lives_team_sec > 0) {
  4433.                     g_iRemaining_lives_team_sec = g_iRespawn_lives_team_sec + 1;
  4434.  
  4435.                     // Call respawn timer
  4436.                     CreateCounterRespawnTimer(client);
  4437.                 }
  4438.                 // Respawn type 2 for bots
  4439.                 else if (team == TEAM_2_INS && g_iCvar_respawn_type_team_ins == 2 &&
  4440.                 (g_iRespawn_lives_team_ins > 0 ||
  4441.                 ((acp+1) == ncp && g_iCvar_final_counterattack_type == 2) ||
  4442.                 ((acp+1) != ncp && g_iCvar_counterattack_type == 2))) {
  4443.                     g_iRemaining_lives_team_ins = g_iRespawn_lives_team_ins + 1;
  4444.  
  4445.                     // Call respawn timer
  4446.                     CreateBotRespawnTimer(client);
  4447.                 }
  4448.             }
  4449.             // Normal respawn
  4450.             else if ((g_iCvar_respawn_type_team_sec == 1 && team == TEAM_1_SEC) ||
  4451.                 (g_iCvar_respawn_type_team_ins == 1 && team == TEAM_2_INS)) {
  4452.                 if (g_iSpawnTokens[client] > 0) {
  4453.                     if (team == TEAM_1_SEC) {
  4454.                         CreatePlayerRespawnTimer(client);
  4455.                     }
  4456.                     else if (team == TEAM_2_INS) {
  4457.                         CreateBotRespawnTimer(client);
  4458.                     }
  4459.                 }
  4460.                 else if (g_iSpawnTokens[client] <= 0 && g_iRespawnCount[team] > 0) {
  4461.                     // Cannot respawn anymore
  4462.                     char sChat[128];
  4463.                     Format(sChat, 128,"You cannot be respawned anymore. (out of lives)");
  4464.                     PrintToChat(client, "%s", sChat);
  4465.                 }
  4466.             }
  4467.             // Respawn type 2 for players
  4468.             else if (g_iCvar_respawn_type_team_sec == 2 && team == TEAM_1_SEC) {
  4469.                 if (g_iRemaining_lives_team_sec > 0) {
  4470.                     CreatePlayerRespawnTimer(client);
  4471.                 }
  4472.                 else if (g_iRemaining_lives_team_sec <= 0 && g_iRespawn_lives_team_sec > 0) {
  4473.                     // Cannot respawn anymore
  4474.                     char sChat[128];
  4475.                     Format(sChat, 128,"You cannot be respawned anymore. (out of team lives)");
  4476.                     PrintToChat(client, "%s", sChat);
  4477.                 }
  4478.             }
  4479.             // Respawn type 2 for bots
  4480.             else if (g_iCvar_respawn_type_team_ins == 2 && g_iRemaining_lives_team_ins >  0 && team == TEAM_2_INS) {
  4481.                 CreateBotRespawnTimer(client);
  4482.             }
  4483.         }
  4484.     }
  4485.  
  4486.     // Init variables
  4487.     char wound_hint[64];
  4488.     char fatal_hint[64];
  4489.     char woundType[64];
  4490.     if (g_playerWoundType[client] == 0) {
  4491.         woundType = "MINORLY WOUNDED";
  4492.     }
  4493.     else if (g_playerWoundType[client] == 1) {
  4494.         woundType = "MODERATELY WOUNDED";
  4495.     }
  4496.     else if (g_playerWoundType[client] == 2) {
  4497.         woundType = "CRITCALLY WOUNDED";
  4498.     }
  4499.  
  4500.     // Display death message
  4501.     if (g_fCvar_fatal_chance > 0.0) {
  4502.         if (g_iHurtFatal[client] == 1 && !IsFakeClient(client)) {
  4503.                 Format(fatal_hint, 255,"You were fatally killed for %i damage", g_clientDamageDone[client]);
  4504.                 PrintHintText(client, "%s", fatal_hint);
  4505.                 PrintToChat(client, "%s", fatal_hint);
  4506.         }
  4507.         else {
  4508.                 Format(wound_hint, 255,"You're %s for %i damage, call a medic for revive!", woundType, g_clientDamageDone[client]);
  4509.                 PrintHintText(client, "%s", wound_hint);
  4510.                 PrintToChat(client, "%s", wound_hint);
  4511.         }
  4512.     }
  4513.         else {
  4514.         Format(wound_hint, 255,"You're %s for %i damage, call a medic for revive!", woundType, g_clientDamageDone[client]);
  4515.         PrintHintText(client, "%s", wound_hint);
  4516.         PrintToChat(client, "%s", wound_hint);
  4517.     }
  4518.  
  4519.  
  4520.         // Update remaining life
  4521.         // ConVar hCvar = null;
  4522.         // new iRemainingLife = GetRemainingLife();
  4523.         // ConVar hCvar = FindConVar("sm_remaininglife");
  4524.         // hCvar.SetInt(iRemainingLife);
  4525.  
  4526.     return Plugin_Continue;
  4527. }
  4528.  
  4529. // Convert dead body to new ragdoll
  4530. public Action ConvertDeleteRagdoll(Handle timer, any client)
  4531. {  
  4532.     if (IsClientInGame(client) && g_iRoundStatus == 1 && !IsPlayerAlive(client))
  4533.     {
  4534.         //PrintToServer("CONVERT RAGDOLL********************");
  4535.         //new clientRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
  4536.         //TeleportEntity(clientRagdoll, g_fDeadPosition[client], NULL_VECTOR, NULL_VECTOR);
  4537.        
  4538.         // Get dead body
  4539.         int clientRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
  4540.        
  4541.         //This timer safely removes client-side ragdoll
  4542.         if(clientRagdoll > 0 && IsValidEdict(clientRagdoll) && IsValidEntity(clientRagdoll) && g_iEnableRevive == 1)
  4543.         {
  4544.             // Get dead body's entity
  4545.             int ref = EntIndexToEntRef(clientRagdoll);
  4546.             int entity = EntRefToEntIndex(ref);
  4547.             if(entity != INVALID_ENT_REFERENCE && IsValidEntity(entity))
  4548.             {
  4549.                 // Remove dead body's entity
  4550.                 AcceptEntityInput(entity, "Kill");
  4551.                 clientRagdoll = INVALID_ENT_REFERENCE;
  4552.             }
  4553.         }
  4554.        
  4555.         // Check is fatally dead
  4556.         if (g_iHurtFatal[client] != 1)
  4557.         {
  4558.             // Create new ragdoll
  4559.             int tempRag = CreateEntityByName("prop_ragdoll");
  4560.            
  4561.             // Set client's new ragdoll
  4562.             g_iClientRagdolls[client]  = EntIndexToEntRef(tempRag);
  4563.            
  4564.             // Set position
  4565.             g_fDeadPosition[client][2] = g_fDeadPosition[client][2] + 50;
  4566.            
  4567.             // If success initialize ragdoll
  4568.             if(tempRag != -1)
  4569.             {
  4570.                 // Get model name
  4571.                 char sModelName[64];
  4572.                 GetClientModel(client, sModelName, sizeof(sModelName));
  4573.                
  4574.                 // Set model
  4575.                 SetEntityModel(tempRag, sModelName);
  4576.                 DispatchSpawn(tempRag);
  4577.                
  4578.                 // Set collisiongroup
  4579.                 SetEntProp(tempRag, Prop_Send, "m_CollisionGroup", 17);
  4580.                 //Set bodygroups for ragdoll
  4581.                     SetEntProp(tempRag, Prop_Send, "m_nBody", g_iPlayerBGroups[client]);
  4582.                
  4583.                 // Teleport to current position
  4584.                 TeleportEntity(tempRag, g_fDeadPosition[client], NULL_VECTOR, NULL_VECTOR);
  4585.                
  4586.                 // Set vector
  4587.                 GetEntPropVector(tempRag, Prop_Send, "m_vecOrigin", g_fRagdollPosition[client]);
  4588.                
  4589.                 // Set revive time remaining
  4590.                 g_iReviveRemainingTime[client] = g_playerWoundTime[client];
  4591.                 g_iReviveNonMedicRemainingTime[client] = g_nonMedRevive_time;
  4592.                 // Start revive checking timer
  4593.                 /*
  4594.                 Handle revivePack;
  4595.                 CreateDataTimer(1.0 , Timer_RevivePeriod, revivePack, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
  4596.                 revivePack.WriteCell(client);
  4597.                 revivePack.WriteCell(tempRag);
  4598.                 */
  4599.             }
  4600.             else
  4601.             {
  4602.                 // If failed to create ragdoll, remove entity
  4603.                 if(tempRag > 0 && IsValidEdict(tempRag) && IsValidEntity(tempRag))
  4604.                 {
  4605.                     RemoveRagdoll(client);
  4606.                 }
  4607.             }
  4608.         }
  4609.     }
  4610. }
  4611.  
  4612. // Remove ragdoll
  4613. void RemoveRagdoll(int client)
  4614. {
  4615.     //new ref = EntIndexToEntRef(g_iClientRagdolls[client]);
  4616.     int entity = EntRefToEntIndex(g_iClientRagdolls[client]);
  4617.     if(entity != INVALID_ENT_REFERENCE && IsValidEntity(entity))
  4618.     {
  4619.         AcceptEntityInput(entity, "Kill");
  4620.         g_iClientRagdolls[client] = INVALID_ENT_REFERENCE;
  4621.     }  
  4622. }
  4623.  
  4624. // This handles revives by medics
  4625. void CreateReviveTimer(int client)
  4626. {
  4627.     CreateTimer(0.0, RespawnPlayerRevive, client);
  4628. }
  4629.  
  4630. // Handles spawns when counter attack starts
  4631. void CreateCounterRespawnTimer(int client)
  4632. {
  4633.     CreateTimer(0.0, RespawnPlayerCounter, client);
  4634. }
  4635.  
  4636. // Respawn bot
  4637. void CreateBotRespawnTimer(int client)
  4638. {  
  4639.     CreateTimer(g_fCvar_respawn_delay_team_ins, RespawnBot, client);
  4640. }
  4641.  
  4642. // Respawn player
  4643. void CreatePlayerRespawnTimer(int client)
  4644. {
  4645.     // Check is respawn timer active
  4646.     if (g_iPlayerRespawnTimerActive[client] == 0)
  4647.     {
  4648.         // Set timer active
  4649.         g_iPlayerRespawnTimerActive[client] = 1;
  4650.        
  4651.         //new validAntenna = -1;
  4652.         //validAntenna = FindValid_Antenna();
  4653.  
  4654.         // Set remaining timer for respawn
  4655.         //if (validAntenna != -1)
  4656.         //{
  4657.         int timeReduce = (GetTeamSecCount() / 3);
  4658.         if (timeReduce <= 0)
  4659.         {
  4660.             timeReduce = 3;
  4661.         }
  4662.  
  4663.         int jammerSpawnReductionAmt = (g_iRespawnSeconds / timeReduce);
  4664.         g_iRespawnTimeRemaining[client] = (g_iRespawnSeconds - jammerSpawnReductionAmt);
  4665.         if (g_iRespawnTimeRemaining[client] < 5)
  4666.                 g_iRespawnTimeRemaining[client] = 5;
  4667.         else
  4668.             g_iRespawnTimeRemaining[client] = g_iRespawnSeconds;
  4669.        
  4670.         //Sync wave based timer if enabled
  4671.         if (g_respawn_mode_team_sec)
  4672.         {
  4673.             g_iRespawnTimeRemaining[client] = g_secWave_Timer;
  4674.         }
  4675.  
  4676.         // Call respawn timer
  4677.         CreateTimer(1.0, Timer_PlayerRespawn, client, TIMER_REPEAT);
  4678.     }
  4679. }
  4680.  
  4681. // Revive player
  4682. Action RespawnPlayerRevive(Handle timer, any client)
  4683. {
  4684.     // Exit if client is not in game
  4685. //  if (!IsClientInGame(client)) return;
  4686.     if (IsPlayerAlive(client) || !IsClientInGame(client) || g_iRoundStatus == 0) return;
  4687.    
  4688.     //PrintToServer("[REVIVE_RESPAWN] REVIVING client %N who has %d lives remaining", client, g_iSpawnTokens[client]);
  4689.     // Call forcerespawn fucntion
  4690.     SDKCall(g_hForceRespawn, client);
  4691.    
  4692.     // If set 'sm_respawn_enable_track_ammo', restore player's ammo
  4693.     if (playerRevived[client] == true && g_iCvar_enable_track_ammo == 1)
  4694.     {
  4695.         playerInRevivedState[client] = true;
  4696.         SetPlayerAmmo(client); //AmmoResupply_Player(client, 0, 0, 1);
  4697.  
  4698.     }      
  4699.    
  4700.     //Set wound health
  4701.     int iHealth = GetClientHealth(client);
  4702.     if (g_playerNonMedicRevive[client] == 0)
  4703.     {
  4704.         if (g_playerWoundType[client] == 0)
  4705.             iHealth = g_minorWoundRevive_hp;
  4706.         else if (g_playerWoundType[client] == 1)
  4707.             iHealth = g_modWoundRevive_hp;
  4708.         else if (g_playerWoundType[client] == 2)
  4709.             iHealth = g_critWoundRevive_hp;
  4710.     }
  4711.     else if (g_playerNonMedicRevive[client] == 1)
  4712.     {
  4713.         //NonMedic Revived
  4714.         iHealth = g_nonMedicRevive_hp;
  4715.     }
  4716.  
  4717.     SetEntityHealth(client, iHealth);
  4718.    
  4719.     // Get player's ragdoll
  4720.     int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  4721.    
  4722.     //Remove network ragdoll
  4723.     if(playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  4724.         RemoveRagdoll(client);
  4725.    
  4726.     //Do the post-spawn stuff like moving to final "spawnpoint" selected
  4727.     //CreateTimer(0.0, RespawnPlayerRevivePost, client);
  4728.     RespawnPlayerRevivePost(null, client);
  4729.     if ((StrContains(g_client_last_classstring[client], "medic") > -1))
  4730.         g_AIDir_TeamStatus += 2;
  4731.     else
  4732.         g_AIDir_TeamStatus += 1;
  4733.     g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  4734. }
  4735.  
  4736. // Do post revive stuff
  4737. Action RespawnPlayerRevivePost(Handle timer, any client)
  4738. {
  4739.     // Exit if client is not in game
  4740.     if (!IsClientInGame(client)) return;
  4741.    
  4742.     //PrintToServer("[REVIVE_DEBUG] called RespawnPlayerRevivePost for client %N (%d)",client,client);
  4743.     TeleportEntity(client, g_fRagdollPosition[client], NULL_VECTOR, NULL_VECTOR);
  4744.    
  4745.     //Check if player is connected and is alive and player team is security
  4746.     int m_iTeam = GetClientTeam(client);
  4747.     if((IsClientConnected(client)) && (IsPlayerAlive(client)) && m_iTeam == TEAM_1_SEC)
  4748.     {  
  4749.         //Set health 100 percent if resupplying
  4750.         int iHealth = GetClientHealth(client);
  4751.         if (iHealth < 100)
  4752.             SetEntityHealth(client, 100);
  4753.         playerInRevivedState[client] = false;
  4754.     }
  4755.     // Reset ragdoll position
  4756.     g_fRagdollPosition[client][0] = 0.0;
  4757.     g_fRagdollPosition[client][1] = 0.0;
  4758.     g_fRagdollPosition[client][2] = 0.0;
  4759. }
  4760.  
  4761. // Respawn player in counter attack
  4762. Action RespawnPlayerCounter(Handle timer, any client)
  4763. {
  4764.     // Exit if client is not in game
  4765.     if (!IsClientInGame(client)) return;
  4766.     if (IsPlayerAlive(client) || g_iRoundStatus == 0) return;
  4767.    
  4768.     //PrintToServer("[Counter Respawn] Respawning client %N who has %d lives remaining", client, g_iSpawnTokens[client]);
  4769.     // Call forcerespawn fucntion
  4770.     SDKCall(g_hForceRespawn, client);
  4771.  
  4772.     // Get player's ragdoll
  4773.     int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  4774.    
  4775.     //Remove network ragdoll
  4776.     if(playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  4777.         RemoveRagdoll(client);
  4778.    
  4779.     // If set 'sm_respawn_enable_track_ammo', restore player's ammo
  4780.     // Get the number of control points
  4781.     //new ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  4782.     // Get active push point
  4783.     //new acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  4784.    
  4785.     //Remove grenades if not final
  4786.     //if ((acp+1) != ncp)
  4787.     //RemoveWeapons(client, 0, 0, 1);
  4788.  
  4789.     // Teleport to active counter attack point
  4790.     //PrintToServer("[REVIVE_DEBUG] called RespawnPlayerPost for client %N (%d)",client,client);
  4791.     if (g_fRespawnPosition[0] != 0.0 && g_fRespawnPosition[1] != 0.0 && g_fRespawnPosition[2] != 0.0)
  4792.         TeleportEntity(client, g_fRespawnPosition, NULL_VECTOR, NULL_VECTOR);
  4793.  
  4794.     // Reset ragdoll position
  4795.     g_fRagdollPosition[client][0] = 0.0;
  4796.     g_fRagdollPosition[client][1] = 0.0;
  4797.     g_fRagdollPosition[client][2] = 0.0;
  4798. }
  4799.  
  4800.  
  4801. // Respawn bot
  4802. public Action RespawnBot(Handle timer, any client)
  4803. {
  4804.  
  4805.     // Exit if client is not in game
  4806.     //if (IsPlayerAlive(client) || !IsClientInGame(client) || g_iRoundStatus == 0) return;
  4807.     //if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && owner > 0 && GetClientTeam(owner) == 3)
  4808.    
  4809.     //if (client > 0 && !IsClientInGame(client) || IsPlayerAlive(client) || g_iRoundStatus == 0)
  4810.  
  4811.     if (client <= 0 || client > MaxClients || !IsClientInGame(client) || IsPlayerAlive(client) || g_iRoundStatus == 0) return; 
  4812.     char sModelName[64];
  4813.     GetClientModel(client, sModelName, sizeof(sModelName));
  4814.     if (StrEqual(sModelName, "")) return;  
  4815.    
  4816.     // Check respawn type
  4817.     if (g_iCvar_respawn_type_team_ins == 1 && g_iSpawnTokens[client] > 0)
  4818.         g_iSpawnTokens[client]--;
  4819.     else if (g_iCvar_respawn_type_team_ins == 2)
  4820.     {
  4821.         if (g_iRemaining_lives_team_ins > 0)
  4822.         {
  4823.             g_iRemaining_lives_team_ins--;
  4824.             if (g_iRemaining_lives_team_ins <= 0)
  4825.                 g_iRemaining_lives_team_ins = 0;
  4826.             //PrintToServer("######################TEAM 2 LIVES REMAINING %i", g_iRemaining_lives_team_ins);
  4827.         }
  4828.     }
  4829.     //PrintToServer("######################TEAM 2 LIVES REMAINING %i", g_iRemaining_lives_team_ins);
  4830.     //PrintToServer("######################TEAM 2 LIVES REMAINING %i", g_iRemaining_lives_team_ins);
  4831.     //PrintToServer("[RESPAWN] Respawning client %N who has %d lives remaining", client, g_iSpawnTokens[client]);
  4832.    
  4833.     // Call forcerespawn function
  4834.    
  4835.     //if (client !=0) SDKCall(g_hForceRespawn, client);
  4836.  
  4837.     //if ((0 >= client || client > MaxClients) || !IsClientInGame(client))
  4838.     if ((0 < client <= MaxClients) || !IsClientInGame(client))
  4839.     {
  4840.        
  4841.         SDKCall(g_hForceRespawn, client);  
  4842.     }
  4843. }
  4844.  
  4845. // Monitor player reload and set ammo after each reload
  4846. Action Timer_ForceReload(Handle timer, any client)
  4847. {
  4848.     bool isReloading = Client_IsReloading(client);
  4849.     int primaryWeapon = GetPlayerWeaponSlot(client, 0);
  4850.     int secondaryWeapon = GetPlayerWeaponSlot(client, 1);
  4851.  
  4852.     if (IsPlayerAlive(client) && g_iRoundStatus == 1 && !isReloading && g_playerActiveWeapon[client] == primaryWeapon)
  4853.     {
  4854.         playerAmmo[client][0] -= 1;
  4855.         SetPlayerAmmo(client);
  4856.         return Plugin_Stop;
  4857.     }
  4858.  
  4859.     if (IsPlayerAlive(client) && g_iRoundStatus == 1 && !isReloading && g_playerActiveWeapon[client] == secondaryWeapon)
  4860.     {
  4861.         playerAmmo[client][1] -= 1;
  4862.         SetPlayerAmmo(client);
  4863.         return Plugin_Stop;
  4864.     }
  4865.     return Plugin_Continue;
  4866. }
  4867.  
  4868. // Player respawn timer
  4869. Action Timer_PlayerRespawn(Handle timer, any client)
  4870. {
  4871.     char sRemainingTime[256];
  4872.  
  4873.     // Exit if client is not in game
  4874.     if (!IsClientInGame(client)) return Plugin_Stop; // empty class name
  4875.     if (!IsPlayerAlive(client) && g_iRoundStatus == 1)
  4876.     {
  4877.         if (g_iRespawnTimeRemaining[client] > 0)
  4878.         {  
  4879.             if (g_playerFirstJoin[client] == 1)
  4880.             {
  4881.                 char woundType[128];
  4882.                 int tIsFatal = false;
  4883.                 if (g_iHurtFatal[client] == 1)
  4884.                 {
  4885.                     woundType = "fatally killed";
  4886.                     tIsFatal = true;
  4887.                 }
  4888.                 else
  4889.                 {
  4890.                     woundType = "WOUNDED";
  4891.                     if (g_playerWoundType[client] == 0)
  4892.                         woundType = "MINORLY WOUNDED";
  4893.                     else if (g_playerWoundType[client] == 1)
  4894.                         woundType = "MODERATELY WOUNDED";
  4895.                     else if (g_playerWoundType[client] == 2)
  4896.                         woundType = "CRITCALLY WOUNDED";
  4897.                 }
  4898.                 // Print remaining time to center text area
  4899.                 if (!IsFakeClient(client))
  4900.                 {
  4901.                     if (tIsFatal)
  4902.                     {
  4903.                         Format(sRemainingTime, sizeof(sRemainingTime),"Reinforcing in %d second%s (%d lives left) ", woundType, g_clientDamageDone[client], g_iRespawnTimeRemaining[client], (g_iRespawnTimeRemaining[client] > 1 ? "s" : ""), g_iSpawnTokens[client]);
  4904.                     }
  4905.                     else
  4906.                     {
  4907.                         Format(sRemainingTime, sizeof(sRemainingTime),"%s for %d damage | wait patiently for a medic\n\n                Reinforcing in %d second%s (%d lives left) ", woundType, g_clientDamageDone[client], g_iRespawnTimeRemaining[client], (g_iRespawnTimeRemaining[client] > 1 ? "s" : ""), g_iSpawnTokens[client]);
  4908.                     }
  4909.                     PrintCenterText(client, sRemainingTime);
  4910.                 }
  4911.             }
  4912.            
  4913.             // Decrease respawn remaining time
  4914.             g_iRespawnTimeRemaining[client]--;
  4915.         }
  4916.         else
  4917.         {
  4918.             // Decrease respawn token
  4919.             if (g_iCvar_respawn_type_team_sec == 1)
  4920.                 g_iSpawnTokens[client]--;
  4921.             else if (g_iCvar_respawn_type_team_sec == 2)
  4922.                 g_iRemaining_lives_team_sec--;
  4923.            
  4924.             // Call forcerespawn function
  4925.             SDKCall(g_hForceRespawn, client);
  4926.  
  4927.             //AI Director START
  4928.             if ((StrContains(g_client_last_classstring[client], "medic") > -1))
  4929.                 g_AIDir_TeamStatus += 2;
  4930.             else
  4931.                 g_AIDir_TeamStatus += 1;
  4932.  
  4933.             g_AIDir_TeamStatus = AI_Director_SetMinMax(g_AIDir_TeamStatus, g_AIDir_TeamStatus_min, g_AIDir_TeamStatus_max);
  4934.                
  4935.             //AI Director STOP
  4936.  
  4937.             // Print remaining time to center text area
  4938.             if (!IsFakeClient(client))
  4939.                 PrintCenterText(client, "You reinforced! (%d lives left)", g_iSpawnTokens[client]);
  4940.  
  4941.            
  4942.             bool tSquadSpawned = false;             //Lets confirm squad spawn
  4943.             int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]); // Get ragdoll position
  4944.            
  4945.             // Remove network ragdoll
  4946.             if(playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  4947.                 RemoveRagdoll(client);
  4948.            
  4949.             // Do the post-spawn stuff like moving to final "spawnpoint" selected
  4950.             //CreateTimer(0.0, RespawnPlayerPost, client);
  4951.             //RespawnPlayerPost(null, client);
  4952.                    
  4953.             // Reset ragdoll position
  4954.             g_fRagdollPosition[client][0] = 0.0;
  4955.             g_fRagdollPosition[client][1] = 0.0;
  4956.             g_fRagdollPosition[client][2] = 0.0;
  4957.  
  4958.             // Announce respawn if not wave based (to avoid spam)
  4959.             if (!g_respawn_mode_team_sec)
  4960.             {
  4961.             if (g_squadSpawnEnabled[client] == 1 && tSquadSpawned == true)
  4962.                     PrintToChatAll("\x05%N\x01 squad-reinforced on %N", client, g_squadLeader[client]);
  4963.                 else
  4964.                     PrintToChatAll("\x05%N\x01 reinforced..", client);
  4965.             }
  4966.             // Reset variable
  4967.             g_iPlayerRespawnTimerActive[client] = 0;
  4968.             return Plugin_Stop;
  4969.         }
  4970.     }
  4971.     else
  4972.     {
  4973.         // Reset variable
  4974.         g_iPlayerRespawnTimerActive[client] = 0;
  4975.         return Plugin_Stop;
  4976.     }
  4977.     return Plugin_Continue;
  4978. }
  4979.  
  4980.  
  4981. // Handles reviving for medics and non-medics
  4982. public Action Timer_ReviveMonitor(Handle timer, any data)
  4983. {
  4984.     // Check round state
  4985.     if (g_iRoundStatus == 0) return Plugin_Continue;
  4986.    
  4987.     // Init variables
  4988.     float fReviveDistance = 65.0;
  4989.     int iInjured;
  4990.     int iInjuredRagdoll;
  4991.     float fRagPos[3];
  4992.     float fMedicPos[3];
  4993.     float fDistance;
  4994.    
  4995.     // Search medics
  4996.     for (int iMedic = 1; iMedic <= MaxClients; iMedic++)
  4997.     {
  4998.         if (!IsClientInGame(iMedic) || IsFakeClient(iMedic))
  4999.             continue;
  5000.        
  5001.         // Is valid iMedic?
  5002.         if (IsPlayerAlive(iMedic) && (StrContains(g_client_last_classstring[iMedic], "medic") > -1))
  5003.         {
  5004.             // Check is there nearest body
  5005.             iInjured = g_iNearestBody[iMedic];
  5006.            
  5007.             // Valid nearest body
  5008.             if (iInjured > 0 && IsClientInGame(iInjured) && !IsPlayerAlive(iInjured) && g_iHurtFatal[iInjured] == 0
  5009.                 && iInjured != iMedic && GetClientTeam(iMedic) == GetClientTeam(iInjured))
  5010.             {
  5011.                 // Get found medic position
  5012.                 GetClientAbsOrigin(iMedic, fMedicPos);
  5013.                
  5014.                 // Get player's entity index
  5015.                 iInjuredRagdoll = EntRefToEntIndex(g_iClientRagdolls[iInjured]);
  5016.                
  5017.                 // Check ragdoll is valid
  5018.                 if(iInjuredRagdoll > 0 && iInjuredRagdoll != INVALID_ENT_REFERENCE
  5019.                     && IsValidEdict(iInjuredRagdoll) && IsValidEntity(iInjuredRagdoll))
  5020.                 {
  5021.                     // Get player's ragdoll position
  5022.                     GetEntPropVector(iInjuredRagdoll, Prop_Send, "m_vecOrigin", fRagPos);
  5023.                    
  5024.                     // Update ragdoll position
  5025.                     g_fRagdollPosition[iInjured] = fRagPos;
  5026.                    
  5027.                     // Get distance from iMedic
  5028.                     fDistance = GetVectorDistance(fRagPos,fMedicPos);
  5029.                 }
  5030.                 else
  5031.                     // Ragdoll is not valid
  5032.                     continue;
  5033.                
  5034.                 // Jareds pistols only code to verify iMedic is carrying knife
  5035.                 int ActiveWeapon = GetEntPropEnt(iMedic, Prop_Data, "m_hActiveWeapon");
  5036.                 if (ActiveWeapon < 0)
  5037.                     continue;
  5038.                
  5039.                 // Get weapon class name
  5040.                 char sWeapon[32];
  5041.                 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5042.                 //PrintToServer("[KNIFE ONLY] CheckWeapon for iMedic %d named %N ActiveWeapon %d sWeapon %s",iMedic,iMedic,ActiveWeapon,sWeapon);
  5043.                
  5044.                 // If iMedic can see ragdoll and using defib or knife
  5045.                 if (fDistance < fReviveDistance && (ClientCanSeeVector(iMedic, fRagPos, fReviveDistance))
  5046.                     && ((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1))
  5047.                 )
  5048.                 {
  5049.                     //PrintToServer("[REVIVE_DEBUG] Distance from %N to %N is %f Seconds %d", iInjured, iMedic, fDistance, g_iReviveRemainingTime[iInjured]);      
  5050.                     char sBuf[255];
  5051.                    
  5052.                     // Need more time to revive
  5053.                     if (g_iReviveRemainingTime[iInjured] > 0)
  5054.                     {
  5055.  
  5056.                         char woundType[64];
  5057.                         if (g_playerWoundType[iInjured] == 0)
  5058.                             woundType = "Minor wound";
  5059.                         else if (g_playerWoundType[iInjured] == 1)
  5060.                             woundType = "Moderate wound";
  5061.                         else if (g_playerWoundType[iInjured] == 2)
  5062.                             woundType = "Critical wound";
  5063.  
  5064.                         // Hint to iMedic
  5065.                         Format(sBuf, 255,"Reviving %N in: %i seconds (%s)", iInjured, g_iReviveRemainingTime[iInjured], woundType);
  5066.                         PrintHintText(iMedic, "%s", sBuf);
  5067.                        
  5068.                         // Hint to victim
  5069.                         Format(sBuf, 255,"%N is reviving you in: %i seconds (%s)", iMedic, g_iReviveRemainingTime[iInjured], woundType);
  5070.                         PrintHintText(iInjured, "%s", sBuf);
  5071.                        
  5072.                         // Decrease revive remaining time
  5073.                         g_iReviveRemainingTime[iInjured]--;
  5074.                        
  5075.                         //prevent respawn while reviving
  5076.                         g_iRespawnTimeRemaining[iInjured]++;
  5077.                     }
  5078.                     // Revive player
  5079.                     else if (g_iReviveRemainingTime[iInjured] <= 0)
  5080.                     {  
  5081.                         char woundType[64];
  5082.                         if (g_playerWoundType[iInjured] == 0)
  5083.                             woundType = "minor wound";
  5084.                         else if (g_playerWoundType[iInjured] == 1)
  5085.                             woundType = "moderate wound";
  5086.                         else if (g_playerWoundType[iInjured] == 2)
  5087.                             woundType = "critical wound";
  5088.  
  5089.                         // Chat to all
  5090.                         //Format(sBuf, 255,"\x05%N\x01 revived \x03%N from a %s", iMedic, iInjured, woundType);
  5091.                         //PrintToChatAll("%s", sBuf);
  5092.                        
  5093.                         // Hint to iMedic
  5094.                         Format(sBuf, 255,"You revived %N from a %s", iInjured, woundType);
  5095.                         PrintHintText(iMedic, "%s", sBuf);
  5096.                        
  5097.                         // Hint to victim
  5098.                         Format(sBuf, 255,"%N revived you from a %s", iMedic, woundType);
  5099.                         PrintHintText(iInjured, "%s", sBuf);
  5100.                         g_iStatRevives[iMedic]++;
  5101.            
  5102.                         //Accumulate a revive
  5103.                         g_playerMedicRevivessAccumulated[iMedic]++;
  5104.                         int iReviveCap = sm_revive_cap_for_bonus.IntValue;
  5105.  
  5106.                         // Hint to iMedic
  5107.                         Format(sBuf, 255,"You revived %N from a %s | Revives remaining til bonus life: %d", iInjured, woundType, (iReviveCap - g_playerMedicRevivessAccumulated[iMedic]));
  5108.                         PrintHintText(iMedic, "%s", sBuf);
  5109.                         if (g_playerMedicRevivessAccumulated[iMedic] >= iReviveCap)
  5110.                         {
  5111.                             g_playerMedicRevivessAccumulated[iMedic] = 0;
  5112.                             g_iSpawnTokens[iMedic]++;
  5113.                         }
  5114.  
  5115.                         // Update ragdoll position
  5116.                         g_fRagdollPosition[iInjured] = fRagPos;
  5117.                        
  5118.                         // Reset revive counter
  5119.                         playerRevived[iInjured] = true;
  5120.                        
  5121.                         // Call revive function
  5122.                         g_playerNonMedicRevive[iInjured] = 0;
  5123.                         CreateReviveTimer(iInjured);
  5124.                         continue;
  5125.                     }
  5126.                 }
  5127.             }
  5128.         }
  5129.         //Non Medics with Medic Pack
  5130.         else if (IsPlayerAlive(iMedic) && !(StrContains(g_client_last_classstring[iMedic], "medic") > -1))
  5131.         {
  5132.             //PrintToServer("Non-Medic Reviving..");
  5133.             // Check is there nearest body
  5134.             iInjured = g_iNearestBody[iMedic];
  5135.            
  5136.             // Valid nearest body
  5137.             if (iInjured > 0 && IsClientInGame(iInjured) && !IsPlayerAlive(iInjured) && g_iHurtFatal[iInjured] == 0
  5138.                 && iInjured != iMedic && GetClientTeam(iMedic) == GetClientTeam(iInjured))
  5139.             {
  5140.                 // Get found medic position
  5141.                 GetClientAbsOrigin(iMedic, fMedicPos);
  5142.                
  5143.                 // Get player's entity index
  5144.                 iInjuredRagdoll = EntRefToEntIndex(g_iClientRagdolls[iInjured]);
  5145.                
  5146.                 // Check ragdoll is valid
  5147.                 if(iInjuredRagdoll > 0 && iInjuredRagdoll != INVALID_ENT_REFERENCE
  5148.                     && IsValidEdict(iInjuredRagdoll) && IsValidEntity(iInjuredRagdoll))
  5149.                 {
  5150.                     // Get player's ragdoll position
  5151.                     GetEntPropVector(iInjuredRagdoll, Prop_Send, "m_vecOrigin", fRagPos);
  5152.                    
  5153.                     // Update ragdoll position
  5154.                     g_fRagdollPosition[iInjured] = fRagPos;
  5155.                    
  5156.                     // Get distance from iMedic
  5157.                     fDistance = GetVectorDistance(fRagPos,fMedicPos);
  5158.                 }
  5159.                 else
  5160.                     // Ragdoll is not valid
  5161.                     continue;
  5162.                
  5163.                 // Jareds pistols only code to verify iMedic is carrying knife
  5164.                 int ActiveWeapon = GetEntPropEnt(iMedic, Prop_Data, "m_hActiveWeapon");
  5165.                 if (ActiveWeapon < 0)
  5166.                     continue;
  5167.                
  5168.                 // Get weapon class name
  5169.                 char sWeapon[32];
  5170.                 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5171.                 //PrintToServer("[KNIFE ONLY] CheckWeapon for iMedic %d named %N ActiveWeapon %d sWeapon %s",iMedic,iMedic,ActiveWeapon,sWeapon);
  5172.                
  5173.                 // If NON Medic can see ragdoll and using healthkit
  5174.                 if (fDistance < fReviveDistance && (ClientCanSeeVector(iMedic, fRagPos, fReviveDistance))
  5175.                     && ((StrContains(sWeapon, "weapon_healthkit") > -1)))
  5176.                 {
  5177.                     //PrintToServer("[REVIVE_DEBUG] Distance from %N to %N is %f Seconds %d", iInjured, iMedic, fDistance, g_iReviveNonMedicRemainingTime[iInjured]);      
  5178.                     char sBuf[255];
  5179.                    
  5180.                     // Need more time to reviving
  5181.                     if (g_iReviveNonMedicRemainingTime[iInjured] > 0)
  5182.                     {
  5183.  
  5184.                         //PrintToServer("NONMEDIC HAS TIME");
  5185.                         if (g_playerWoundType[iInjured] == 0 || g_playerWoundType[iInjured] == 1 || g_playerWoundType[iInjured] == 2)
  5186.                         {
  5187.                             char woundType[64];
  5188.                             if (g_playerWoundType[iInjured] == 0)
  5189.                                 woundType = "Minor wound";
  5190.                             else if (g_playerWoundType[iInjured] == 1)
  5191.                                 woundType = "Moderate wound";
  5192.                             else if (g_playerWoundType[iInjured] == 2)
  5193.                                 woundType = "Critical wound";
  5194.                             // Hint to NonMedic
  5195.                             Format(sBuf, 255,"Reviving %N in: %i seconds (%s)", iInjured, g_iReviveNonMedicRemainingTime[iInjured], woundType);
  5196.                             PrintHintText(iMedic, "%s", sBuf);
  5197.                            
  5198.                             // Hint to victim
  5199.                             Format(sBuf, 255,"%N is reviving you in: %i seconds (%s)", iMedic, g_iReviveNonMedicRemainingTime[iInjured], woundType);
  5200.                             PrintHintText(iInjured, "%s", sBuf);
  5201.                            
  5202.                             // Decrease revive remaining time
  5203.                             g_iReviveNonMedicRemainingTime[iInjured]--;
  5204.                         }
  5205.  
  5206.                         //prevent respawn while reviving
  5207.                         g_iRespawnTimeRemaining[iInjured]++;
  5208.                     }
  5209.  
  5210.                     // Revive player
  5211.                     else if (g_iReviveNonMedicRemainingTime[iInjured] <= 0)
  5212.                     {  
  5213.                         char woundType[64];
  5214.                         if (g_playerWoundType[iInjured] == 0)
  5215.                             woundType = "minor wound";
  5216.                         else if (g_playerWoundType[iInjured] == 1)
  5217.                             woundType = "moderate wound";
  5218.                         else if (g_playerWoundType[iInjured] == 2)
  5219.                             woundType = "critical wound";
  5220.  
  5221.                         // Chat to all
  5222.                         Format(sBuf, 255,"\x05%N\x01 revived \x03%N from a %s", iMedic, iInjured, woundType);
  5223.                         //PrintToChatAll("%s", sBuf);
  5224.                        
  5225.                         // Hint to iMedic
  5226.                         Format(sBuf, 255,"You revived %N from a %s", iInjured, woundType);
  5227.                         PrintHintText(iMedic, "%s", sBuf);
  5228.                        
  5229.                         // Hint to victim
  5230.                         Format(sBuf, 255,"%N revived you from a %s", iMedic, woundType);
  5231.                         PrintHintText(iInjured, "%s", sBuf);
  5232.                        
  5233.                         // Add kill bonus to iMedic
  5234.                         int iBonus = sm_revive_bonus.IntValue;
  5235.                         int iScore = GetClientFrags(iMedic) + iBonus;
  5236.                         SetEntProp(iMedic, Prop_Data, "m_iFrags", iScore);
  5237.                        
  5238.                         // Rank System
  5239.                         g_iStatRevives[iMedic]++;
  5240.                        
  5241.                         //Accumulate a revive
  5242.                         g_playerMedicRevivessAccumulated[iMedic]++;
  5243.                         int iReviveCap = sm_revive_cap_for_bonus.IntValue;
  5244.  
  5245.                         // Hint to iMedic
  5246.                         if (g_playerMedicRevivessAccumulated[iMedic] >= iReviveCap)
  5247.                         {
  5248.                             g_playerMedicRevivessAccumulated[iMedic] = 0;
  5249.                             g_iSpawnTokens[iMedic]++;
  5250.                         }
  5251.  
  5252.                        
  5253.                         // Update ragdoll position
  5254.                         g_fRagdollPosition[iInjured] = fRagPos;
  5255.                        
  5256.                         //Reward nearby medics who asssisted
  5257.                         //Check_NearbyMedicsRevive(iMedic, iInjured);
  5258.  
  5259.                         // Reset revive counter
  5260.                         playerRevived[iInjured] = true;
  5261.                        
  5262.                         g_playerNonMedicRevive[iInjured] = 1;
  5263.                         // Call revive function
  5264.                         CreateReviveTimer(iInjured);
  5265.                         RemovePlayerItem(iMedic,ActiveWeapon);
  5266.                         //Switch to knife after removing kit
  5267.                         ChangePlayerWeaponSlot(iMedic, 2);
  5268.                         //PrintToServer("##########PLAYER REVIVED %s ############", playerRevived[iInjured]);
  5269.                         continue;
  5270.                     }
  5271.                 }
  5272.             }
  5273.         }
  5274.     }
  5275.     return Plugin_Continue;
  5276. }
  5277.  
  5278. // Handles medic functions (Inspecting health, healing)
  5279. public Action Timer_MedicMonitor(Handle timer, any data)
  5280. {
  5281.     // Check round state
  5282.     if (g_iRoundStatus == 0) return Plugin_Continue;
  5283.    
  5284.     // Search medics
  5285.     for(int medic = 1; medic <= MaxClients; medic++)
  5286.     {
  5287.         if (!IsClientInGame(medic) || IsFakeClient(medic)) continue;
  5288.        
  5289.        
  5290.         // Medic only can inspect health.
  5291.         int iTeam = GetClientTeam(medic);
  5292.         if (iTeam == TEAM_1_SEC && IsPlayerAlive(medic) && StrContains(g_client_last_classstring[medic], "medic") > -1)
  5293.         {
  5294.             // Target is teammate and alive.
  5295.             int iTarget = TraceClientViewEntity(medic);
  5296.             if(iTarget > 0 && iTarget <= MaxClients && IsClientInGame(iTarget) && IsPlayerAlive(iTarget) && iTeam == GetClientTeam(iTarget))
  5297.             {
  5298.                 // Check distance
  5299.                 bool bCanHealPaddle = false;
  5300.                 bool bCanHealMedpack = false;
  5301.                 float fReviveDistance = 80.0;
  5302.                 float vecMedicPos[3];
  5303.                 float vecTargetPos[3];
  5304.                 float tDistance;
  5305.                 GetClientAbsOrigin(medic, vecMedicPos);
  5306.                 GetClientAbsOrigin(iTarget, vecTargetPos);
  5307.                 tDistance = GetVectorDistance(vecMedicPos,vecTargetPos);
  5308.                
  5309.                 if (tDistance < fReviveDistance && ClientCanSeeVector(medic, vecTargetPos, fReviveDistance))
  5310.                 {
  5311.                     // Check weapon
  5312.                     int ActiveWeapon = GetEntPropEnt(medic, Prop_Data, "m_hActiveWeapon");
  5313.                     if (ActiveWeapon < 0)
  5314.                         continue;
  5315.                     char sWeapon[32];
  5316.                     GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5317.                    
  5318.                     if ((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1))
  5319.                     {
  5320.                         bCanHealPaddle = true;
  5321.                     }
  5322.                     if ((StrContains(sWeapon, "weapon_healthkit") > -1))
  5323.                     {
  5324.                         bCanHealMedpack = true;
  5325.                     }
  5326.                 }
  5327.  
  5328.                 // Check heal
  5329.                 int iHealth = GetClientHealth(iTarget);
  5330.  
  5331.                 if (tDistance < 750.0)
  5332.                 {
  5333.                     PrintHintText(medic, "%N\nHP: %i", iTarget, iHealth);
  5334.                 }
  5335.  
  5336.                 if (bCanHealPaddle)
  5337.                 {
  5338.                     if (iHealth < 100)
  5339.                     {
  5340.                         iHealth += g_iHeal_amount_paddles;
  5341.                         g_playerMedicHealsAccumulated[medic] += g_iHeal_amount_paddles;
  5342.                         int iHealthCap = sm_heal_cap_for_bonus.IntValue;
  5343.                         int iRewardMedicEnabled = sm_reward_medics_enabled.IntValue;
  5344.  
  5345.                         //Reward player for healing
  5346.                         if (g_playerMedicHealsAccumulated[medic] >= iHealthCap && iRewardMedicEnabled == 1)
  5347.                         {
  5348.                             g_playerMedicHealsAccumulated[medic] = 0;
  5349.                             g_iSpawnTokens[medic]++;
  5350.                         }
  5351.                        
  5352.                         if (iHealth >= 100)
  5353.                         {
  5354.                             g_iStatHeals[medic]++;
  5355.                             iHealth = 100;
  5356.                             PrintHintText(iTarget, "You were healed by %N (HP: %i)", medic, iHealth);
  5357.                             char sBuf[255];
  5358.                             Format(sBuf, 255,"You fully healed %N | Health points remaining til bonus life: %d", iTarget, (iHealthCap - g_playerMedicHealsAccumulated[medic]));
  5359.                             PrintHintText(medic, "%s", sBuf);
  5360.                         }
  5361.                         else
  5362.                         {
  5363.                             PrintHintText(iTarget, "DON'T MOVE! %N is healing you.(HP: %i)", medic, iHealth);
  5364.                         }
  5365.                        
  5366.                         SetEntityHealth(iTarget, iHealth);
  5367.                         PrintHintText(medic, "%N\nHP: %i\n\nHealing with paddles for: %i", iTarget, iHealth, g_iHeal_amount_paddles);
  5368.                     }
  5369.                     else
  5370.                     {
  5371.                         PrintHintText(medic, "%N\nHP: %i", iTarget, iHealth);
  5372.                     }
  5373.                 }
  5374.                 else if (bCanHealMedpack)
  5375.                 {
  5376.                     if (iHealth < 100)
  5377.                     {
  5378.                         iHealth += g_iHeal_amount_medPack;
  5379.                         g_playerMedicHealsAccumulated[medic] += g_iHeal_amount_medPack;
  5380.                         int iHealthCap = sm_heal_cap_for_bonus.IntValue;
  5381.                         int iRewardMedicEnabled = sm_reward_medics_enabled.IntValue;
  5382.                         //Reward player for healing
  5383.                         if (g_playerMedicHealsAccumulated[medic] >= iHealthCap && iRewardMedicEnabled == 1)
  5384.                         {
  5385.                             g_playerMedicHealsAccumulated[medic] = 0;
  5386.                             g_iSpawnTokens[medic]++;
  5387.                         }
  5388.                         if (iHealth >= 100)
  5389.                         {
  5390.                             g_iStatHeals[medic]++;
  5391.                             iHealth = 100;
  5392.                             PrintHintText(iTarget, "You were healed by %N (HP: %i)", medic, iHealth);
  5393.                             char sBuf[255];
  5394.                             Format(sBuf, 255,"You fully healed %N | Health points remaining til bonus life: %d", iTarget, (iHealthCap - g_playerMedicHealsAccumulated[medic]));
  5395.                             PrintHintText(medic, "%s", sBuf);
  5396.                         }
  5397.                         else
  5398.                         {
  5399.                             PrintHintText(iTarget, "DON'T MOVE! %N is healing you.(HP: %i)", medic, iHealth);
  5400.                         }
  5401.                         SetEntityHealth(iTarget, iHealth);
  5402.                         PrintHintText(medic, "%N\nHP: %i\n\nHealing with medpack for: %i", iTarget, iHealth, g_iHeal_amount_medPack);
  5403.                     }
  5404.                     else
  5405.                     {
  5406.                         PrintHintText(medic, "%N\nHP: %i", iTarget, iHealth);
  5407.                     }
  5408.                 }
  5409.             }
  5410.             else //Heal Self
  5411.             {
  5412.                 // Check distance
  5413.                 bool bCanHealMedpack = false;
  5414.                 bool bCanHealPaddle = false;
  5415.                
  5416.                 // Check weapon
  5417.                 int ActiveWeapon = GetEntPropEnt(medic, Prop_Data, "m_hActiveWeapon");
  5418.                 if (ActiveWeapon < 0) continue;
  5419.                 char sWeapon[32];
  5420.                 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5421.  
  5422.                 if ((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1))
  5423.                 {
  5424.                     bCanHealPaddle = true;
  5425.                 }
  5426.                 if ((StrContains(sWeapon, "weapon_healthkit") > -1))
  5427.                 {
  5428.                     bCanHealMedpack = true;
  5429.                 }
  5430.                
  5431.                 // Check heal
  5432.                 int iHealth = GetClientHealth(medic);
  5433.                 if (bCanHealMedpack || bCanHealPaddle)
  5434.                 {
  5435.                     if (iHealth < g_medicHealSelf_max)
  5436.                     {
  5437.                         if (bCanHealMedpack)
  5438.                             iHealth += g_iHeal_amount_medPack;
  5439.                         else
  5440.                             iHealth += g_iHeal_amount_paddles;
  5441.  
  5442.                         if (iHealth >= g_medicHealSelf_max)
  5443.                         {
  5444.                             iHealth = g_medicHealSelf_max;
  5445.                             PrintHintText(medic, "You healed yourself (HP: %i) | MAX: %i", iHealth, g_medicHealSelf_max);
  5446.                         }
  5447.                         else
  5448.                         {
  5449.                             PrintHintText(medic, "Healing Self (HP: %i) | MAX: %i", iHealth, g_medicHealSelf_max);
  5450.                         }
  5451.                         SetEntityHealth(medic, iHealth);
  5452.                     }
  5453.                 }
  5454.             }
  5455.         }
  5456.         else if (iTeam == TEAM_1_SEC && IsPlayerAlive(medic) && !(StrContains(g_client_last_classstring[medic], "medic") > -1))
  5457.         {
  5458.             // Check weapon for non medics outside
  5459.             int ActiveWeapon = GetEntPropEnt(medic, Prop_Data, "m_hActiveWeapon");
  5460.             if (ActiveWeapon < 0)
  5461.                 continue;
  5462.             char checkWeapon[32];
  5463.             GetEdictClassname(ActiveWeapon, checkWeapon, sizeof(checkWeapon));
  5464.             if ((StrContains(checkWeapon, "weapon_healthkit") > -1))
  5465.             {
  5466.                 // Target is teammate and alive.
  5467.                 int iTarget = TraceClientViewEntity(medic);
  5468.                 if(iTarget > 0 && iTarget <= MaxClients && IsClientInGame(iTarget) && IsPlayerAlive(iTarget) && iTeam == GetClientTeam(iTarget))
  5469.                 {
  5470.                     // Check distance
  5471.                     bool bCanHealMedpack = false;
  5472.                     float fReviveDistance = 80.0;
  5473.                     float vecMedicPos[3];
  5474.                     float vecTargetPos[3];
  5475.                     float tDistance;
  5476.                     GetClientAbsOrigin(medic, vecMedicPos);
  5477.                     GetClientAbsOrigin(iTarget, vecTargetPos);
  5478.                     tDistance = GetVectorDistance(vecMedicPos,vecTargetPos);
  5479.                    
  5480.                     if (tDistance < fReviveDistance && ClientCanSeeVector(medic, vecTargetPos, fReviveDistance))
  5481.                     {
  5482.                         // Check weapon
  5483.                         if (ActiveWeapon < 0) continue;
  5484.                         char sWeapon[32];
  5485.                         GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5486.                         if ((StrContains(sWeapon, "weapon_healthkit") > -1))
  5487.                             bCanHealMedpack = true;
  5488.                     }
  5489.                     // Check heal
  5490.                     int iHealth = GetClientHealth(iTarget);
  5491.                     if (tDistance < 750.0)
  5492.                         PrintHintText(medic, "%N\nHP: %i", iTarget, iHealth);
  5493.                     if (bCanHealMedpack)
  5494.                     {
  5495.                         if (iHealth < g_nonMedic_maxHealOther)
  5496.                         {
  5497.                             iHealth += g_nonMedicHeal_amount;
  5498.                             g_playerNonMedicHealsAccumulated[medic] += g_nonMedicHeal_amount;
  5499.                             int iHealthCap = sm_heal_cap_for_bonus.IntValue;
  5500.                             int iRewardMedicEnabled = sm_reward_medics_enabled.IntValue;
  5501.                             //Reward player for healing
  5502.                             if (g_playerNonMedicHealsAccumulated[medic] >= iHealthCap && iRewardMedicEnabled == 1)
  5503.                             {
  5504.                                 g_playerNonMedicHealsAccumulated[medic] = 0;
  5505.                                 g_iSpawnTokens[medic]++;
  5506.                             }
  5507.  
  5508.                             if (iHealth >= g_nonMedic_maxHealOther)
  5509.                             {
  5510.                                 g_iStatHeals[medic]++;
  5511.                                 iHealth = g_nonMedic_maxHealOther;
  5512.                                 PrintHintText(iTarget, "Non-Medic %N can only heal you for %i HP!)", medic, iHealth);
  5513.                                 char sBuf[255];
  5514.                                 Format(sBuf, 255,"You max healed %N | Health points remaining til bonus life: %d", iTarget, (iHealthCap - g_playerNonMedicHealsAccumulated[medic]));
  5515.                                 PrintHintText(medic, "%s", sBuf);
  5516.                             }
  5517.                             else
  5518.                             {
  5519.                                 PrintHintText(iTarget, "DON'T MOVE! %N is healing you.(HP: %i)", medic, iHealth);
  5520.                             }
  5521.                             SetEntityHealth(iTarget, iHealth);
  5522.                             PrintHintText(medic, "%N\nHP: %i\n\nHealing.", iTarget, iHealth);
  5523.                         }
  5524.                         else
  5525.                         {
  5526.                             if (iHealth < g_nonMedic_maxHealOther)
  5527.                             {
  5528.                                 PrintHintText(medic, "%N\nHP: %i", iTarget, iHealth);
  5529.                             }
  5530.                             else if (iHealth >= g_nonMedic_maxHealOther)
  5531.                                 PrintHintText(medic, "%N\nHP: %i (MAX YOU CAN HEAL)", iTarget, iHealth);
  5532.                         }
  5533.                     }
  5534.                 }
  5535.                 else //Heal Self
  5536.                 {
  5537.                     // Check distance
  5538.                     bool bCanHealMedpack = false;
  5539.                    
  5540.                     // Check weapon
  5541.                     if (ActiveWeapon < 0) continue;
  5542.                     char sWeapon[32];
  5543.                     GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5544.                     if ((StrContains(sWeapon, "weapon_healthkit") > -1))
  5545.                         bCanHealMedpack = true;
  5546.  
  5547.                     // Check heal
  5548.                     int iHealth = GetClientHealth(medic);
  5549.                     if (bCanHealMedpack)
  5550.                     {
  5551.                         if (iHealth < g_nonMedicHealSelf_max)
  5552.                         {
  5553.                             iHealth += g_nonMedicHeal_amount;
  5554.                             if (iHealth >= g_nonMedicHealSelf_max)
  5555.                             {
  5556.                                 iHealth = g_nonMedicHealSelf_max;
  5557.                                 PrintHintText(medic, "You healed yourself (HP: %i) | MAX: %i", iHealth, g_nonMedicHealSelf_max);
  5558.                             }
  5559.                             else
  5560.                             {
  5561.                                 PrintHintText(medic, "Healing Self (HP: %i) | MAX: %i", iHealth, g_nonMedicHealSelf_max);
  5562.                             }
  5563.                            
  5564.                             SetEntityHealth(medic, iHealth);
  5565.                         }
  5566.                     }
  5567.                 }
  5568.             }
  5569.         }
  5570.     }
  5571.     return Plugin_Continue;
  5572. }
  5573.  
  5574. //Main AI Director Tick
  5575. public Action Timer_AIDirector_Main(Handle timer, any data)
  5576. {
  5577.     g_AIDir_AnnounceCounter++;
  5578.     g_AIDir_ChangeCond_Counter++;
  5579.     g_AIDir_AmbushCond_Counter++;
  5580.    
  5581.     //Ambush Reinforcement Chance
  5582.     int tAmbushChance = GetRandomInt(0, 100);
  5583.  
  5584.     //AI Director Set Difficulty
  5585.     if (g_AIDir_ChangeCond_Counter >= g_AIDir_ChangeCond_Rand)
  5586.     {
  5587.         g_AIDir_ChangeCond_Counter = 0;
  5588.         g_AIDir_ChangeCond_Rand = GetRandomInt(g_AIDir_ChangeCond_Min, g_AIDir_ChangeCond_Max);
  5589.         //PrintToServer("[AI_DIRECTOR] STATUS: %i | SetDifficulty CALLED", g_AIDir_TeamStatus);
  5590.         AI_Director_SetDifficulty();
  5591.     }
  5592.  
  5593.     if (g_AIDir_AmbushCond_Counter >= g_AIDir_AmbushCond_Rand)
  5594.     {
  5595.         if (tAmbushChance <= g_AIDir_AmbushCond_Chance)
  5596.         {
  5597.             g_AIDir_AmbushCond_Counter = 0;
  5598.             g_AIDir_AmbushCond_Rand = GetRandomInt(g_AIDir_AmbushCond_Min, g_AIDir_AmbushCond_Max);
  5599.             AI_Director_RandomEnemyReinforce();
  5600.         }
  5601.         else
  5602.         {
  5603.             //PrintToServer("[AI_DIRECTOR]: tAmbushChance: %d | g_AIDir_AmbushCond_Chance %d", tAmbushChance, g_AIDir_AmbushCond_Chance);
  5604.             //Reset
  5605.             g_AIDir_AmbushCond_Counter = 0;
  5606.             g_AIDir_AmbushCond_Rand = GetRandomInt(g_AIDir_AmbushCond_Min, g_AIDir_AmbushCond_Max);
  5607.         }
  5608.     }
  5609.  
  5610.     // Get the number of control points
  5611.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  5612.     // Get active push point
  5613.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  5614.    
  5615.     //Confirm percent finale
  5616.     if ((acp+1) == ncp)
  5617.     {
  5618.         if (g_finale_counter_spec_enabled == 1)
  5619.                 g_dynamicSpawnCounter_Perc = g_finale_counter_spec_percent;
  5620.     }
  5621.     return Plugin_Continue;
  5622. }
  5623.  
  5624.  
  5625. public Action Timer_AmmoResupply(Handle timer, any data) {
  5626.     if (g_iRoundStatus == 0) {
  5627.         return Plugin_Continue;
  5628.     }
  5629.     for (int client = 1; client <= MaxClients; client++) {
  5630.         if (!IsClientInGame(client) || IsFakeClient(client)) {
  5631.             continue;
  5632.         }
  5633.         int team = GetClientTeam(client);
  5634.         // Valid medic?
  5635.         if (IsPlayerAlive(client) && team == TEAM_1_SEC) {
  5636.             int ActiveWeapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  5637.             if (ActiveWeapon < 0) {
  5638.                 continue;
  5639.             }
  5640.  
  5641.             // Get weapon class name
  5642.             char sWeapon[32];
  5643.             GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  5644.             //if (GetClientButtons(client) & //INS_RELOAD  && ((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1)))
  5645.             if (((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1))) {
  5646.                 int validAmmoCache = -1;
  5647.                 validAmmoCache = FindValidProp_InDistance(client);
  5648.                 //PrintToServer("validAmmoCache: %d", validAmmoCache);
  5649.                 if (validAmmoCache != -1) {
  5650.                     g_resupplyCounter[client] -= 1;
  5651.                     if (g_ammoResupplyAmt[validAmmoCache] <= 0) {
  5652.                         int secTeamCount = GetTeamSecCount();
  5653.                         g_ammoResupplyAmt[validAmmoCache] = (secTeamCount / 6);
  5654.                         if (g_ammoResupplyAmt[validAmmoCache] <= 1) {
  5655.                             g_ammoResupplyAmt[validAmmoCache] = 1;
  5656.                         }
  5657.  
  5658.                     }
  5659.                     char sBuf[255];
  5660.                     // Hint to client
  5661.                     Format(sBuf, 255,"Resupplying ammo in %d seconds | Supply left: %d", g_resupplyCounter[client], g_ammoResupplyAmt[validAmmoCache]);
  5662.                     PrintHintText(client, "%s", sBuf);
  5663.                     if (g_resupplyCounter[client] <= 0) {
  5664.                         g_resupplyCounter[client] = sm_resupply_delay.IntValue;
  5665.                         //Spawn player again
  5666.                         AmmoResupply_Player(client, 0, 0, 0);
  5667.  
  5668.  
  5669.                         g_ammoResupplyAmt[validAmmoCache] -= 1;
  5670.                         if (g_ammoResupplyAmt[validAmmoCache] <= 0) {
  5671.                             if (validAmmoCache != -1) {
  5672.                                 AcceptEntityInput(validAmmoCache, "kill");
  5673.                             }
  5674.                         }
  5675.                         Format(sBuf, 255,"Rearmed! Ammo Supply left: %d", g_ammoResupplyAmt[validAmmoCache]);
  5676.  
  5677.                         PrintHintText(client, "%s", sBuf);
  5678.                         PrintToChat(client, "%s", sBuf);
  5679.  
  5680.                     }
  5681.                 }
  5682.             }
  5683.         }
  5684.     }
  5685.     return Plugin_Continue;
  5686. }
  5687.  
  5688. /*public void AmmoResupply_Player(int client, int primaryRemove, int secondaryRemove, int grenadesRemove) {
  5689.  
  5690.     float plyrOrigin[3];
  5691.     float tempOrigin[3];
  5692.     GetClientAbsOrigin(client, plyrOrigin);
  5693.     tempOrigin = plyrOrigin;
  5694.     tempOrigin[2] = -5000.0;
  5695.  
  5696.     //TeleportEntity(client, tempOrigin, NULL_VECTOR, NULL_VECTOR);
  5697.     //ForcePlayerSuicide(client);
  5698.     // Get dead body
  5699.     int clientRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
  5700.  
  5701.     //This timer safely removes client-side ragdoll
  5702.     if (clientRagdoll > 0 && IsValidEdict(clientRagdoll) && IsValidEntity(clientRagdoll)) {
  5703.         // Get dead body's entity
  5704.         int ref = EntIndexToEntRef(clientRagdoll);
  5705.         int entity = EntRefToEntIndex(ref);
  5706.         if (entity != INVALID_ENT_REFERENCE && IsValidEntity(entity)) {
  5707.             // Remove dead body's entity
  5708.             AcceptEntityInput(entity, "Kill");
  5709.             clientRagdoll = INVALID_ENT_REFERENCE;
  5710.         }
  5711.     }
  5712.  
  5713.     ForceRespawnPlayer(client, client);
  5714.     TeleportEntity(client, plyrOrigin, NULL_VECTOR, NULL_VECTOR);
  5715.     RemoveWeapons(client, primaryRemove, secondaryRemove, grenadesRemove);
  5716.     PrintHintText(client, "Ammo Resupplied");
  5717.     playerInRevivedState[client] = false;
  5718.     // //Give back life
  5719.     // new iDeaths = GetClientDeaths(client) - 1;
  5720.     // SetEntProp(client, Prop_Data, "m_iDeaths", iDeaths);
  5721. }*/
  5722.  
  5723. //Find Valid Prop
  5724. public void RemoveWeapons(int client, int primaryRemove, int secondaryRemove, int grenadesRemove)
  5725. {
  5726.  
  5727.     int primaryWeapon = GetPlayerWeaponSlot(client, 0);
  5728.     int secondaryWeapon = GetPlayerWeaponSlot(client, 1);
  5729.     int playerGrenades = GetPlayerWeaponSlot(client, 3);
  5730.  
  5731.     // Check and remove primaryWeapon
  5732.     // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 13
  5733.     if (primaryWeapon != -1 && IsValidEntity(primaryWeapon) && primaryRemove == 1)  
  5734.     {
  5735.         // Remove primaryWeapon
  5736.         char weapon[32];
  5737.         GetEntityClassname(primaryWeapon, weapon, sizeof(weapon));
  5738.         RemovePlayerItem(client, primaryWeapon);
  5739.         AcceptEntityInput(primaryWeapon, "kill");
  5740.     }
  5741.     // Check and remove secondaryWeapon
  5742.     // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 13
  5743.     if (secondaryWeapon != -1 && IsValidEntity(secondaryWeapon) && secondaryRemove == 1)  
  5744.     {
  5745.         // Remove primaryWeapon
  5746.         char weapon[32];
  5747.         GetEntityClassname(secondaryWeapon, weapon, sizeof(weapon));
  5748.         RemovePlayerItem(client, secondaryWeapon);
  5749.         AcceptEntityInput(secondaryWeapon, "kill");
  5750.     }
  5751.     // Check and remove grenades
  5752.     // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 13
  5753.     if (playerGrenades != -1 && IsValidEntity(playerGrenades) && grenadesRemove == 1)  
  5754.     {
  5755.         // since we only have 3 slots in current theate
  5756.         while (playerGrenades != -1 && IsValidEntity(playerGrenades))  
  5757.         {
  5758.             playerGrenades = GetPlayerWeaponSlot(client, 3);
  5759.             // We need to figure out what slots are defined#define Slot_HEgrenade 11, #define Slot_Flashbang 12, #define Slot_Smokegrenade 1
  5760.             if (playerGrenades != -1 && IsValidEntity(playerGrenades))  
  5761.             {
  5762.                 // Remove grenades
  5763.                 char weapon[32];
  5764.                 GetEntityClassname(playerGrenades, weapon, sizeof(weapon));
  5765.                 RemovePlayerItem(client, playerGrenades);
  5766.                 AcceptEntityInput(playerGrenades, "kill");
  5767.  
  5768.             }
  5769.         }
  5770.     }
  5771. }
  5772.  
  5773. public Action Timer_AmbientRadio(Handle timer, any data)
  5774. {
  5775.     if (g_iRoundStatus == 0) return Plugin_Continue;
  5776.     for (int client = 1; client <= MaxClients; client++)
  5777.     {
  5778.         if (!IsClientInGame(client) || IsFakeClient(client)) continue;
  5779.         int team = GetClientTeam(client);
  5780.        
  5781.         // Valid medic?
  5782.         if (IsPlayerAlive(client) && ((StrContains(g_client_last_classstring[client], "squadleader") > -1) || (StrContains(g_client_last_classstring[client], "teamleader") > -1)) && team == TEAM_1_SEC)
  5783.         {
  5784.             int fRandomChance = GetRandomInt(1, 100);
  5785.             if (fRandomChance < 50)
  5786.             {  
  5787.                 Handle hDatapack;
  5788.                 float fRandomFloat = GetRandomFloat(1.0, 30.0);
  5789.                 //CreateTimer(fRandomFloat, Timer_PlayAmbient);
  5790.                 CreateDataTimer(fRandomFloat, Timer_PlayAmbient, hDatapack);
  5791.                 WritePackCell(hDatapack, client);
  5792.             }
  5793.         }
  5794.     }
  5795.     return Plugin_Continue;
  5796.  
  5797. }
  5798. public Action Timer_PlayAmbient(Handle timer, DataPack hDatapack)
  5799. {
  5800.  
  5801.     hDatapack.Reset();
  5802.     int client = hDatapack.ReadCell();
  5803.  
  5804.     //PrintToServer("PlaySound");
  5805.     switch(GetRandomInt(1, 10))
  5806.     {
  5807.         case 1: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_01.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5808.         case 2: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_02.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5809.         case 3: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_03.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5810.         case 4: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_04.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5811.         case 5: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_01.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5812.         case 6: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_02.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5813.         case 7: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_03.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5814.         case 8: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_04.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5815.         case 9: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_05.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5816.         case 10: EmitSoundToAll("soundscape/emitters/oneshot/mil_radio_oneshot_06.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  5817.     }
  5818.     return Plugin_Continue;
  5819.  
  5820.  
  5821.  
  5822. // Check for nearest player
  5823. public Action Timer_NearestBody(Handle timer, any data)
  5824. {
  5825.     // Check round state
  5826.     if (g_iRoundStatus == 0) return Plugin_Continue;
  5827.    
  5828.     // Variables to store
  5829.     float fMedicPosition[3];
  5830.     float fMedicAngles[3];
  5831.     float fInjuredPosition[3];
  5832.     float fNearestDistance;
  5833.     float fTempDistance;
  5834.  
  5835.     // iNearest Injured client
  5836.     int iNearestInjured;
  5837.     char sDirection[64];
  5838.     char sDistance[64];
  5839.     char sHeight[6];
  5840.  
  5841.     // Client loop
  5842.     for (int medic = 1; medic <= MaxClients; medic++)
  5843.     {
  5844.         if (!IsClientInGame(medic) || IsFakeClient(medic))
  5845.             continue;
  5846.        
  5847.         // Valid medic?
  5848.         if (IsPlayerAlive(medic) && (StrContains(g_client_last_classstring[medic], "medic") > -1))
  5849.         {
  5850.             // Reset variables
  5851.             iNearestInjured = 0;
  5852.             fNearestDistance = 0.0;
  5853.            
  5854.             // Get medic position
  5855.             GetClientAbsOrigin(medic, fMedicPosition);
  5856.  
  5857.             //PrintToServer("MEDIC DETECTED ********************");
  5858.             // Search dead body
  5859.             for (int search = 1; search <= MaxClients; search++)
  5860.             {
  5861.                 if (!IsClientInGame(search) || IsFakeClient(search) || IsPlayerAlive(search)) continue;
  5862.                
  5863.                 // Check if valid
  5864.                 if (g_iHurtFatal[search] == 0 && search != medic && GetClientTeam(medic) == GetClientTeam(search))
  5865.                 {
  5866.                     // Get found client's ragdoll
  5867.                     int clientRagdoll = EntRefToEntIndex(g_iClientRagdolls[search]);
  5868.                     if (clientRagdoll > 0 && IsValidEdict(clientRagdoll) && IsValidEntity(clientRagdoll) && clientRagdoll != INVALID_ENT_REFERENCE)
  5869.                     {
  5870.                         // Get ragdoll's position
  5871.                         fInjuredPosition = g_fRagdollPosition[search];
  5872.                        
  5873.                         // Get distance from ragdoll
  5874.                         fTempDistance = GetVectorDistance(fMedicPosition, fInjuredPosition);
  5875.  
  5876.                         // Is he more fNearestDistance to the player as the player before?
  5877.                         if (fNearestDistance == 0.0)
  5878.                         {
  5879.                             fNearestDistance = fTempDistance;
  5880.                             iNearestInjured = search;
  5881.                         }
  5882.                         // Set new distance and new iNearestInjured player
  5883.                         else if (fTempDistance < fNearestDistance)
  5884.                         {
  5885.                             fNearestDistance = fTempDistance;
  5886.                             iNearestInjured = search;
  5887.                         }
  5888.                     }
  5889.                 }
  5890.             }
  5891.            
  5892.             // Found a dead body?
  5893.             if (iNearestInjured != 0)
  5894.             {
  5895.                 // Set iNearestInjured body
  5896.                 g_iNearestBody[medic] = iNearestInjured;
  5897.                
  5898.                 // Get medic angle
  5899.                 GetClientAbsAngles(medic, fMedicAngles);
  5900.                
  5901.                 // Get direction string (if it cause server lag, remove this)
  5902.                 sDirection = GetDirectionString(fMedicAngles, fMedicPosition, fInjuredPosition);
  5903.                
  5904.                 // Get distance string
  5905.                 sDistance = GetDistanceString(fNearestDistance);
  5906.                 // Get height string
  5907.                 sHeight = GetHeightString(fMedicPosition, fInjuredPosition);
  5908.                
  5909.                 // Print iNearestInjured dead body's distance and direction text
  5910.                 //PrintCenterText(medic, "Nearest dead: %N (%s)", iNearestInjured, sDistance);
  5911.                 PrintCenterText(medic, "Nearest dead: %N ( %s | %s | %s )", iNearestInjured, sDistance, sDirection, sHeight);
  5912.                 float beamPos[3];
  5913.                 beamPos = fInjuredPosition;
  5914.                 beamPos[2] += 0.3;
  5915.                 if (fTempDistance >= 140)
  5916.                 {
  5917.                     //Attack markers option
  5918.                     //Effect_SetMarkerAtPos(medic,beamPos,1.0,{255, 0, 0, 255});
  5919.  
  5920.                     //Beam dead when farther
  5921.                     TE_SetupBeamRingPoint(beamPos, 1.0, Revive_Indicator_Radius, g_iBeaconBeam, g_iBeaconHalo, 0, 15, 5.0, 3.0, 5.0, {255, 0, 0, 255}, 1, (FBEAM_FADEIN, FBEAM_FADEOUT));
  5922.                     //void TE_SetupBeamRingPoint(const float center[3], float Start_Radius, float End_Radius, int ModelIndex, int HaloIndex, int StartFrame, int FrameRate, float Life, float Width, float Amplitude, const int Color[4], int Speed, int Flags)
  5923.                     TE_SendToClient(medic);
  5924.                 }
  5925.             }
  5926.             else
  5927.             {
  5928.                 // Reset iNearestInjured body
  5929.                 g_iNearestBody[medic] = -1;
  5930.             }
  5931.         }
  5932.         else if (IsPlayerAlive(medic) && !(StrContains(g_client_last_classstring[medic], "medic") > -1))
  5933.         {
  5934.             // Reset variables
  5935.             iNearestInjured = 0;
  5936.             fNearestDistance = 0.0;
  5937.            
  5938.             // Get medic position
  5939.             GetClientAbsOrigin(medic, fMedicPosition);
  5940.  
  5941.             //PrintToServer("MEDIC DETECTED ********************");
  5942.             // Search dead body
  5943.             for (int search = 1; search <= MaxClients; search++)
  5944.             {
  5945.                 if (!IsClientInGame(search) || IsFakeClient(search) || IsPlayerAlive(search))
  5946.                     continue;
  5947.                
  5948.                 // Check if valid
  5949.                 if (g_iHurtFatal[search] == 0 && search != medic && GetClientTeam(medic) == GetClientTeam(search))
  5950.                 {
  5951.                     // Get found client's ragdoll
  5952.                     int clientRagdoll = EntRefToEntIndex(g_iClientRagdolls[search]);
  5953.                     if (clientRagdoll > 0 && IsValidEdict(clientRagdoll) && IsValidEntity(clientRagdoll) && clientRagdoll != INVALID_ENT_REFERENCE)
  5954.                     {
  5955.                         // Get ragdoll's position
  5956.                         fInjuredPosition = g_fRagdollPosition[search];
  5957.                        
  5958.                         // Get distance from ragdoll
  5959.                         fTempDistance = GetVectorDistance(fMedicPosition, fInjuredPosition);
  5960.  
  5961.                         // Is he more fNearestDistance to the player as the player before?
  5962.                         if (fNearestDistance == 0.0)
  5963.                         {
  5964.                             fNearestDistance = fTempDistance;
  5965.                             iNearestInjured = search;
  5966.                         }
  5967.                         // Set new distance and new iNearestInjured player
  5968.                         else if (fTempDistance < fNearestDistance)
  5969.                         {
  5970.                             fNearestDistance = fTempDistance;
  5971.                             iNearestInjured = search;
  5972.                         }
  5973.                     }
  5974.                 }
  5975.             }
  5976.            
  5977.             // Found a dead body?
  5978.             if (iNearestInjured != 0)
  5979.             {
  5980.                 // Set iNearestInjured body
  5981.                 g_iNearestBody[medic] = iNearestInjured;
  5982.                
  5983.             }
  5984.             else
  5985.             {
  5986.                 // Reset iNearestInjured body
  5987.                 g_iNearestBody[medic] = -1;
  5988.             }
  5989.         }
  5990.     }
  5991.    
  5992.     return Plugin_Continue;
  5993. }
  5994.  
  5995. public bool Check_NearbyPlayers(int enemyBot)
  5996. {
  5997.     for (int client = 1; client <= MaxClients; client++)
  5998.     {
  5999.         if (IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
  6000.         {
  6001.             if (IsPlayerAlive(client))
  6002.             {
  6003.                 float botOrigin[3];
  6004.                 float clientOrigin[3];
  6005.                 float fDistance;
  6006.                
  6007.                 GetClientAbsOrigin(enemyBot,botOrigin);
  6008.                 GetClientAbsOrigin(client,clientOrigin);
  6009.                
  6010.                 //determine distance from the two
  6011.                 fDistance = GetVectorDistance(botOrigin,clientOrigin);
  6012.                
  6013.                 if (fDistance <= 600) return true;
  6014.             }
  6015.         }
  6016.     }
  6017.     return false;
  6018. }
  6019.  
  6020. /**
  6021.  * Get direction string for nearest dead body
  6022.  *
  6023.  * @param fClientAngles[3]      Client angle
  6024.  * @param fClientPosition[3]    Client position
  6025.  * @param fTargetPosition[3]    Target position
  6026.  * @Return                      direction string.
  6027.  */
  6028. char GetDirectionString(float fClientAngles[3], float fClientPosition[3], float fTargetPosition[3])
  6029. {
  6030.     float fTempAngles[3], fTempPoints[3];
  6031.     char sDirection[64];
  6032.  
  6033.     // Angles from origin
  6034.     MakeVectorFromPoints(fClientPosition, fTargetPosition, fTempPoints);
  6035.     GetVectorAngles(fTempPoints, fTempAngles);
  6036.    
  6037.     // Difference
  6038.     float fDiff = fClientAngles[1] - fTempAngles[1];
  6039.    
  6040.     // Correct it
  6041.     if (fDiff < -180)
  6042.         fDiff = 360 + fDiff;
  6043.  
  6044.     if (fDiff > 180)
  6045.         fDiff = 360 - fDiff;
  6046.    
  6047.     // Now get the direction
  6048.     // Up
  6049.     if (fDiff >= -22.5 && fDiff < 22.5)
  6050.         Format(sDirection, sizeof(sDirection), "FWD");//"\xe2\x86\x91");
  6051.     // right up
  6052.     else if (fDiff >= 22.5 && fDiff < 67.5)
  6053.         Format(sDirection, sizeof(sDirection), "FWD-RIGHT");//"\xe2\x86\x97");
  6054.     // right
  6055.     else if (fDiff >= 67.5 && fDiff < 112.5)
  6056.         Format(sDirection, sizeof(sDirection), "RIGHT");//"\xe2\x86\x92");
  6057.     // right down
  6058.     else if (fDiff >= 112.5 && fDiff < 157.5)
  6059.         Format(sDirection, sizeof(sDirection), "BACK-RIGHT");//"\xe2\x86\x98");
  6060.     // down
  6061.     else if (fDiff >= 157.5 || fDiff < -157.5)
  6062.         Format(sDirection, sizeof(sDirection), "BACK");//"\xe2\x86\x93");
  6063.     // down left
  6064.     else if (fDiff >= -157.5 && fDiff < -112.5)
  6065.         Format(sDirection, sizeof(sDirection), "BACK-LEFT");//"\xe2\x86\x99");
  6066.     // left
  6067.     else if (fDiff >= -112.5 && fDiff < -67.5)
  6068.         Format(sDirection, sizeof(sDirection), "LEFT");//"\xe2\x86\x90");
  6069.     // left up
  6070.     else if (fDiff >= -67.5 && fDiff < -22.5)
  6071.         Format(sDirection, sizeof(sDirection), "FWD-LEFT");//"\xe2\x86\x96");
  6072.    
  6073.     return sDirection;
  6074. }
  6075.  
  6076. // Return distance string
  6077. char GetDistanceString(float fDistance)
  6078. {
  6079.     // Distance to meters
  6080.     float fTempDistance = fDistance * 0.01905;
  6081.     char sResult[64];
  6082.  
  6083.     // Distance to feet?
  6084.     if (g_iUnitMetric == 1)
  6085.     {
  6086.         fTempDistance = fTempDistance * 3.2808399;
  6087.  
  6088.         // Feet
  6089.         Format(sResult, sizeof(sResult), "%.0f feet", fTempDistance);
  6090.     }
  6091.     else
  6092.     {
  6093.         // Meter
  6094.         Format(sResult, sizeof(sResult), "%.0f meter", fTempDistance);
  6095.     }
  6096.    
  6097.     return sResult;
  6098. }
  6099.  
  6100.  
  6101.  
  6102. public hideBot(any client)
  6103. {
  6104.     SetEntProp(client, Prop_Data, "m_takedamage", 0, 1);
  6105.     SetEntData(client, g_iCollOff, 2, 4, true);
  6106.     set_rendering(client, g_Effect, 0, 0, 0, g_Render, 0);
  6107. }
  6108.  
  6109.  
  6110.  
  6111. // Trace client's view entity
  6112. int TraceClientViewEntity(int client) {
  6113.     float m_vecOrigin[3];
  6114.     float m_angRotation[3];
  6115.  
  6116.     GetClientEyePosition(client, m_vecOrigin);
  6117.     GetClientEyeAngles(client, m_angRotation);
  6118.  
  6119.     Handle tr = TR_TraceRayFilterEx(m_vecOrigin, m_angRotation, MASK_VISIBLE, RayType_Infinite, TRDontHitSelf, client);
  6120.     int pEntity = -1;
  6121.  
  6122.     if (TR_DidHit(tr)) {
  6123.         pEntity = TR_GetEntityIndex(tr);
  6124.         delete tr;
  6125.         return pEntity;
  6126.     }
  6127.  
  6128.     delete tr;
  6129.  
  6130.     return -1;
  6131. }
  6132.  
  6133. // Check is hit self
  6134. public bool TRDontHitSelf(int entity, int mask, any data) // Don't ray trace ourselves -_-"
  6135. {
  6136.     return (1 <= entity <= MaxClients) && (entity != data);
  6137. }
  6138.  
  6139. /*
  6140. ########################LUA HEALING INTEGRATION######################
  6141. #   This portion of the script adds in health packs from Lua        #
  6142. ##############################START##################################
  6143. #####################################################################*/
  6144.  
  6145. /*
  6146. public Action Event_GrenadeThrown(Event event, const char[] name, bool dontBroadcast)
  6147. {
  6148.     int client = GetClientOfUserId(event.GetInt("userid"));
  6149.     int nade_id = event.GetInt("entityid");
  6150.     if (nade_id > -1 && client > -1)
  6151.     {
  6152.         if (IsPlayerAlive(client))
  6153.         {
  6154.             char grenade_name[32];
  6155.             GetEntityClassname(nade_id, grenade_name, sizeof(grenade_name));
  6156.             if (StrEqual(grenade_name, "healthkit"))
  6157.             {
  6158.                 switch(GetRandomInt(1, 18))
  6159.                 {
  6160.                     case 1: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/need_backup1.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6161.                     case 2: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/need_backup2.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6162.                     case 3: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/need_backup3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6163.                     case 4: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/holdposition2.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6164.                     case 5: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/holdposition3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6165.                     case 6: EmitSoundToAll("player/voice/radial/security/leader/unsuppressed/moving2.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6166.                     case 7: EmitSoundToAll("player/voice/radial/security/leader/suppressed/backup3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6167.                     case 8: EmitSoundToAll("player/voice/radial/security/leader/suppressed/holdposition1.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6168.                     case 9: EmitSoundToAll("player/voice/radial/security/leader/suppressed/holdposition2.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6169.                     case 10: EmitSoundToAll("player/voice/radial/security/leader/suppressed/holdposition3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6170.                     case 11: EmitSoundToAll("player/voice/radial/security/leader/suppressed/holdposition4.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6171.                     case 12: EmitSoundToAll("player/voice/radial/security/leader/suppressed/moving3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6172.                     case 13: EmitSoundToAll("player/voice/radial/security/leader/suppressed/ontheway1.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6173.                     case 14: EmitSoundToAll("player/voice/security/command/leader/located4.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6174.                     case 15: EmitSoundToAll("player/voice/security/command/leader/setwaypoint1.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6175.                     case 16: EmitSoundToAll("player/voice/security/command/leader/setwaypoint2.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6176.                     case 17: EmitSoundToAll("player/voice/security/command/leader/setwaypoint3.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6177.                     case 18: EmitSoundToAll("player/voice/security/command/leader/setwaypoint4.ogg", client, SNDCHAN_VOICE, _, _, 1.0);
  6178.                 }
  6179.             }
  6180.         }
  6181.     }
  6182. }*/
  6183.  
  6184. //Healthkit Start
  6185.  
  6186. public void OnEntityDestroyed(int entity)
  6187. {
  6188.     if (entity > MaxClients)
  6189.     {
  6190.         char classname[255];
  6191.         GetEntityClassname(entity, classname, 255);
  6192.         if (StrEqual(classname, "healthkit")) {
  6193.             //StopSound(entity, SNDCHAN_STATIC, "Lua_sounds/healthkit_healing.wav");
  6194.         }
  6195.         if (!(StrContains(classname, "wcache_crate_01") > -1)) {
  6196.             g_ammoResupplyAmt[entity] = 0;
  6197.         }
  6198.     }
  6199. }
  6200.  
  6201. public OnEntityCreated(entity, const char[] classname)
  6202. {
  6203.  
  6204.     if (StrEqual(classname, "healthkit"))
  6205.     {
  6206.         Handle hDatapack;
  6207.         g_healthPack_Amount[entity] = g_medpack_health_amt;
  6208.         CreateDataTimer(Healthkit_Timer_Tickrate, Healthkit, hDatapack, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  6209.         WritePackCell(hDatapack, entity);
  6210.         WritePackFloat(hDatapack, GetGameTime()+Healthkit_Timer_Timeout);
  6211.         g_fLastHeight[entity] = -9999.0;
  6212.         g_iTimeCheckHeight[entity] = -9999;
  6213.         SDKHook(entity, SDKHook_VPhysicsUpdate, HealthkitGroundCheck);
  6214.         CreateTimer(0.1, HealthkitGroundCheckTimer, entity, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  6215.     }
  6216.     /*else if (StrEqual(classname, "grenade_m67") || StrEqual(classname, "grenade_f1"))
  6217.     {
  6218.         CreateTimer(0.5, GrenadeScreamCheckTimer, entity, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  6219.     }
  6220.     else if (StrEqual(classname, "grenade_molotov") || StrEqual(classname, "grenade_anm14"))
  6221.         CreateTimer(0.2, FireScreamCheckTimer, entity, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);*/
  6222. }
  6223.  
  6224. /*Action FireScreamCheckTimer(Handle timer, any entity)
  6225. {
  6226.     float fGrenOrigin[3];
  6227.     float fPlayerOrigin[3];
  6228.     float fPlayerEyeOrigin[3];
  6229.     int owner;
  6230.     if (IsValidEntity(entity) && entity > 0)
  6231.     {
  6232.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fGrenOrigin);
  6233.         owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
  6234.     }
  6235.     else
  6236.         CloseHandle(timer);
  6237.     for (int client = 1;client <= MaxClients;client++)
  6238.     {
  6239.         if (client <= 0 || !IsClientInGame(client) || !IsClientConnected(client)) continue;
  6240.         if (owner <= 0 || !IsClientInGame(owner) || IsFakeClient(client) || !IsClientConnected(owner)) continue;
  6241.         if (IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
  6242.         {
  6243.             GetClientEyePosition(client, fPlayerEyeOrigin);
  6244.             GetClientAbsOrigin(client,fPlayerOrigin);
  6245.             //Handle trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_SOLID_BRUSHONLY, RayType_EndPoint, Base_TraceFilter);
  6246.             if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 300 &&  g_plyrFireScreamCoolDown[client] <= 0)
  6247.             {
  6248.                 //PrintToServer("SCREAM FIRE");
  6249.                 PlayerFireScreamRand(client);
  6250.                 int fRandomInt = GetRandomInt(20, 30);
  6251.                 g_plyrFireScreamCoolDown[client] = fRandomInt;
  6252.                 //CloseHandle(trace);  
  6253.             }
  6254.         }
  6255.     }
  6256.     if (!IsValidEntity(entity) || !(entity > 0)) CloseHandle(timer);
  6257. }*/
  6258.  
  6259. /*Action GrenadeScreamCheckTimer(Handle timer, any entity)
  6260. {
  6261.     float fGrenOrigin[3];
  6262.     float fPlayerOrigin[3];
  6263.     float fPlayerEyeOrigin[3];
  6264.     int owner;
  6265.     if (IsValidEntity(entity) && entity > 0)
  6266.     {
  6267.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fGrenOrigin);
  6268.         owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
  6269.     }
  6270.     else
  6271.         KillTimer(timer);
  6272.     for (int client = 1;client <= MaxClients;client++)
  6273.     {
  6274.         if (client <= 0 || IsFakeClient(client) || !IsClientInGame(client)) continue;
  6275.         if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && owner > 0 && GetClientTeam(owner) == 3)
  6276.         {
  6277.             GetClientEyePosition(client, fPlayerEyeOrigin);
  6278.             GetClientAbsOrigin(client,fPlayerOrigin);
  6279.  
  6280.             if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 240 &&  g_plyrGrenScreamCoolDown[client] <= 0)
  6281.             {
  6282.                 PlayerGrenadeScreamRand(client);
  6283.                 int fRandomInt = GetRandomInt(6, 12);
  6284.                 g_plyrGrenScreamCoolDown[client] = fRandomInt;
  6285.             }
  6286.         }
  6287.     }
  6288.     if (!IsValidEntity(entity) || !(entity > 0))
  6289.         KillTimer(timer);
  6290. }*/
  6291.  
  6292. public Action HealthkitGroundCheck(int entity, int activator, int caller, UseType type, float value)
  6293. {
  6294.     float fOrigin[3];
  6295.     GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fOrigin);
  6296.     int iRoundHeight = RoundFloat(fOrigin[2]);
  6297.     if (iRoundHeight != g_iTimeCheckHeight[entity])
  6298.     {
  6299.         g_iTimeCheckHeight[entity] = iRoundHeight;
  6300.         g_fTimeCheck[entity] = GetGameTime();
  6301.     }
  6302. }
  6303.  
  6304. Action HealthkitGroundCheckTimer(Handle timer, any entity)
  6305. {
  6306.     if (entity > MaxClients && IsValidEntity(entity))
  6307.     {
  6308.         float fGameTime = GetGameTime();
  6309.         if (fGameTime-g_fTimeCheck[entity] >= 1.0)
  6310.         {
  6311.             float fOrigin[3];
  6312.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fOrigin);
  6313.             int iRoundHeight = RoundFloat(fOrigin[2]);
  6314.             if (iRoundHeight == g_iTimeCheckHeight[entity])
  6315.             {
  6316.                 g_fTimeCheck[entity] = GetGameTime();
  6317.                 SDKUnhook(entity, SDKHook_VPhysicsUpdate, HealthkitGroundCheck);
  6318.                 SDKHook(entity, SDKHook_VPhysicsUpdate, OnEntityPhysicsUpdate);
  6319.                 KillTimer(timer);
  6320.             }
  6321.         }
  6322.     }
  6323.     else CloseHandle(timer);
  6324. }
  6325.  
  6326. public Action OnEntityPhysicsUpdate(int entity, int activator, int caller, UseType type, float value)
  6327. {
  6328.     TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, view_as<float> ({0.0, 0.0, 0.0}));
  6329. }
  6330.  
  6331. public Action Healthkit(Handle timer, Handle hDatapack)
  6332. {
  6333.     ResetPack(hDatapack);
  6334.     int entity = ReadPackCell(hDatapack);
  6335.     float fEndTime = ReadPackFloat(hDatapack);
  6336.     float fGameTime = GetGameTime();
  6337.     if (entity > 0 && IsValidEntity(entity) && fGameTime <= fEndTime)
  6338.     {
  6339.         float fOrigin[3];
  6340.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fOrigin);
  6341.         if (g_fLastHeight[entity] == -9999.0)
  6342.         {
  6343.             g_fLastHeight[entity] = 0.0;
  6344.             EmitSoundToAll("Lua_sounds/healthkit_healing.wav", entity, SNDCHAN_STATIC, _, _, 0.7);
  6345.         }
  6346.         //fOrigin[2] += 16.0;
  6347.         fOrigin[2] += 1.0;
  6348.         //TE_SetupBeamRingPoint(beamPos, 1.0, Revive_Indicator_Radius, g_iBeaconBeam, g_iBeaconHalo, 0, 15, 5.0, 3.0, 5.0, {255, 0, 0, 255}, 1, (FBEAM_FADEIN, FBEAM_FADEOUT));
  6349.         TE_SetupBeamRingPoint(fOrigin, 15.0, Healthkit_Radius*0.55, g_iBeaconBeam, g_iBeaconHalo, 0, 5, 1.0, 1.0, 2.0, {0, 204, 100, 255},1,0);
  6350.         // // //TE_SetupBeamRingPoint(fOrigin, 5.0, Healthkit_Radius*1.95, g_iBeaconBeam, g_iBeaconHalo, 0, 30, 5.0, 3.0, 5.0, {0, 255, 0, 255}, 1, (FBEAM_FADEOUT));
  6351.         //TE_SetupBeamRingPoint(fOrigin, 10.0, Healthkit_Radius*1.95, g_iBeaconBeam, g_iBeaconHalo, 0, 30, 0.6, 3.0, 0.0, {0, 204, 102, 255}, 3, 0);
  6352.         TE_SendToAll();
  6353.         fOrigin[2] -= 16.0;
  6354.         if (fOrigin[2] != g_fLastHeight[entity])
  6355.         {
  6356.             g_fLastHeight[entity] = fOrigin[2];
  6357.         }
  6358.         else
  6359.         {
  6360.             float fAng[3];
  6361.             GetEntPropVector(entity, Prop_Send, "m_angRotation", fAng);
  6362.             if (fAng[1] > 89.0 || fAng[1] < -89.0)
  6363.                 fAng[1] = 90.0;
  6364.             if (fAng[2] > 89.0 || fAng[2] < -89.0)
  6365.             {
  6366.                 fAng[2] = 0.0;
  6367.                 fOrigin[2] -= 6.0;
  6368.                 TeleportEntity(entity, fOrigin, fAng, view_as<float>({0.0, 0.0, 0.0}));
  6369.                 fOrigin[2] += 6.0;
  6370.                 EmitSoundToAll("ui/sfx/cl_click.wav", entity, SNDCHAN_STATIC, _, _, 1.0);
  6371.             }
  6372.         }
  6373.        
  6374.         for (int iPlayer = 1;iPlayer <= MaxClients;iPlayer++)
  6375.         {
  6376.             if (IsClientInGame(iPlayer) && IsPlayerAlive(iPlayer) && GetClientTeam(iPlayer) == 2)
  6377.             {
  6378.                 float fPlayerOrigin[3];
  6379.                 GetClientEyePosition(iPlayer, fPlayerOrigin);
  6380.                 if (GetVectorDistance(fPlayerOrigin, fOrigin) <= Healthkit_Radius)
  6381.                 {
  6382.                     Handle hData = CreateDataPack();
  6383.                     WritePackCell(hData, entity);
  6384.                     WritePackCell(hData, iPlayer);
  6385.                     fOrigin[2] += 32.0;
  6386.                     Handle trace = TR_TraceRayFilterEx(fPlayerOrigin, fOrigin, MASK_SOLID, RayType_EndPoint, Filter_ClientSelf, hData);
  6387.                     CloseHandle(hData);
  6388.                     if (!TR_DidHit(trace))
  6389.                     {
  6390.                         int iMaxHealth = GetEntProp(iPlayer, Prop_Data, "m_iMaxHealth");
  6391.                         int iHealth = GetEntProp(iPlayer, Prop_Data, "m_iHealth");
  6392.                         if (iMaxHealth > iHealth)
  6393.                         {
  6394.                             iHealth += GetRandomInt(Healthkit_Healing_Per_Tick_Min, Healthkit_Healing_Per_Tick_Max);
  6395.                             if (iHealth >= iMaxHealth)
  6396.                             {
  6397.                                 EmitSoundToAll("Lua_sounds/healthkit_complete.wav", iPlayer, SNDCHAN_STATIC, _, _, 1.0);
  6398.                                 iHealth = iMaxHealth;
  6399.                                 //PrintToChat(iPlayer, "\x05竊긌ua \x01@ \x03You are completely healed!");
  6400.                                 PrintCenterText(iPlayer, "Healed !\n\n \n %d %%\n \n \n \n \n \n \n \n", iMaxHealth);
  6401.                             }
  6402.                             else PrintCenterText(iPlayer, "Healing...\n\n \n   %d %%\n \n \n \n \n \n \n \n", iHealth);
  6403.                             SetEntProp(iPlayer, Prop_Data, "m_iHealth", iHealth);
  6404.                         }
  6405.                         else PrintCenterText(iPlayer, "Healed !\n\n \n %d %%\n \n \n \n \n \n \n \n", iMaxHealth);
  6406.                     }
  6407.                     CloseHandle(trace);
  6408.                 }
  6409.             }
  6410.         }
  6411.     }
  6412.     else
  6413.     {
  6414.         RemoveHealthkit(entity);
  6415.         KillTimer(timer);
  6416.     }
  6417. }
  6418.  
  6419. public bool Filter_ClientSelf(int entity, int contentsMask, any data)
  6420. {
  6421.     DataPack dp = data;
  6422.     dp.Reset();
  6423.     int client = dp.ReadCell();
  6424.     int player = dp.ReadCell();
  6425.     delete dp;
  6426.     return (entity != client && entity != player);
  6427. }
  6428.  
  6429. public RemoveHealthkit(entity)
  6430. {
  6431.     if (entity > MaxClients && IsValidEntity(entity))
  6432.     {
  6433.         AcceptEntityInput(entity, "Kill");
  6434.     }
  6435. }
  6436.  
  6437. bool Check_NearbyMedics(client)
  6438. {
  6439.     for (int friendlyMedic = 1; friendlyMedic <= MaxClients; friendlyMedic++)
  6440.     {
  6441.         if (IsClientConnected(friendlyMedic) && IsClientInGame(friendlyMedic) && !IsFakeClient(friendlyMedic))
  6442.         {
  6443.             if (IsPlayerAlive(friendlyMedic) && (StrContains(g_client_last_classstring[friendlyMedic], "medic") > -1) && client != friendlyMedic)
  6444.             {
  6445.             //PrintToServer("Medic 2");
  6446.                 //Get position of bot and prop
  6447.                 float plyrOrigin[3];
  6448.                 float medicOrigin[3];
  6449.                 float fDistance;
  6450.        
  6451.                 GetClientAbsOrigin(client,plyrOrigin);
  6452.                 GetClientAbsOrigin(friendlyMedic,medicOrigin);
  6453.                
  6454.                 //determine distance from the two
  6455.                 fDistance = GetVectorDistance(medicOrigin,plyrOrigin);
  6456.                
  6457.                 int ActiveWeapon = GetEntPropEnt(friendlyMedic, Prop_Data, "m_hActiveWeapon");
  6458.                 if (ActiveWeapon < 0)
  6459.                     continue;
  6460.  
  6461.                 // Get weapon class name
  6462.                 char sWeapon[32];
  6463.                 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  6464.  
  6465.             //PrintToServer("Medic 3");
  6466.                 bool bCanHealPaddle = false;
  6467.                 if ((StrContains(sWeapon, "weapon_defib") > -1) || (StrContains(sWeapon, "weapon_knife") > -1) || (StrContains(sWeapon, "weapon_kabar") > -1) || (StrContains(sWeapon, "weapon_healthkit") > -1))
  6468.                 {
  6469.             //PrintToServer("Medic 4");
  6470.                     bCanHealPaddle = true;
  6471.                 }
  6472.                 if (fDistance <= Healthkit_Radius && bCanHealPaddle)
  6473.                 {
  6474.             //PrintToServer("Medic 5");
  6475.                     return true;
  6476.                 }
  6477.             }
  6478.         }
  6479.     }
  6480.     return false;
  6481. }
  6482.  
  6483. // Healthkit Finished
  6484.  
  6485. /*public Action Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
  6486. {
  6487.         int client = GetClientOfUserId(event.GetInt("userid"));
  6488.  
  6489.         if (client > 0) // Check the client is not console/world?
  6490.             if (IsValidClient(client))
  6491.             {
  6492.                 int m_iTeam = GetClientTeam(client);
  6493.                 if (!IsFakeClient(client) && m_iTeam == TEAM_SPEC)
  6494.                 {
  6495.                     //remove network ragdoll associated with player
  6496.                     int playerRag = EntRefToEntIndex(g_iClientRagdolls[client]);
  6497.                     if(playerRag > 0 && IsValidEdict(playerRag) && IsValidEntity(playerRag))
  6498.                         RemoveRagdoll(client);
  6499.                 }
  6500.             }
  6501.         return Plugin_Continue;
  6502. }*/
  6503.  
  6504.  
  6505. //############# AI DIRECTOR In-Script Functions START #######################
  6506.  
  6507.  
  6508. void AI_Director_ResetReinforceTimers()
  6509. {
  6510.         //Set Reinforce Time
  6511.         g_iReinforceTime_AD_Temp = (g_AIDir_ReinforceTimer_Orig);
  6512.         g_iReinforceTimeSubsequent_AD_Temp = (g_AIDir_ReinforceTimer_SubOrig);
  6513. }
  6514.  
  6515. void AI_Director_SetDifficulty()
  6516. {
  6517.     AI_Director_ResetReinforceTimers();
  6518.  
  6519.         //AI Director Local Scaling Vars
  6520.     //AID_ReinfAdj_low = 10, AID_ReinfAdj_med = 20, AID_ReinfAdj_high = 30, AID_ReinfAdj_pScale = 0,
  6521.     int AID_ReinfAdj_med = 20;
  6522.     int AID_ReinfAdj_high = 30;
  6523.     int AID_ReinfAdj_pScale = 0;
  6524.     float AID_SpecDelayAdj_low = 10.0;
  6525.     float AID_SpecDelayAdj_med = 20.0;
  6526.     float AID_SpecDelayAdj_high = 30.0;
  6527.     float AID_SpecDelayAdj_pScale_Pro = 0.0;
  6528.     float AID_SpecDelayAdj_pScale_Con = 0.0;
  6529.     int AID_AmbChance_vlow = 10;
  6530.     int AID_AmbChance_low = 15;
  6531.     int AID_AmbChance_med = 20;
  6532.     int AID_AmbChance_high = 25;
  6533.     int AID_AmbChance_pScale = 0;
  6534.     int AID_SetDiffChance_pScale = 0;
  6535.  
  6536.     //Scale based on team count
  6537.     int tTeamSecCount = GetTeamSecCount();
  6538.     if (tTeamSecCount <= 6) {
  6539.         AID_ReinfAdj_pScale = 8;
  6540.         AID_SpecDelayAdj_pScale_Pro = 30.0;
  6541.         AID_SpecDelayAdj_pScale_Con = 10.0;
  6542.     }
  6543.     else if (tTeamSecCount >= 7 && tTeamSecCount <= 12) {
  6544.         AID_ReinfAdj_pScale = 4;
  6545.         AID_SpecDelayAdj_pScale_Pro = 20.0;
  6546.         AID_SpecDelayAdj_pScale_Con = 20.0;
  6547.         AID_AmbChance_pScale = 5;
  6548.         AID_SetDiffChance_pScale = 5;
  6549.     }
  6550.     else if (tTeamSecCount >= 13) {
  6551.         AID_ReinfAdj_pScale = 8;
  6552.         AID_SpecDelayAdj_pScale_Pro = 10.0;
  6553.         AID_SpecDelayAdj_pScale_Con = 30.0;
  6554.         AID_AmbChance_pScale = 10;
  6555.         AID_SetDiffChance_pScale = 10;
  6556.     }
  6557.  
  6558.     // Get the number of control points
  6559.     int ncp = Ins_ObjectiveResource_GetProp("m_iNumControlPoints");
  6560.  
  6561.     // Get active push point
  6562.     int acp = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
  6563.  
  6564.     int tAmbScaleMult = 2;
  6565.     if (ncp <= 5)
  6566.     {
  6567.         tAmbScaleMult = 3;
  6568.         AID_SetDiffChance_pScale += 5;
  6569.     }
  6570.     //Add More to Ambush chance based on what point we are at.
  6571.     AID_AmbChance_pScale += (acp * tAmbScaleMult);
  6572.     AID_SetDiffChance_pScale += (acp * tAmbScaleMult);
  6573.  
  6574.     float cvarSpecDelay = sm_respawn_delay_team_ins_special.FloatValue;
  6575.     int fRandomInt = GetRandomInt(0, 100);
  6576.  
  6577.  
  6578.     //Set Difficulty Based On g_AIDir_TeamStatus and adjust per player scale g_SernixMaxPlayerCount
  6579.     if (fRandomInt <= (g_AIDir_DiffChanceBase + AID_SetDiffChance_pScale))
  6580.     {
  6581.         AI_Director_ResetReinforceTimers();
  6582.         //Set Reinforce Time
  6583.         g_iReinforceTime_AD_Temp = ((g_AIDir_ReinforceTimer_Orig - AID_ReinfAdj_high) - AID_ReinfAdj_pScale);
  6584.         g_iReinforceTimeSubsequent_AD_Temp = ((g_AIDir_ReinforceTimer_SubOrig - AID_ReinfAdj_high) - AID_ReinfAdj_pScale);
  6585.  
  6586.         //Mod specialized bot spawn interval
  6587.         g_fCvar_respawn_delay_team_ins_spec = ((cvarSpecDelay - AID_SpecDelayAdj_high) - AID_SpecDelayAdj_pScale_Con);
  6588.         if (g_fCvar_respawn_delay_team_ins_spec <= 0)
  6589.             g_fCvar_respawn_delay_team_ins_spec = 1.0;
  6590.  
  6591.         //DEBUG: Track Current Difficulty setting
  6592.         //g_AIDir_CurrDiff = 5;
  6593.  
  6594.         //Set Ambush Chance
  6595.         g_AIDir_AmbushCond_Chance = AID_AmbChance_high + AID_AmbChance_pScale;
  6596.     }
  6597.     // < 25% DOING BAD >> MAKE EASIER //Scale variables should be lower with higher player counts
  6598.     else if (g_AIDir_TeamStatus < (g_AIDir_TeamStatus_max / 4))
  6599.     {
  6600.         //Set Reinforce Time
  6601.         g_iReinforceTime_AD_Temp = ((g_AIDir_ReinforceTimer_Orig + AID_ReinfAdj_high) + AID_ReinfAdj_pScale);
  6602.         g_iReinforceTimeSubsequent_AD_Temp = ((g_AIDir_ReinforceTimer_SubOrig + AID_ReinfAdj_high) + AID_ReinfAdj_pScale);
  6603.  
  6604.         //Mod specialized bot spawn interval
  6605.         g_fCvar_respawn_delay_team_ins_spec = ((cvarSpecDelay + AID_SpecDelayAdj_high) + AID_SpecDelayAdj_pScale_Pro);
  6606.  
  6607.         //DEBUG: Track Current Difficulty setting
  6608.         //g_AIDir_CurrDiff = 1;
  6609.  
  6610.         //Set Ambush Chance
  6611.         g_AIDir_AmbushCond_Chance = AID_AmbChance_vlow + AID_AmbChance_pScale;
  6612.     }
  6613.     // >= 25% and < 50% NORMAL >> No Adjustments
  6614.     else if (g_AIDir_TeamStatus >= (g_AIDir_TeamStatus_max / 4) && g_AIDir_TeamStatus < (g_AIDir_TeamStatus_max / 2))
  6615.     {
  6616.         AI_Director_ResetReinforceTimers();
  6617.  
  6618.         // >= 25% and < 33% Ease slightly if <= half the team alive which is 9 right now.
  6619.         if (g_AIDir_TeamStatus >= (g_AIDir_TeamStatus_max / 4) && g_AIDir_TeamStatus < (g_AIDir_TeamStatus_max / 3) && GetTeamSecCount() <= 9)
  6620.         {
  6621.             //Set Reinforce Time
  6622.             g_iReinforceTime_AD_Temp = ((g_AIDir_ReinforceTimer_Orig + AID_ReinfAdj_med) + AID_ReinfAdj_pScale);
  6623.             g_iReinforceTimeSubsequent_AD_Temp = ((g_AIDir_ReinforceTimer_SubOrig + AID_ReinfAdj_med) + AID_ReinfAdj_pScale);
  6624.  
  6625.             //Mod specialized bot spawn interval
  6626.             g_fCvar_respawn_delay_team_ins_spec = ((cvarSpecDelay + AID_SpecDelayAdj_low) + AID_SpecDelayAdj_pScale_Pro);
  6627.  
  6628.             //DEBUG: Track Current Difficulty setting
  6629.             //g_AIDir_CurrDiff = 2;
  6630.  
  6631.             //Set Ambush Chance
  6632.             g_AIDir_AmbushCond_Chance = AID_AmbChance_low + AID_AmbChance_pScale;
  6633.         }
  6634.         else
  6635.         {
  6636.             //Set Reinforce Time
  6637.             g_iReinforceTime_AD_Temp = (g_AIDir_ReinforceTimer_Orig);
  6638.             g_iReinforceTimeSubsequent_AD_Temp = (g_AIDir_ReinforceTimer_SubOrig);
  6639.  
  6640.             //Mod specialized bot spawn interval
  6641.             g_fCvar_respawn_delay_team_ins_spec = cvarSpecDelay;
  6642.  
  6643.             //DEBUG: Track Current Difficulty setting
  6644.             //g_AIDir_CurrDiff = 2;
  6645.  
  6646.             //Set Ambush Chance
  6647.             g_AIDir_AmbushCond_Chance = AID_AmbChance_low + AID_AmbChance_pScale;
  6648.  
  6649.         }
  6650.     }
  6651.     // >= 50% and < 75% DOING GOOD
  6652.     else if (g_AIDir_TeamStatus >= (g_AIDir_TeamStatus_max / 2) && g_AIDir_TeamStatus < ((g_AIDir_TeamStatus_max / 4) * 3))
  6653.     {
  6654.         AI_Director_ResetReinforceTimers();
  6655.         //Set Reinforce Time
  6656.         g_iReinforceTime_AD_Temp = ((g_AIDir_ReinforceTimer_Orig - AID_ReinfAdj_med) - AID_ReinfAdj_pScale);
  6657.         g_iReinforceTimeSubsequent_AD_Temp = ((g_AIDir_ReinforceTimer_SubOrig - AID_ReinfAdj_med) - AID_ReinfAdj_pScale);
  6658.  
  6659.         //Mod specialized bot spawn interval
  6660.         g_fCvar_respawn_delay_team_ins_spec = ((cvarSpecDelay - AID_SpecDelayAdj_med) - AID_SpecDelayAdj_pScale_Con);
  6661.         if (g_fCvar_respawn_delay_team_ins_spec <= 0)
  6662.             g_fCvar_respawn_delay_team_ins_spec = 1.0;
  6663.  
  6664.         //DEBUG: Track Current Difficulty setting
  6665.         //g_AIDir_CurrDiff = 3;
  6666.  
  6667.         //Set Ambush Chance
  6668.         g_AIDir_AmbushCond_Chance = AID_AmbChance_med + AID_AmbChance_pScale;
  6669.     }
  6670.     // >= 75%  CAKE WALK
  6671.     else if (g_AIDir_TeamStatus >= ((g_AIDir_TeamStatus_max / 4) * 3))
  6672.     {
  6673.         AI_Director_ResetReinforceTimers();
  6674.         //Set Reinforce Time
  6675.         g_iReinforceTime_AD_Temp = ((g_AIDir_ReinforceTimer_Orig - AID_ReinfAdj_high) - AID_ReinfAdj_pScale);
  6676.         g_iReinforceTimeSubsequent_AD_Temp = ((g_AIDir_ReinforceTimer_SubOrig - AID_ReinfAdj_high) - AID_ReinfAdj_pScale);
  6677.  
  6678.         //Mod specialized bot spawn interval
  6679.         g_fCvar_respawn_delay_team_ins_spec = ((cvarSpecDelay - AID_SpecDelayAdj_high) - AID_SpecDelayAdj_pScale_Con);
  6680.         if (g_fCvar_respawn_delay_team_ins_spec <= 0)
  6681.             g_fCvar_respawn_delay_team_ins_spec = 1.0;
  6682.  
  6683.         //DEBUG: Track Current Difficulty setting
  6684.         //g_AIDir_CurrDiff = 4;
  6685.  
  6686.         //Set Ambush Chance
  6687.         g_AIDir_AmbushCond_Chance = AID_AmbChance_high + AID_AmbChance_pScale;
  6688.     }
  6689.     //return g_AIDir_TeamStatus;
  6690. }
  6691. //############# AI DIRECTOR In-Script END #######################
Add Comment
Please, Sign In to add comment