Advertisement
ElectricStalin

Untitled

Apr 27th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 58.99 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma tabsize 0
  3.  
  4. #define PLUGIN_VERSION "0.3.0"
  5.  
  6. #define DMG_FALL   (1 << 5)
  7. #define HIDEHUD_RADAR 1 << 12
  8. #define DMG_HEADSHOT (1 << 30)
  9. #define MAX_BUTTONS 25
  10.  
  11. #include <sourcemod>
  12. #include <SDKTools>
  13. #include <csgocolors>
  14. #include <sdkhooks>
  15. #undef REQUIRE_EXTENSIONS
  16. #include <cstrike>
  17. #define REQUIRE_EXTENSIONS
  18. #define MAX_SPAWNS 99999
  19.  
  20. /* Console variables */
  21. ConVar cvar_dm_enabled;
  22. ConVar cvar_dm_valvedm;
  23. ConVar cvar_dm_welcomemsg;
  24. ConVar cvar_dm_free_for_all;
  25. ConVar cvar_dm_hide_radar;
  26. ConVar cvar_dm_display_panel;
  27. ConVar cvar_dm_display_panel_damage;
  28. ConVar cvar_dm_sounds_bodyshots;
  29. ConVar cvar_dm_sounds_headshots;
  30. ConVar cvar_dm_headshot_only;
  31. ConVar cvar_dm_headshot_only_allow_world;
  32. ConVar cvar_dm_headshot_only_allow_knife;
  33. ConVar cvar_dm_headshot_only_allow_taser;
  34. ConVar cvar_dm_headshot_only_allow_nade;
  35. ConVar cvar_dm_remove_objectives;
  36. ConVar cvar_dm_respawning;
  37. ConVar cvar_dm_respawn_time;
  38. ConVar cvar_dm_gun_menu_mode;
  39. ConVar cvar_dm_los_spawning;
  40. ConVar cvar_dm_los_attempts;
  41. ConVar cvar_dm_spawn_distance;
  42. ConVar cvar_dm_spawn_time;
  43. ConVar cvar_dm_no_knife_damage;
  44. ConVar cvar_dm_remove_weapons;
  45. ConVar cvar_dm_replenish_ammo;
  46. ConVar cvar_dm_replenish_clip;
  47. ConVar cvar_dm_replenish_reserve;
  48. ConVar cvar_dm_replenish_grenade;
  49. ConVar cvar_dm_replenish_hegrenade;
  50. ConVar cvar_dm_replenish_grenade_kill;
  51. ConVar cvar_dm_hp_start;
  52. ConVar cvar_dm_hp_max;
  53. ConVar cvar_dm_hp_kill;
  54. ConVar cvar_dm_hp_hs;
  55. ConVar cvar_dm_hp_knife;
  56. ConVar cvar_dm_hp_nade;
  57. ConVar cvar_dm_hp_messages;
  58. ConVar cvar_dm_ap_max;
  59. ConVar cvar_dm_ap_kill;
  60. ConVar cvar_dm_ap_hs;
  61. ConVar cvar_dm_ap_knife;
  62. ConVar cvar_dm_ap_nade;
  63. ConVar cvar_dm_ap_messages;
  64. ConVar cvar_dm_nade_messages;
  65. ConVar cvar_dm_armor;
  66. ConVar cvar_dm_armor_full;
  67. ConVar cvar_dm_zeus;
  68. ConVar cvar_dm_nades_incendiary;
  69. ConVar cvar_dm_nades_molotov;
  70. ConVar cvar_dm_nades_decoy;
  71. ConVar cvar_dm_nades_flashbang;
  72. ConVar cvar_dm_nades_he;
  73. ConVar cvar_dm_nades_smoke;
  74.  
  75. Handle mp_ct_default_primary;
  76. Handle mp_t_default_primary;
  77. Handle mp_ct_default_secondary;
  78. Handle mp_t_default_secondary;
  79. Handle mp_t_default_melee;
  80. Handle mp_ct_default_melee;
  81. Handle mp_startmoney;
  82. Handle mp_playercashawards;
  83. Handle mp_teamcashawards;
  84. Handle mp_friendlyfire;
  85. Handle mp_autokick;
  86. Handle mp_tkpunish;
  87. Handle mp_teammates_are_enemies;
  88. Handle ff_damage_reduction_bullets;
  89. Handle ff_damage_reduction_grenade;
  90. Handle ff_damage_reduction_other;
  91. Handle ammo_grenade_limit_default;
  92. Handle ammo_grenade_limit_flashbang;
  93. Handle ammo_grenade_limit_total;
  94. Handle mp_roundtime_defuse;
  95. Handle mp_warmuptime;
  96. Handle mp_warmup;
  97.  
  98. Handle g_timer = INVALID_HANDLE;
  99.  
  100. bool removeWeapons=0;
  101. int backup_mp_startmoney;
  102. int backup_mp_playercashawards;
  103. int backup_mp_teamcashawards;
  104. int backup_mp_friendlyfire;
  105. int backup_mp_autokick;
  106. int backup_mp_tkpunish;
  107. int backup_mp_teammates_are_enemies;
  108. int backup_ammo_grenade_limit_default;
  109. int backup_ammo_grenade_limit_flashbang;
  110. int backup_ammo_grenade_limit_total;
  111.  
  112. new g_LastButtons[MAXPLAYERS+1];
  113. float backup_ff_damage_reduction_bullets;
  114. float backup_ff_damage_reduction_grenade;
  115. float backup_ff_damage_reduction_other;
  116. bool enabled = true;
  117. bool valveDM;
  118. bool welcomemsg;
  119. bool ffa=true;
  120. bool hideradar;
  121. bool displayPanel;
  122. bool displayPanelDamage;
  123. bool bdSounds;
  124. bool hsSounds;
  125. bool hsOnly;
  126. bool hsOnly_AllowWorld;
  127. bool hsOnly_AllowKnife;
  128. bool hsOnly_AllowTaser;
  129. bool hsOnly_AllowNade;
  130. bool removeObjectives;
  131. bool roundEnded = false;
  132.  
  133. /* Health Variables */
  134. int startHP;
  135. int maxHP;
  136. int HPPerKill;
  137. int HPPerHeadshotKill;
  138. int HPPerKnifeKill;
  139. int HPPerNadeKill;
  140.  
  141.  
  142. int defaultColor[4] = { 255, 255, 255, 255 };
  143. int tColor[4] = { 255, 0, 0, 200 };
  144. int ctColor[4] = { 0, 0, 255, 200 };
  145.  
  146. new Handle:sm_deathmatch_primary = INVALID_HANDLE;
  147. new Handle:sm_deathmatch_secondary = INVALID_HANDLE;
  148. new Handle:sm_deathmatch_blockdrop = INVALID_HANDLE;
  149. new Handle:sm_deathmatch_noscope = INVALID_HANDLE;
  150. new Handle:sm_deathmatch_health = INVALID_HANDLE;
  151. new Handle:sm_deathmatch_armor = INVALID_HANDLE;
  152. new Handle:sm_deathmatch_respawn_time = INVALID_HANDLE;
  153.  
  154. //spawn vars
  155. float spawnDistanceFromEnemies;
  156. float spawnProtectionTime;
  157. float respawnTime;
  158. bool respawning;
  159. bool lineOfSightSpawning;
  160. int lineOfSightAttempts;
  161. int spawnPointCount = 0;
  162. int spawnWeaponPointCount = 0;
  163. bool inEditMode = false;
  164. bool spawnPointOccupied[MAX_SPAWNS] = {false, ...};
  165. float spawnPositions[MAX_SPAWNS][3];
  166. float spawnAngles[MAX_SPAWNS][3];
  167. float spawnWeaponPositions[40][3];
  168. float spawnWeaponAngles[40][3];
  169. int weaponCount;
  170. ArrayList weapons;
  171. float eyeOffset[3] = { 0.0, 0.0, 64.0 }; /* CSGO offset. */
  172. float spawnPointOffset[3] = { 0.0, 0.0, 20.0 };
  173.  
  174. int lastEditorSpawnPoint[MAXPLAYERS + 1] = { -1, ... };
  175. char primaryWeapon[MAXPLAYERS + 1][24];
  176. char secondaryWeapon[MAXPLAYERS + 1][24];
  177. int infoMessageCount[MAXPLAYERS + 1] = { 2, ... };
  178. bool firstWeaponSelection[MAXPLAYERS + 1] = { true, ... };
  179. bool weaponsGivenThisRound[MAXPLAYERS + 1] = { false, ... };
  180. bool newWeaponsSelected[MAXPLAYERS + 1] = { false, ... };
  181. bool rememberChoice[MAXPLAYERS + 1] = { false, ... };
  182. bool playerMoved[MAXPLAYERS + 1] = { false, ... };
  183. /* Spawn stats */
  184. int numberOfPlayerSpawns = 0;
  185. int losSearchAttempts = 0;
  186. int losSearchSuccesses = 0;
  187. int losSearchFailures = 0;
  188. int distanceSearchAttempts = 0;
  189. int distanceSearchSuccesses = 0;
  190. int distanceSearchFailures = 0;
  191. int spawnPointSearchFailures = 0;
  192. //
  193. int i_PlayerCount;
  194. bool b_MaxClients;
  195.  
  196. public Plugin myinfo =
  197. {
  198.     name = "Skin Deathmatch",
  199.     author = "ElectricStalin",
  200.     description = "",
  201.     version = PLUGIN_VERSION,
  202.     url = "",
  203. };
  204.  
  205. public OnPluginStart()
  206. {
  207.     //ServerCommand("mp_warmuptime 999999");
  208.     RetrieveVariables();
  209.     SetNoSpawnWeapons();
  210.     sm_deathmatch_primary = CreateConVar("sm_deathmatch_primary", "", "ID of the primary weapon (Default: weapon_awp)");
  211.     sm_deathmatch_secondary = CreateConVar("sm_deathmatch_secondary", "weapon_glock", "ID of the primary weapon (Default: weapon_revolver)");
  212.     sm_deathmatch_blockdrop = CreateConVar("sm_deathmatch_blockdrop", "0", "Block the drop of weapon (1 = yes, 0 = no)(Default: 1)");
  213.     sm_deathmatch_noscope = CreateConVar("sm_deathmatch_noscope", "0", "Noscope mode (1 = yes, 0 = no)(Default: 0)");
  214.     sm_deathmatch_health = CreateConVar("sm_deathmatch_health", "100", "Players Health on spawn (Default: 100)");
  215.     sm_deathmatch_armor = CreateConVar("sm_deathmatch_armor", "0", "Player Armor on spawn (Default: 0)");
  216.     sm_deathmatch_respawn_time = CreateConVar("sm_deathmatch_respawn_time", "3.0", "Time between the player's death and his respawn (Default: 3.0)");
  217.    
  218.         /* Hook Events */
  219.     HookEvent("player_team", Event_PlayerTeam);
  220.     HookEvent("round_prestart", Event_RoundPrestart, EventHookMode_PostNoCopy);
  221.     HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  222.     HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
  223.     HookEvent("player_death", Event_PlayerDeath);
  224.     HookEvent("bomb_pickup", Event_BombPickup);
  225.     HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
  226.    
  227.     AddCommandListener(OnCommandDrop, "drop");
  228.    
  229.     /* Let's not waste our time here... */
  230.     if(GetEngineVersion() != Engine_CSGO)
  231.     {
  232.         SetFailState("ERROR: This plugin is designed only for CS:GO.");
  233.     }
  234.  
  235.     /* Load translations for multi-language */
  236.     LoadTranslations("deathmatch.phrases");
  237.     LoadTranslations("common.phrases");
  238.  
  239.     /* Create spawns directory if necessary. */
  240.     char spawnsPath[PLATFORM_MAX_PATH];
  241.     BuildPath(Path_SM, spawnsPath, sizeof(spawnsPath), "configs/deathmatch/spawns");
  242.     if (!DirExists(spawnsPath))
  243.         CreateDirectory(spawnsPath, 711);
  244.  
  245.     /* Find Offsets */
  246.     /*ownerOffset = FindSendPropInfo("CBaseCombatWeapon", "m_hOwnerEntity");
  247.     healthOffset = FindSendPropInfo("CCSPlayerResource", "m_iHealth");
  248.     armorOffset = FindSendPropInfo("CCSPlayer", "m_ArmorValue");
  249.     helmetOffset = FindSendPropInfo("CCSPlayer", "m_bHasHelmet");
  250.     ammoTypeOffset = FindSendPropInfo("CBaseCombatWeapon", "m_iPrimaryAmmoType");
  251.     ammoOffset = FindSendPropInfo("CCSPlayer", "m_iAmmo");
  252.     ragdollOffset = FindSendPropInfo("CCSPlayer", "m_hRagdoll");*/
  253.  
  254.     /* Create arrays to store available weapons loaded by config */
  255.     /*primaryWeaponsAvailable = CreateArray(24);
  256.     secondaryWeaponsAvailable = CreateArray(10);
  257.     weaponSkipMap = new StringMap();*/
  258.  
  259.     /* Create trie to store menu names for weapons */
  260.     //BuildWeaponMenuNames();
  261.  
  262.     /* Create trie to store weapon limits and counts */
  263.     //weaponLimits = CreateTrie();
  264.     //weaponCounts = CreateTrie();
  265.  
  266.     /* Create Menus */
  267.     //optionsMenu1 = BuildOptionsMenu(true);
  268.     //optionsMenu2 = BuildOptionsMenu(false);
  269.  
  270.     /* Create Console Variables */
  271.     //CreateConVar("dm_m5_version", PLUGIN_VERSION, PLUGIN_NAME, FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);
  272.     cvar_dm_enabled = CreateConVar("dm_enabled", "1", "Enable Deathmatch.");
  273.     cvar_dm_valvedm = CreateConVar("dm_enable_valve_deathmatch", "0", "Enable compatibility for Valve's Deathmatch (game_type 1 & game_mode 2) or Custom (game_type 3 & game_mode 0).");
  274.     cvar_dm_welcomemsg = CreateConVar("dm_welcomemsg", "1", "Display a message saying that your server is running Deathmatch.");
  275.     cvar_dm_free_for_all = CreateConVar("dm_free_for_all", "0", "Free for all mode.");
  276.     cvar_dm_hide_radar = CreateConVar("dm_hide_radar", "0", "Hides the radar from players.");
  277.     cvar_dm_display_panel = CreateConVar("dm_display_panel", "0", "Display a panel showing health of the victim.");
  278.     cvar_dm_display_panel_damage = CreateConVar("dm_display_panel_damage", "0", "Display a panel showing damage done to a player. Requires dm_display_panel set to 1.");
  279.     cvar_dm_sounds_bodyshots = CreateConVar("dm_sounds_bodyshots", "1", "Enable the sounds of bodyshots.");
  280.     cvar_dm_sounds_headshots = CreateConVar("dm_sounds_headshots", "1", "Enable the sounds of headshots.");
  281.     cvar_dm_headshot_only = CreateConVar("dm_headshot_only", "0", "Headshot only mode.");
  282.     cvar_dm_headshot_only_allow_world = CreateConVar("dm_headshot_only_allow_world", "0", "Enable world damage during headshot only mode.");
  283.     cvar_dm_headshot_only_allow_knife = CreateConVar("dm_headshot_only_allow_knife", "0", "Enable knife damage during headshot only mode.");
  284.     cvar_dm_headshot_only_allow_taser = CreateConVar("dm_headshot_only_allow_taser", "0", "Enable taser damage during headshot only mode.");
  285.     cvar_dm_headshot_only_allow_nade = CreateConVar("dm_headshot_only_allow_nade", "0", "Enable grenade damage during headshot only mode.");
  286.     cvar_dm_remove_objectives = CreateConVar("dm_remove_objectives", "1", "Remove objectives (disables bomb sites, and removes c4 and hostages).");
  287.     cvar_dm_respawning = CreateConVar("dm_respawning", "1", "Enable respawning.");
  288.     cvar_dm_respawn_time = CreateConVar("dm_respawn_time", "2.0", "Respawn time.");
  289.     cvar_dm_gun_menu_mode = CreateConVar("dm_gun_menu_mode", "1", "Gun menu mode. 1) Enabled. 2) Primary weapons only. 3) Secondary weapons only. 4) Random weapons only. 5) Disabled.");
  290.     cvar_dm_los_spawning = CreateConVar("dm_los_spawning", "1", "Enable line of sight spawning. If enabled, players will be spawned at a point where they cannot see enemies, and enemies cannot see them.");
  291.     cvar_dm_los_attempts = CreateConVar("dm_los_attempts", "10", "Maximum number of attempts to find a suitable line of sight spawn point.");
  292.     cvar_dm_spawn_distance = CreateConVar("dm_spawn_distance", "0.0", "Minimum distance from enemies at which a player can spawn.");
  293.     cvar_dm_spawn_time = CreateConVar("dm_spawn_time", "1.0", "Spawn protection time.");
  294.     cvar_dm_no_knife_damage = CreateConVar("dm_no_knife_damage", "0", "Knives do NO damage to players.");
  295.     cvar_dm_remove_weapons = CreateConVar("dm_remove_weapons", "1", "Remove ground weapons.");
  296.     cvar_dm_replenish_ammo = CreateConVar("dm_replenish_ammo", "1", "Replenish ammo on reload.");
  297.     cvar_dm_replenish_clip = CreateConVar("dm_replenish_clip", "0", "Replenish ammo clip on kill.");
  298.     cvar_dm_replenish_reserve = CreateConVar("dm_replenish_reserve", "0", "Replenish ammo reserve on kill.");
  299.     cvar_dm_replenish_grenade = CreateConVar("dm_replenish_grenade", "0", "Unlimited player grenades.");
  300.     cvar_dm_replenish_hegrenade = CreateConVar("dm_replenish_hegrenade", "0", "Unlimited hegrenades.");
  301.     cvar_dm_replenish_grenade_kill = CreateConVar("dm_replenish_grenade_kill", "0", "Give players their grenade back on successful kill.");
  302.     cvar_dm_hp_start = CreateConVar("dm_hp_start", "100", "Spawn Health Points (HP).");
  303.     cvar_dm_hp_max = CreateConVar("dm_hp_max", "100", "Maximum Health Points (HP).");
  304.     cvar_dm_hp_kill = CreateConVar("dm_hp_kill", "5", "Health Points (HP) per kill.");
  305.     cvar_dm_hp_hs = CreateConVar("dm_hp_hs", "10", "Health Points (HP) per headshot kill.");
  306.     cvar_dm_hp_knife = CreateConVar("dm_hp_knife", "50", "Health Points (HP) per knife kill.");
  307.     cvar_dm_hp_nade = CreateConVar("dm_hp_nade", "30", "Health Points (HP) per nade kill.");
  308.     cvar_dm_hp_messages = CreateConVar("dm_hp_messages", "1", "Display HP messages.");
  309.     cvar_dm_ap_max = CreateConVar("dm_ap_max", "100", "Maximum Armor Points (AP).");
  310.     cvar_dm_ap_kill = CreateConVar("dm_ap_kill", "5", "Armor Points (AP) per kill.");
  311.     cvar_dm_ap_hs = CreateConVar("dm_ap_hs", "10", "Armor Points (AP) per headshot kill.");
  312.     cvar_dm_ap_knife = CreateConVar("dm_ap_knife", "50", "Armor Points (AP) per knife kill.");
  313.     cvar_dm_ap_nade = CreateConVar("dm_ap_nade", "30", "Armor Points (AP) per nade kill.");
  314.     cvar_dm_ap_messages = CreateConVar("dm_ap_messages", "1", "Display AP messages.");
  315.     cvar_dm_nade_messages = CreateConVar("dm_nade_messages", "1", "Display grenade messages.");
  316.     cvar_dm_armor = CreateConVar("dm_armor", "0", "Give players chest armor.");
  317.     cvar_dm_armor_full = CreateConVar("dm_armor_full", "1", "Give players head and chest armor.");
  318.     cvar_dm_zeus = CreateConVar("dm_zeus", "0", "Give players a taser.");
  319.     cvar_dm_nades_incendiary = CreateConVar("dm_nades_incendiary", "0", "Number of incendiary grenades to give each player.");
  320.     cvar_dm_nades_molotov = CreateConVar("dm_nades_molotov", "0", "Number of molotov grenades to give each player.");
  321.     cvar_dm_nades_decoy = CreateConVar("dm_nades_decoy", "0", "Number of decoy grenades to give each player.");
  322.     cvar_dm_nades_flashbang = CreateConVar("dm_nades_flashbang", "0", "Number of flashbang grenades to give each player.");
  323.     cvar_dm_nades_he = CreateConVar("dm_nades_he", "0", "Number of HE grenades to give each player.");
  324.     cvar_dm_nades_smoke = CreateConVar("dm_nades_smoke", "0", "Number of smoke grenades to give each player.");
  325.  
  326.     /* Load DM Config */
  327.     LoadConfig();
  328.  
  329.     /* Listen For Client Commands */
  330.     //AddCommandListener(Event_Say, "say");
  331.     //AddCommandListener(Event_Say, "say_team");
  332.  
  333.     /* Hook Client Messages */
  334.     //HookUserMessage(GetUserMessageId("TextMsg"), Event_TextMsg, true);
  335.     //HookUserMessage(GetUserMessageId("HintText"), Event_HintText, true);
  336.     //HookUserMessage(GetUserMessageId("RadioText"), Event_RadioText, true);
  337.  
  338.     /* Hook Events */
  339.     HookEvent("player_team", Event_PlayerTeam);
  340.     HookEvent("round_prestart", Event_RoundPrestart, EventHookMode_PostNoCopy);
  341.     HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  342.     HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  343.     HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
  344.     HookEvent("player_death", Event_PlayerDeath);
  345.     HookEvent("bomb_pickup", Event_BombPickup);
  346.  
  347.     /* Hook Sound Events */
  348.     AddNormalSoundHook(view_as<NormalSHook>(Event_Sound));
  349.  
  350.     /* Create Global Timers */
  351.     CreateTimer(0.5, UpdateSpawnPointStatus, INVALID_HANDLE, TIMER_REPEAT);
  352.  
  353.     /* Find Offsets */
  354.     //g_iWeapons_Clip1Offset = FindSendPropInfo("CBaseCombatWeapon", "m_iClip1");
  355.  
  356.     /*if (g_iWeapons_Clip1Offset == -1)
  357.     {
  358.         SetFailState("[DM] Error - Unable to get offset for CBaseCombatWeapon::m_iClip1");
  359.     }
  360.  
  361.     healthOffset = FindSendPropInfo("CCSPlayer", "m_iHealth");
  362.  
  363.     if (healthOffset == -1)
  364.     {
  365.         SetFailState("[DM] Error - Unable to get offset for CCSPlayer::m_iHealth");
  366.     }
  367.  
  368.     armorOffset = FindSendPropInfo("CCSPlayer", "m_ArmorValue");
  369.  
  370.     if (armorOffset == -1)
  371.     {
  372.         SetFailState("[DM] Error - Unable to get offset for CCSPlayer::m_ArmorValue");
  373.     }
  374. */
  375.     /* SDK Hooks For Clients */
  376.     for (int i = 1; i <= MaxClients; i++)
  377.     {
  378.         if (IsClientInGame(i))
  379.         {
  380.             OnClientPutInServer(i);
  381.         }
  382.     }
  383.     /* Update and retrieve */
  384.     RetrieveVariables();
  385.     UpdateState();
  386.    
  387. }
  388.  
  389. public void OnMapStart()
  390. {
  391.     //RetrieveVariables();
  392.     EnableFFA();
  393.     LoadMapConfig();
  394.     SetBuyZones("Disable");
  395.     i_PlayerCount = 0;
  396.     b_MaxClients = false;
  397.    
  398. }
  399.  
  400. public void OnMapEnd()
  401. {
  402.     i_PlayerCount = 0;
  403.     b_MaxClients = false;
  404. }  
  405.  
  406. void LoadMapConfig()
  407. {
  408.     char map[64];
  409.     GetCurrentMap(map, sizeof(map));
  410.     /*Player spawn config loading*/
  411.     char path[PLATFORM_MAX_PATH];
  412.     BuildPath(Path_SM, path, sizeof(path), "configs/sdm/spawns/%s.txt", map);
  413.  
  414.     spawnPointCount = 0;
  415.  
  416.     /* Open file */
  417.     Handle file = OpenFile(path, "r");
  418.     if (file == INVALID_HANDLE)
  419.         return;
  420.     /* Read file */
  421.     char buffer[256];
  422.     char parts[6][16];
  423.     while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
  424.     {
  425.         ExplodeString(buffer, " ", parts, 6, 16);
  426.         spawnPositions[spawnPointCount][0] = StringToFloat(parts[0]);
  427.         spawnPositions[spawnPointCount][1] = StringToFloat(parts[1]);
  428.         spawnPositions[spawnPointCount][2] = StringToFloat(parts[2]);
  429.         spawnAngles[spawnPointCount][0] = StringToFloat(parts[3]);
  430.         spawnAngles[spawnPointCount][1] = StringToFloat(parts[4]);
  431.         spawnAngles[spawnPointCount][2] = StringToFloat(parts[5]);
  432.         spawnPointCount++;
  433.     }
  434.     /* Close file */
  435.     CloseHandle(file);
  436.     /*Weapons spawn config loading*/
  437.     BuildPath(Path_SM, path, sizeof(path), "configs/sdm/weapon_spawn/%s.txt", map);
  438.  
  439.     spawnWeaponPointCount = 0;
  440.  
  441.     /* Open file */
  442.     file = OpenFile(path, "r");
  443.     if (file == INVALID_HANDLE)
  444.         return;
  445.     /* Read file */
  446.  
  447.     while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
  448.     {
  449.         ExplodeString(buffer, " ", parts, 6, 16);
  450.         spawnWeaponPositions[spawnWeaponPointCount][0] = StringToFloat(parts[0]);
  451.         spawnWeaponPositions[spawnWeaponPointCount][1] = StringToFloat(parts[1]);
  452.         spawnWeaponPositions[spawnWeaponPointCount][2] = StringToFloat(parts[2])+55.0;
  453.         spawnWeaponAngles[spawnWeaponPointCount][0] = StringToFloat(parts[3]);
  454.         spawnWeaponAngles[spawnWeaponPointCount][1] = StringToFloat(parts[4]);
  455.         spawnWeaponAngles[spawnWeaponPointCount][2] = StringToFloat(parts[5]);
  456.         spawnWeaponPointCount++;
  457.     }
  458.     /* Close file */
  459.     CloseHandle(file);
  460.     /*Weapons names config loading*/
  461.     BuildPath(Path_SM, path, sizeof(path), "configs/sdm/weapons.txt");
  462.  
  463.     int count = 0;
  464.     weapons = new ArrayList(ByteCountToCells(64));
  465.     /* Open file */
  466.     file = OpenFile(path, "r");
  467.     if (file == INVALID_HANDLE)
  468.         return;
  469.     /* Read file */
  470.  
  471.     while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
  472.     {
  473.         count++;
  474.         weapons.PushString(buffer);
  475.         LogError("Loaded from file '%s'",buffer);
  476.     }
  477.     /* Close file */
  478.     CloseHandle(file);
  479. }
  480.  
  481. public OnClientDisconnect_Post(client)
  482. {
  483.     g_LastButtons[client] = 0;
  484.     i_PlayerCount = i_PlayerCount - 1;
  485. }
  486.  
  487. void RetrieveVariables()
  488. {
  489.     /* Retrieve Native Console Variables */
  490.     mp_ct_default_primary = FindConVar("mp_ct_default_primary");
  491.     mp_t_default_primary = FindConVar("mp_t_default_primary");
  492.     mp_ct_default_secondary = FindConVar("mp_ct_default_secondary");
  493.     mp_t_default_secondary = FindConVar("mp_t_default_secondary");
  494.     mp_t_default_melee = FindConVar("mp_t_default_melee");
  495.     mp_ct_default_melee = FindConVar("mp_t_default_melee");
  496.    
  497.     mp_startmoney = FindConVar("mp_startmoney");
  498.     mp_playercashawards = FindConVar("mp_playercashawards");
  499.     mp_teamcashawards = FindConVar("mp_teamcashawards");
  500.     mp_friendlyfire = FindConVar("mp_friendlyfire");
  501.     mp_autokick = FindConVar("mp_autokick");
  502.     mp_tkpunish = FindConVar("mp_tkpunish");
  503.     mp_teammates_are_enemies = FindConVar("mp_teammates_are_enemies");
  504.     ff_damage_reduction_bullets = FindConVar("ff_damage_reduction_bullets");
  505.     ff_damage_reduction_grenade = FindConVar("ff_damage_reduction_grenade");
  506.     ff_damage_reduction_other = FindConVar("ff_damage_reduction_other");
  507.     ammo_grenade_limit_default = FindConVar("ammo_grenade_limit_default");
  508.     ammo_grenade_limit_flashbang = FindConVar("ammo_grenade_limit_flashbang");
  509.     ammo_grenade_limit_total = FindConVar("ammo_grenade_limit_total");
  510.     mp_roundtime_defuse = FindConVar("mp_roundtime_defuse");
  511.     mp_warmuptime = FindConVar("mp_warmuptime");
  512.     mp_warmup = FindConVar("mp_warmup");
  513.  
  514.     /* Retrieve Native Console Variable Values */
  515.     backup_mp_startmoney = GetConVarInt(mp_startmoney);
  516.     backup_mp_playercashawards = GetConVarInt(mp_playercashawards);
  517.     backup_mp_teamcashawards = GetConVarInt(mp_teamcashawards);
  518.     backup_mp_friendlyfire = GetConVarInt(mp_friendlyfire);
  519.     backup_mp_autokick = GetConVarInt(mp_autokick);
  520.     backup_mp_tkpunish = GetConVarInt(mp_tkpunish);
  521.     backup_mp_teammates_are_enemies = GetConVarInt(mp_teammates_are_enemies);
  522.     backup_ff_damage_reduction_bullets = GetConVarFloat(ff_damage_reduction_bullets);
  523.     backup_ff_damage_reduction_grenade = GetConVarFloat(ff_damage_reduction_grenade);
  524.     backup_ff_damage_reduction_other = GetConVarFloat(ff_damage_reduction_other);
  525.     backup_ammo_grenade_limit_default = GetConVarInt(ammo_grenade_limit_default);
  526.     backup_ammo_grenade_limit_flashbang = GetConVarInt(ammo_grenade_limit_flashbang);
  527.     backup_ammo_grenade_limit_total = GetConVarInt(ammo_grenade_limit_total);
  528. }
  529.  
  530. public Action:OnCommandDrop(client, const String:command[], argc)
  531. {
  532.     int BlockDrop = GetConVarInt(sm_deathmatch_blockdrop);
  533.     if(BlockDrop == 1)
  534.         return Plugin_Handled;
  535.    
  536.     return Plugin_Continue;
  537. }
  538.  
  539. // Players Actions
  540.  
  541. public OnClientPutInServer(client)
  542. {
  543.     SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
  544.     SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
  545.     i_PlayerCount++;
  546.     g_timer = CreateTimer(15.0, Timer_check, client, TIMER_REPEAT);
  547.     //WarmupCheck();
  548. }
  549.  
  550. stock bool IsValidClient(int client)
  551. {
  552.     if (!(0 < client <= MaxClients)) return false;
  553.     if (!IsClientInGame(client)) return false;
  554.     return true;
  555. }
  556.  
  557. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  558. {
  559.     if (!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client)) return Plugin_Continue;
  560.    
  561.     if(!(buttons & IN_ATTACK2))
  562.     {
  563.         return Plugin_Continue;
  564.     }
  565.    
  566.     decl String:sWeapon[32];
  567.     GetClientWeapon(client, sWeapon, sizeof(sWeapon));
  568.        
  569.     int NoScope = GetConVarInt(sm_deathmatch_noscope);
  570.    
  571.     if(NoScope == 1){
  572.         if(StrEqual(sWeapon, "weapon_awp", false) || StrEqual(sWeapon, "weapon_scout", false))
  573.         {
  574.             buttons &= ~IN_ATTACK2;
  575.             return Plugin_Changed;
  576.         }
  577.     }
  578.    
  579.     for (new i = 0; i < MAX_BUTTONS; i++)
  580.     {
  581.         new button = (1 << i);
  582.        
  583.         if ((buttons & button))
  584.         {
  585.             if (!(g_LastButtons[client] & button))
  586.             {
  587.                 OnButtonPress(client, button);
  588.             }
  589.         }
  590.         else if ((g_LastButtons[client] & button))
  591.         {
  592.             OnButtonRelease(client, button);
  593.         }
  594.     }
  595.    
  596.     g_LastButtons[client] = buttons;
  597.    
  598.     return Plugin_Continue;
  599. }
  600.  
  601. //Hook Callbacks
  602. /////////////////////////////////////////
  603. public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  604. {
  605.         SpawnWeapons();
  606. }
  607. ////////////////////////////////////////////////////
  608.  
  609. public Event_PlayerDeath(Event:event, const String:name[], bool:dontBroadcast)
  610. {
  611.     if (enabled)
  612.     {
  613.         int client = GetClientOfUserId(event.GetInt("userid"));
  614.         if (respawning)
  615.         {
  616.             CreateTimer(respawnTime, Respawn, GetClientSerial(client));
  617.         }
  618.     }
  619. }
  620.  
  621. public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
  622. {
  623.     int client = GetClientOfUserId(event.GetInt("userid"));
  624.  
  625.     /* If the player joins spectator, close any open menu, and remove their ragdoll. */
  626.     if ((client != 0) && (GetClientTeam(client) == CS_TEAM_SPECTATOR))
  627.     {
  628.         CancelClientMenu(client);
  629.     }
  630.     if (enabled && respawning)
  631.         CreateTimer(respawnTime, Respawn, GetClientSerial(client));
  632. }
  633.  
  634. public Action:OnTakeDamage(client, &attacker, &inflictor, &Float:damage, &damagetype)
  635. {
  636.     if (damagetype & DMG_FALL)
  637.         return Plugin_Handled;
  638.    
  639.     return Plugin_Continue;
  640. }
  641.  
  642. public Action:OnWeaponDrop(client, weapon)
  643. {
  644.      // или GetEdictClassname(index, weapon, sizeof(weapon));
  645.          if (IsClientInGame(client) && IsPlayerAlive(client))
  646.          return Plugin_Handled;
  647.      return Plugin_Continue;
  648. }
  649.  
  650. // Events
  651.  
  652. /*public Action Event_PlayerSpawn(Handle event, char[] name, bool dontBroadcast)
  653. {
  654.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  655.    
  656.     int PlayerHealth = GetConVarInt(sm_deathmatch_health);
  657.     int PlayerArmor = GetConVarInt(sm_deathmatch_armor);
  658.    
  659.     SetEntityHealth(client, PlayerHealth);
  660.     SetEntProp(client, Prop_Send, "m_ArmorValue", PlayerArmor, 1);
  661.    
  662.     CreateTimer(0.1, GiveGuns, client);
  663. }*/
  664.  
  665. public Action Event_WeaponReload(Handle event, char[] name, bool dontBroadcast)
  666. {
  667.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  668.    
  669.     new PlayerWeaponIndex;
  670.     PlayerWeaponIndex = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  671.    
  672.     SetEntProp(PlayerWeaponIndex, Prop_Send, "m_iPrimaryReserveAmmoCount", 100);
  673.    
  674.     return Plugin_Continue;
  675. }
  676.  
  677. // Timer Callbacks
  678.  
  679. public Action GiveGuns(Handle timer, any client)
  680. {
  681.     /*decl String:PrimaryID[512];
  682.     decl String:SecondaryID[512];
  683.    
  684.     GetConVarString(sm_deathmatch_primary, PrimaryID, sizeof(PrimaryID));
  685.     GetConVarString(sm_deathmatch_secondary, SecondaryID, sizeof(SecondaryID));
  686.    
  687.     int HavePrimary = GetPlayerWeaponSlot(client, 0);
  688.     if (HavePrimary != -1)
  689.     {
  690.         RemovePlayerItem(client, HavePrimary);
  691.         RemoveEdict(HavePrimary);
  692.     }
  693.     int HaveSecondary = GetPlayerWeaponSlot(client, 1);
  694.     if (HaveSecondary != -1)
  695.     {
  696.         RemovePlayerItem(client, HaveSecondary);
  697.         RemoveEdict(HaveSecondary);
  698.     }
  699.    
  700.     GivePlayerItem(client, PrimaryID, 0);
  701.     GivePlayerItem(client, SecondaryID, 0);*/
  702. }
  703.  
  704. public Action Event_RoundPrestart(Event event, const char[] name, bool dontBroadcast)
  705. {
  706.     roundEnded = false;
  707. }
  708.  
  709. public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  710. {
  711.     roundEnded = true;
  712. }
  713.  
  714. public Action:RespawnPlayer(Handle:Timer, any:client)
  715. {
  716.     decl String:game[40];
  717.     GetGameFolderName(game, sizeof(game));
  718.  
  719.     if(StrEqual(game, "cstrike") || StrEqual(game, "csgo"))
  720.     {
  721.         new team = GetClientTeam(client);
  722.         if(team == 2 || team == 3)
  723.         {
  724.             CS_RespawnPlayer(client);
  725.         }
  726.     }
  727. }
  728.  
  729. public Action Respawn(Handle timer, any serial)
  730. {
  731.     int client = GetClientFromSerial(serial);
  732.     if (!roundEnded && IsValidClient(client) && (GetClientTeam(client) != CS_TEAM_SPECTATOR) && !IsPlayerAlive(client))
  733.     {
  734.         /* We set this here rather than in Event_PlayerSpawn to catch the spawn sounds which occur before Event_PlayerSpawn is called (even with EventHookMode_Pre). */
  735.         playerMoved[client] = false;
  736.         CS_RespawnPlayer(client);
  737.     }
  738. }
  739.  
  740. public Action:deleteWeapon(Handle:timer, any:weapon)
  741. {
  742.     /*if (weapon && IsValidEdict(weapon) && IsValidEntity(weapon))
  743.         RemoveEdict(weapon);*/
  744. }
  745.  
  746. void EnableFFA()
  747. {
  748.     SetConVarInt(mp_teammates_are_enemies, 1);
  749.     SetConVarInt(mp_friendlyfire, 1);
  750.     SetConVarInt(mp_autokick, 0);
  751.     SetConVarInt(mp_tkpunish, 0);
  752.     SetConVarFloat(ff_damage_reduction_bullets, 1.0);
  753.     SetConVarFloat(ff_damage_reduction_grenade, 1.0);
  754.     SetConVarFloat(ff_damage_reduction_other, 1.0);
  755.     SetConVarFloat(mp_roundtime_defuse, 6.0);
  756.     SetConVarFloat(mp_warmuptime, 999999.0);
  757. }
  758.  
  759. /*public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
  760. {
  761.  CreateTimer(15.0, Timer_check, client);
  762.  
  763.  return true;
  764. }*/
  765.  
  766. public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
  767. {
  768.     if (enabled)
  769.     {
  770.         int client = GetClientOfUserId(event.GetInt("userid"));
  771.         if (GetClientTeam(client) != CS_TEAM_SPECTATOR)
  772.         {
  773.             if (!IsFakeClient(client))
  774.             {
  775.                 if (welcomemsg && infoMessageCount[client] > 0)
  776.                 {
  777.                     PrintHintText(client, "This server is running:\n <font color='#00FF00'>Deathmatch</font> ");
  778.                     //CPrintToChat(client, "[\x04DM\x01] This server is running \x04Deathmatch \x01v%s");
  779.                 }
  780.                 /* Hide radar. */
  781.                 if (ffa || hideradar)
  782.                 {
  783.                     CreateTimer(0.0, RemoveRadar, GetClientSerial(client));
  784.                 }
  785.  
  786.             }
  787.             /* Teleport player to custom spawn point. */
  788.             if (spawnPointCount > 0)
  789.             {
  790.                 MovePlayer(client);
  791.             }
  792.             /* Enable player spawn protection. */
  793.             if (spawnProtectionTime > 0.0)
  794.             {
  795.                 EnableSpawnProtection(client);
  796.             }
  797.             /* Set health. */
  798.             if (startHP != 100)
  799.             {
  800.                 SetEntityHealth(client, startHP);
  801.             }
  802.  
  803.             /* Remove C4. */
  804.             if (removeObjectives)
  805.             {
  806.                 StripC4(client);
  807.             }
  808.         }
  809.     }
  810. }
  811.  
  812. void MovePlayer(int client)
  813. {
  814.     numberOfPlayerSpawns++; /* Stats */
  815.  
  816.     int clientTeam = GetClientTeam(client);
  817.  
  818.     int spawnPoint;
  819.     bool spawnPointFound = false;
  820.  
  821.     float enemyEyePositions[MAXPLAYERS+1][3];
  822.     int numberOfEnemies = 0;
  823.  
  824.     /* Retrieve enemy positions if required by LoS/distance spawning (at eye level for LoS checking). */
  825.     if (lineOfSightSpawning || (spawnDistanceFromEnemies > 0.0))
  826.     {
  827.         for (int i = 1; i <= MaxClients; i++)
  828.         {
  829.             if (IsClientInGame(i) && (GetClientTeam(i) != CS_TEAM_SPECTATOR) && IsPlayerAlive(i))
  830.             {
  831.                 bool enemy = (ffa || (GetClientTeam(i) != clientTeam));
  832.                 if (enemy)
  833.                 {
  834.                     GetClientEyePosition(i, enemyEyePositions[numberOfEnemies]);
  835.                     numberOfEnemies++;
  836.                 }
  837.             }
  838.         }
  839.     }
  840.  
  841.     if (lineOfSightSpawning)
  842.     {
  843.         losSearchAttempts++; /* Stats */
  844.  
  845.         /* Try to find a suitable spawn point with a clear line of sight. */
  846.         for (int i = 0; i < lineOfSightAttempts; i++)
  847.         {
  848.             spawnPoint = GetRandomInt(0, spawnPointCount - 1);
  849.  
  850.             if (spawnPointOccupied[spawnPoint])
  851.                 continue;
  852.  
  853.             if (spawnDistanceFromEnemies > 0.0)
  854.             {
  855.                 if (!IsPointSuitableDistance(spawnPoint, enemyEyePositions, numberOfEnemies))
  856.                     continue;
  857.             }
  858.  
  859.             float spawnPointEyePosition[3];
  860.             AddVectors(spawnPositions[spawnPoint], eyeOffset, spawnPointEyePosition);
  861.  
  862.             bool hasClearLineOfSight = true;
  863.  
  864.             for (int j = 0; j < numberOfEnemies; j++)
  865.             {
  866.                 Handle trace = TR_TraceRayFilterEx(spawnPointEyePosition, enemyEyePositions[j], MASK_PLAYERSOLID_BRUSHONLY, RayType_EndPoint, TraceEntityFilterPlayer);
  867.                 if (!TR_DidHit(trace))
  868.                 {
  869.                     hasClearLineOfSight = false;
  870.                     CloseHandle(trace);
  871.                     break;
  872.                 }
  873.                 CloseHandle(trace);
  874.             }
  875.             if (hasClearLineOfSight)
  876.             {
  877.                 spawnPointFound = true;
  878.                 break;
  879.             }
  880.         }
  881.         /* Stats */
  882.         if (spawnPointFound)
  883.             losSearchSuccesses++;
  884.         else
  885.             losSearchFailures++;
  886.     }
  887.  
  888.     /* First fallback. Find a random unccupied spawn point at a suitable distance. */
  889.     if (!spawnPointFound && (spawnDistanceFromEnemies > 0.0))
  890.     {
  891.         distanceSearchAttempts++; /* Stats */
  892.  
  893.         for (int i = 0; i < 100; i++)
  894.         {
  895.             spawnPoint = GetRandomInt(0, spawnPointCount - 1);
  896.             if (spawnPointOccupied[spawnPoint])
  897.                 continue;
  898.  
  899.             if (!IsPointSuitableDistance(spawnPoint, enemyEyePositions, numberOfEnemies))
  900.                 continue;
  901.  
  902.             spawnPointFound = true;
  903.             break;
  904.         }
  905.         /* Stats */
  906.         if (spawnPointFound)
  907.             distanceSearchSuccesses++;
  908.         else
  909.             distanceSearchFailures++;
  910.     }
  911.  
  912.     /* Final fallback. Find a random unoccupied spawn point. */
  913.     if (!spawnPointFound)
  914.     {
  915.         for (int i = 0; i < 100; i++)
  916.         {
  917.             spawnPoint = GetRandomInt(0, spawnPointCount - 1);
  918.             if (!spawnPointOccupied[spawnPoint])
  919.             {
  920.                 spawnPointFound = true;
  921.                 break;
  922.             }
  923.         }
  924.     }
  925.  
  926.     if (spawnPointFound)
  927.     {
  928.         TeleportEntity(client, spawnPositions[spawnPoint], spawnAngles[spawnPoint], NULL_VECTOR);
  929.         spawnPointOccupied[spawnPoint] = true;
  930.         playerMoved[client] = true;
  931.     }
  932.  
  933.     if (!spawnPointFound) spawnPointSearchFailures++; /* Stats */
  934. }
  935.  
  936. bool IsPointSuitableDistance(int spawnPoint, float[][3] enemyEyePositions, int numberOfEnemies)
  937. {
  938.     for (int i = 0; i < numberOfEnemies; i++)
  939.     {
  940.         float distance = GetVectorDistance(spawnPositions[spawnPoint], enemyEyePositions[i], true);
  941.         if (distance < spawnDistanceFromEnemies)
  942.             return false;
  943.     }
  944.     return true;
  945. }
  946.  
  947. public bool TraceEntityFilterPlayer(int entity, int contentsMask)
  948. {
  949.     if ((entity > 0) && (entity <= MaxClients)) return false;
  950.     return true;
  951. }
  952.  
  953. void SetPlayerColor(int client, const int color[4])
  954. {
  955.     SetEntityRenderMode(client, (color[3] == 255) ? RENDER_NORMAL : RENDER_TRANSCOLOR);
  956.     SetEntityRenderColor(client, color[0], color[1], color[2], color[3]);
  957. }
  958.  
  959. public Action RemoveRadar(Handle timer, any serial)
  960. {
  961.     int client = GetClientFromSerial(serial);
  962.     if (IsValidClient(client) && IsPlayerAlive(client))
  963.     {
  964.         SetEntProp(client, Prop_Send, "m_iHideHUD", HIDEHUD_RADAR);
  965.     }
  966. }
  967.  
  968. public Action DisableSpawnProtection(Handle timer, any client)
  969. {
  970.     if (IsValidClient(client) && (GetClientTeam(client) != CS_TEAM_SPECTATOR) && IsPlayerAlive(client))
  971.     {
  972.         /* Enable damage */
  973.         SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
  974.         /* Set player color */
  975.         SetPlayerColor(client, defaultColor);
  976.     }
  977. }
  978.  
  979. public void Event_BombPickup(Event event, const char[] name, bool dontBroadcast)
  980. {
  981.     if (enabled && removeObjectives)
  982.     {
  983.         int client = GetClientOfUserId(event.GetInt("userid"));
  984.         StripC4(client);
  985.     }
  986. }
  987.  
  988. bool StripC4(int client)
  989. {
  990.     if (IsClientInGame(client) && (GetClientTeam(client) == CS_TEAM_T) && IsPlayerAlive(client))
  991.     {
  992.         int c4Index = GetPlayerWeaponSlot(client, CS_SLOT_C4);
  993.         if (c4Index != -1)
  994.         {
  995.             char weapon[24];
  996.             GetClientWeapon(client, weapon, sizeof(weapon));
  997.             /* If the player is holding C4, switch to the best weapon before removing it. */
  998.             if (StrEqual(weapon, "weapon_c4"))
  999.             {
  1000.                 if (GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY) != -1)
  1001.                     ClientCommand(client, "slot1");
  1002.                 else if (GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY) != -1)
  1003.                     ClientCommand(client, "slot2");
  1004.                 else
  1005.                     ClientCommand(client, "slot3");
  1006.  
  1007.             }
  1008.             RemovePlayerItem(client, c4Index);
  1009.             AcceptEntityInput(c4Index, "Kill");
  1010.             return true;
  1011.         }
  1012.     }
  1013.     return false;
  1014. }
  1015.  
  1016. void EnableSpawnProtection(int client)
  1017. {
  1018.     int clientTeam = GetClientTeam(client);
  1019.     /* Disable damage */
  1020.     SetEntProp(client, Prop_Data, "m_takedamage", 0, 1);
  1021.     /* Set player color */
  1022.     if (clientTeam == CS_TEAM_T)
  1023.         SetPlayerColor(client, tColor);
  1024.     else if (clientTeam == CS_TEAM_CT)
  1025.         SetPlayerColor(client, ctColor);
  1026.     /* Create timer to remove spawn protection */
  1027.     CreateTimer(spawnProtectionTime, DisableSpawnProtection, client);
  1028. }
  1029.  
  1030. void RemoveHostages()
  1031. {
  1032.     int maxEntities = GetMaxEntities();
  1033.     char class[24];
  1034.  
  1035.     for (int i = MaxClients + 1; i < maxEntities; i++)
  1036.     {
  1037.         if (IsValidEdict(i))
  1038.         {
  1039.             GetEdictClassname(i, class, sizeof(class));
  1040.             if (StrEqual(class, "hostage_entity"))
  1041.                 AcceptEntityInput(i, "Kill");
  1042.         }
  1043.     }
  1044. }
  1045.  
  1046. void SetBuyZones(const char[] status)
  1047. {
  1048.     int maxEntities = GetMaxEntities();
  1049.     char class[24];
  1050.  
  1051.     for (int i = MaxClients + 1; i < maxEntities; i++)
  1052.     {
  1053.         if (IsValidEdict(i))
  1054.         {
  1055.             GetEdictClassname(i, class, sizeof(class));
  1056.             if (StrEqual(class, "func_buyzone"))
  1057.                 AcceptEntityInput(i, status);
  1058.         }
  1059.     }
  1060. }
  1061.  
  1062. void LoadConfig()
  1063. {
  1064.     Handle keyValues = CreateKeyValues("Deathmatch Config");
  1065.     char path[PLATFORM_MAX_PATH];
  1066.     BuildPath(Path_SM, path, sizeof(path), "configs/sdm/sdm.ini");
  1067.  
  1068.     if (!FileToKeyValues(keyValues, path))
  1069.         SetFailState("The configuration file could not be read.");
  1070.  
  1071.     char key[25];
  1072.     char value[25];
  1073.  
  1074.     if (!KvJumpToKey(keyValues, "Options"))
  1075.         SetFailState("The configuration file is corrupt (\"Options\" section could not be found).");
  1076.  
  1077.     KvGetString(keyValues, "dm_enabled", value, sizeof(value), "yes");
  1078.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1079.     SetConVarString(cvar_dm_enabled, value);
  1080.  
  1081.     KvGetString(keyValues, "dm_enable_valve_deathmatch", value, sizeof(value), "no");
  1082.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1083.     SetConVarString(cvar_dm_valvedm, value);
  1084.  
  1085.     KvGetString(keyValues, "dm_welcomemsg", value, sizeof(value), "yes");
  1086.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1087.     SetConVarString(cvar_dm_welcomemsg, value);
  1088.  
  1089.     KvGetString(keyValues, "dm_free_for_all", value, sizeof(value), "no");
  1090.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1091.     SetConVarString(cvar_dm_free_for_all, value);
  1092.  
  1093.     KvGetString(keyValues, "dm_hide_radar", value, sizeof(value), "no");
  1094.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1095.     SetConVarString(cvar_dm_hide_radar, value);
  1096.  
  1097.     KvGetString(keyValues, "dm_display_panel", value, sizeof(value), "no");
  1098.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1099.     SetConVarString(cvar_dm_display_panel, value);
  1100.  
  1101.     KvGetString(keyValues, "dm_display_panel_damage", value, sizeof(value), "no");
  1102.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1103.     SetConVarString(cvar_dm_display_panel_damage, value);
  1104.  
  1105.     KvGetString(keyValues, "dm_sounds_bodyshots", value, sizeof(value), "no");
  1106.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1107.     SetConVarString(cvar_dm_sounds_bodyshots, value);
  1108.  
  1109.     KvGetString(keyValues, "dm_sounds_headshots", value, sizeof(value), "no");
  1110.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1111.     SetConVarString(cvar_dm_sounds_headshots, value);
  1112.  
  1113.     KvGetString(keyValues, "dm_headshot_only", value, sizeof(value), "no");
  1114.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1115.     SetConVarString(cvar_dm_headshot_only, value);
  1116.  
  1117.     KvGetString(keyValues, "dm_headshot_only_allow_world", value, sizeof(value), "no");
  1118.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1119.     SetConVarString(cvar_dm_headshot_only_allow_world, value);
  1120.  
  1121.     KvGetString(keyValues, "dm_headshot_only_allow_knife", value, sizeof(value), "no");
  1122.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1123.     SetConVarString(cvar_dm_headshot_only_allow_knife, value);
  1124.  
  1125.     KvGetString(keyValues, "dm_headshot_only_allow_taser", value, sizeof(value), "no");
  1126.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1127.     SetConVarString(cvar_dm_headshot_only_allow_taser, value);
  1128.  
  1129.     KvGetString(keyValues, "dm_headshot_only_allow_nade", value, sizeof(value), "no");
  1130.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1131.     SetConVarString(cvar_dm_headshot_only_allow_nade, value);
  1132.  
  1133.     KvGetString(keyValues, "dm_remove_objectives", value, sizeof(value), "yes");
  1134.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1135.     SetConVarString(cvar_dm_remove_objectives, value);
  1136.  
  1137.     KvGetString(keyValues, "dm_respawning", value, sizeof(value), "yes");
  1138.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1139.     SetConVarString(cvar_dm_respawning, value);
  1140.  
  1141.     KvGetString(keyValues, "dm_respawn_time", value, sizeof(value), "2.0");
  1142.     SetConVarString(cvar_dm_respawn_time, value);
  1143.  
  1144.     KvGetString(keyValues, "dm_gun_menu_mode", value, sizeof(value), "1");
  1145.     SetConVarString(cvar_dm_gun_menu_mode, value);
  1146.  
  1147.     KvGetString(keyValues, "dm_line_of_sight_spawning", value, sizeof(value), "yes");
  1148.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1149.     SetConVarString(cvar_dm_los_spawning, value);
  1150.  
  1151.     KvGetString(keyValues, "dm_line_of_sight_attempts", value, sizeof(value), "10");
  1152.     SetConVarString(cvar_dm_los_attempts, value);
  1153.  
  1154.     KvGetString(keyValues, "dm_spawn_distance_from_enemies", value, sizeof(value), "0.0");
  1155.     SetConVarString(cvar_dm_spawn_distance, value);
  1156.  
  1157.     KvGetString(keyValues, "dm_spawn_protection_time", value, sizeof(value), "1.0");
  1158.     SetConVarString(cvar_dm_spawn_time, value);
  1159.  
  1160.     KvGetString(keyValues, "dm_no_knife_damage", value, sizeof(value), "no");
  1161.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1162.     SetConVarString(cvar_dm_no_knife_damage, value);
  1163.  
  1164.     KvGetString(keyValues, "dm_remove_weapons", value, sizeof(value), "yes");
  1165.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1166.     SetConVarString(cvar_dm_remove_weapons, value);
  1167.  
  1168.     KvGetString(keyValues, "dm_replenish_ammo", value, sizeof(value), "yes");
  1169.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1170.     SetConVarString(cvar_dm_replenish_ammo, value);
  1171.  
  1172.     KvGetString(keyValues, "dm_replenish_clip", value, sizeof(value), "no");
  1173.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1174.     SetConVarString(cvar_dm_replenish_clip, value);
  1175.  
  1176.     KvGetString(keyValues, "dm_replenish_reserve", value, sizeof(value), "no");
  1177.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1178.     SetConVarString(cvar_dm_replenish_reserve, value);
  1179.  
  1180.     KvGetString(keyValues, "dm_replenish_grenade", value, sizeof(value), "no");
  1181.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1182.     SetConVarString(cvar_dm_replenish_grenade, value);
  1183.  
  1184.     KvGetString(keyValues, "dm_replenish_hegrenade", value, sizeof(value), "no");
  1185.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1186.     SetConVarString(cvar_dm_replenish_hegrenade, value);
  1187.  
  1188.     KvGetString(keyValues, "dm_replenish_grenade_kill", value, sizeof(value), "no");
  1189.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1190.     SetConVarString(cvar_dm_replenish_grenade_kill, value);
  1191.  
  1192.     KvGetString(keyValues, "dm_display_grenade_messages", value, sizeof(value), "yes");
  1193.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1194.     SetConVarString(cvar_dm_nade_messages, value);
  1195.  
  1196.     KvGetString(keyValues, "dm_player_hp_start", value, sizeof(value), "100");
  1197.     SetConVarString(cvar_dm_hp_start, value);
  1198.  
  1199.     KvGetString(keyValues, "dm_player_hp_max", value, sizeof(value), "100");
  1200.     SetConVarString(cvar_dm_hp_max, value);
  1201.  
  1202.     KvGetString(keyValues, "dm_hp_per_kill", value, sizeof(value), "5");
  1203.     SetConVarString(cvar_dm_hp_kill, value);
  1204.  
  1205.     KvGetString(keyValues, "dm_hp_per_headshot_kill", value, sizeof(value), "10");
  1206.     SetConVarString(cvar_dm_hp_hs, value);
  1207.  
  1208.     KvGetString(keyValues, "dm_hp_per_knife_kill", value, sizeof(value), "50");
  1209.     SetConVarString(cvar_dm_hp_knife, value);
  1210.  
  1211.     KvGetString(keyValues, "dm_hp_per_nade_kill", value, sizeof(value), "30");
  1212.     SetConVarString(cvar_dm_hp_nade, value);
  1213.  
  1214.     KvGetString(keyValues, "dm_display_hp_messages", value, sizeof(value), "yes");
  1215.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1216.     SetConVarString(cvar_dm_hp_messages, value);
  1217.  
  1218.     KvGetString(keyValues, "dm_player_ap_max", value, sizeof(value), "100");
  1219.     SetConVarString(cvar_dm_ap_max, value);
  1220.  
  1221.     KvGetString(keyValues, "dm_ap_per_kill", value, sizeof(value), "5");
  1222.     SetConVarString(cvar_dm_ap_kill, value);
  1223.  
  1224.     KvGetString(keyValues, "dm_ap_per_headshot_kill", value, sizeof(value), "10");
  1225.     SetConVarString(cvar_dm_ap_hs, value);
  1226.  
  1227.     KvGetString(keyValues, "dm_ap_per_knife_kill", value, sizeof(value), "50");
  1228.     SetConVarString(cvar_dm_ap_knife, value);
  1229.  
  1230.     KvGetString(keyValues, "dm_ap_per_nade_kill", value, sizeof(value), "30");
  1231.     SetConVarString(cvar_dm_ap_nade, value);
  1232.  
  1233.     KvGetString(keyValues, "dm_display_ap_messages", value, sizeof(value), "yes");
  1234.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1235.     SetConVarString(cvar_dm_ap_messages, value);
  1236.  
  1237.     KvGoBack(keyValues);
  1238.  
  1239.     /*if (!KvJumpToKey(keyValues, "Weapons"))
  1240.         SetFailState("The configuration file is corrupt (\"Weapons\" section could not be found).");
  1241.  
  1242.     if (!KvJumpToKey(keyValues, "Primary"))
  1243.         SetFailState("The configuration file is corrupt (\"Primary\" section could not be found).");
  1244.  
  1245.     if (KvGotoFirstSubKey(keyValues, false))
  1246.     {
  1247.         do {
  1248.             KvGetSectionName(keyValues, key, sizeof(key));
  1249.             int limit = KvGetNum(keyValues, NULL_STRING, -1);
  1250.             if(limit == 0) {continue;}
  1251.             PushArrayString(primaryWeaponsAvailable, key);
  1252.             SetTrieValue(weaponLimits, key, limit);
  1253.         } while (KvGotoNextKey(keyValues, false));
  1254.     }
  1255.  
  1256.     KvGoBack(keyValues);
  1257.     KvGoBack(keyValues);
  1258.  
  1259.     if (!KvJumpToKey(keyValues, "Secondary"))
  1260.         SetFailState("The configuration file is corrupt (\"Secondary\" section could not be found).");
  1261.  
  1262.     if (KvGotoFirstSubKey(keyValues, false))
  1263.     {
  1264.         do {
  1265.             KvGetSectionName(keyValues, key, sizeof(key));
  1266.             int limit = KvGetNum(keyValues, NULL_STRING, -1);
  1267.             if(limit == 0) {continue;}
  1268.             PushArrayString(secondaryWeaponsAvailable, key);
  1269.             SetTrieValue(weaponLimits, key, limit);
  1270.         } while (KvGotoNextKey(keyValues, false));
  1271.     }
  1272.  
  1273.     KvGoBack(keyValues);
  1274.     KvGoBack(keyValues);
  1275.  
  1276.     if (!KvJumpToKey(keyValues, "Misc"))
  1277.         SetFailState("The configuration file is corrupt (\"Misc\" section could not be found).");
  1278.  
  1279.     KvGetString(keyValues, "armor (chest)", value, sizeof(value), "no");
  1280.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1281.     SetConVarString(cvar_dm_armor, value);
  1282.  
  1283.     KvGetString(keyValues, "armor (full)", value, sizeof(value), "yes");
  1284.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1285.     SetConVarString(cvar_dm_armor_full, value);
  1286.  
  1287.     KvGetString(keyValues, "zeus", value, sizeof(value), "no");
  1288.     value = (StrEqual(value, "yes")) ? "1" : "0";
  1289.     SetConVarString(cvar_dm_zeus, value);
  1290.  
  1291.     KvGoBack(keyValues);
  1292.  
  1293.     if (!KvJumpToKey(keyValues, "Grenades"))
  1294.         SetFailState("The configuration file is corrupt (\"Grenades\" section could not be found).");
  1295.  
  1296.     KvGetString(keyValues, "incendiary", value, sizeof(value), "0");
  1297.     SetConVarString(cvar_dm_nades_incendiary, value);
  1298.  
  1299.     KvGetString(keyValues, "molotov", value, sizeof(value), "0");
  1300.     SetConVarString(cvar_dm_nades_incendiary, value);
  1301.  
  1302.     KvGetString(keyValues, "decoy", value, sizeof(value), "0");
  1303.     SetConVarString(cvar_dm_nades_decoy, value);
  1304.  
  1305.     KvGetString(keyValues, "flashbang", value, sizeof(value), "0");
  1306.     SetConVarString(cvar_dm_nades_flashbang, value);
  1307.  
  1308.     KvGetString(keyValues, "he", value, sizeof(value), "0");
  1309.     SetConVarString(cvar_dm_nades_he, value);
  1310.  
  1311.     KvGetString(keyValues, "smoke", value, sizeof(value), "0");
  1312.     SetConVarString(cvar_dm_nades_smoke, value);
  1313.  
  1314.     KvGoBack(keyValues);*/
  1315.  
  1316. /*  if (KvJumpToKey(keyValues, "TeamData") && KvGotoFirstSubKey(keyValues, false)) {
  1317.         do {
  1318.             KvGetSectionName(keyValues, key, sizeof(key));
  1319.             KvGetString(keyValues, NULL_STRING, value, sizeof(value), "");
  1320.             int team = 0;
  1321.             if (StrEqual(value, "CT", false))
  1322.             {
  1323.                 team = CS_TEAM_CT;
  1324.             }
  1325.             else if (StrEqual(value, "T", false))
  1326.             {
  1327.                 team = CS_TEAM_T;
  1328.             }
  1329.             weaponSkipMap.SetValue(key, team);
  1330.         } while (KvGotoNextKey(keyValues, false));
  1331.         KvGoBack(keyValues);
  1332.     }*/
  1333.  
  1334.     CloseHandle(keyValues);
  1335. }
  1336.  
  1337. void UpdateState()
  1338. {
  1339.     int old_enabled = enabled;
  1340.  
  1341.     enabled = GetConVarBool(cvar_dm_enabled);
  1342.     valveDM = GetConVarBool(cvar_dm_valvedm);
  1343.     welcomemsg = GetConVarBool(cvar_dm_welcomemsg);
  1344.     ffa = GetConVarBool(cvar_dm_free_for_all);
  1345.     hideradar = GetConVarBool(cvar_dm_hide_radar);
  1346.     displayPanel = GetConVarBool(cvar_dm_display_panel);
  1347.     displayPanelDamage = GetConVarBool(cvar_dm_display_panel_damage);
  1348.     bdSounds = GetConVarBool(cvar_dm_sounds_bodyshots);
  1349.     hsSounds = GetConVarBool(cvar_dm_sounds_headshots);
  1350.     hsOnly = GetConVarBool(cvar_dm_headshot_only);
  1351.     hsOnly_AllowWorld = GetConVarBool(cvar_dm_headshot_only_allow_world);
  1352.     hsOnly_AllowKnife = GetConVarBool(cvar_dm_headshot_only_allow_knife);
  1353.     hsOnly_AllowTaser = GetConVarBool(cvar_dm_headshot_only_allow_taser);
  1354.     hsOnly_AllowNade = GetConVarBool(cvar_dm_headshot_only_allow_nade);
  1355.     removeObjectives = GetConVarBool(cvar_dm_remove_objectives);
  1356.     respawning = GetConVarBool(cvar_dm_respawning);
  1357.     respawnTime = GetConVarFloat(cvar_dm_respawn_time);
  1358.     //gunMenuMode = GetConVarInt(cvar_dm_gun_menu_mode);
  1359.     lineOfSightSpawning = GetConVarBool(cvar_dm_los_spawning);
  1360.     lineOfSightAttempts = GetConVarInt(cvar_dm_los_attempts);
  1361.     spawnDistanceFromEnemies = GetConVarFloat(cvar_dm_spawn_distance);
  1362.     spawnProtectionTime = GetConVarFloat(cvar_dm_spawn_time);
  1363.     removeWeapons = GetConVarBool(cvar_dm_remove_weapons);
  1364.     //replenishReserve = GetConVarBool(cvar_dm_replenish_reserve);
  1365.     startHP = GetConVarInt(cvar_dm_hp_start);
  1366.     maxHP = GetConVarInt(cvar_dm_hp_max);
  1367.     //displayHPMessages = GetConVarBool(cvar_dm_hp_messages);
  1368.     //maxAP = GetConVarInt(cvar_dm_ap_max);
  1369.     //displayAPMessages = GetConVarBool(cvar_dm_ap_messages);
  1370.     //displayGrenadeMessages = GetConVarBool(cvar_dm_nade_messages);
  1371.     //armorChest = GetConVarBool(cvar_dm_armor);
  1372.     //armorFull = GetConVarBool(cvar_dm_armor_full);
  1373.     //zeus = GetConVarBool(cvar_dm_zeus);
  1374.     //incendiary = GetConVarInt(cvar_dm_nades_incendiary);
  1375.  
  1376.     if (respawnTime < 0.0) respawnTime = 0.0;
  1377.     //if (gunMenuMode < 1) gunMenuMode = 1;
  1378.     //if (gunMenuMode > 5) gunMenuMode = 5;
  1379.     //if (lineOfSightAttempts < 0) lineOfSightAttempts = 0;
  1380.     //if (spawnDistanceFromEnemies < 0.0) spawnDistanceFromEnemies = 0.0;
  1381.     //if (spawnProtectionTime < 0.0) spawnProtectionTime = 0.0;
  1382.     if (startHP < 1) startHP = 1;
  1383.     if (maxHP < 1) maxHP = 1;
  1384.     if (HPPerKill < 0) HPPerKill = 0;
  1385.     if (HPPerHeadshotKill < 0) HPPerHeadshotKill = 0;
  1386.     if (HPPerKnifeKill < 0) HPPerKnifeKill = 0;
  1387.     if (HPPerNadeKill < 0) HPPerNadeKill = 0;
  1388.     //if (maxAP < 0) maxAP = 0;
  1389.     //if (APPerKill < 0) APPerKill = 0;
  1390.     //if (APPerHeadshotKill < 0) APPerHeadshotKill = 0;
  1391.     //if (APPerKnifeKill < 0) APPerKnifeKill = 0;
  1392.     //if (APPerNadeKill < 0) APPerNadeKill = 0;
  1393.     //if (incendiary < 0) incendiary = 0;
  1394.     /*if (molotov < 0) molotov = 0;
  1395.     if (decoy < 0) decoy = 0;
  1396.     if (flashbang < 0) flashbang = 0;
  1397.     if (he < 0) he = 0;
  1398.     if (smoke < 0) smoke = 0;*/
  1399.  
  1400.     if (enabled && !old_enabled)
  1401.     {
  1402.         /*for (int i = 1; i <= MaxClients; i++)
  1403.         {
  1404.             if (IsClientConnected(i))
  1405.                 ResetClientSettings(i);
  1406.         }*/
  1407.         RespawnAll();
  1408.         SetBuyZones("Disable");
  1409.         char status[10];
  1410.         status = (removeObjectives) ? "Disable" : "Enable";
  1411.         SetObjectives(status);
  1412.         //SetCashState();
  1413.         SetNoSpawnWeapons();
  1414.     }
  1415.     else if (!enabled && old_enabled)
  1416.     {
  1417.         /*for (int i = 1; i <= MaxClients; i++)
  1418.             DisableSpawnProtection(INVALID_HANDLE, i);
  1419.         CancelMenu(optionsMenu1);
  1420.         CancelMenu(optionsMenu2);
  1421.         for (int i = 1; i <= MaxClients; i++)
  1422.         {
  1423.             if (primaryMenus[i] != INVALID_HANDLE)
  1424.                 CancelMenu(primaryMenus[i]);
  1425.         }
  1426.         for (int i = 1; i <= MaxClients; i++)
  1427.         {
  1428.             if (secondaryMenus[i] != INVALID_HANDLE)
  1429.                 CancelMenu(secondaryMenus[i]);
  1430.         }*/
  1431.         SetBuyZones("Enable");
  1432.         SetObjectives("Enable");
  1433.         //RestoreCashState();
  1434.         //RestoreGrenadeState();
  1435.     }
  1436.  
  1437.     if (enabled)
  1438.     {
  1439.         /*if (gunMenuMode != old_gunMenuMode)
  1440.         {
  1441.             if (gunMenuMode == 5)
  1442.             {
  1443.                 for (int i = 1; i <= MaxClients; i++)
  1444.                     CancelClientMenu(i);
  1445.             }
  1446.             /* Only if the plugin was enabled before the state update do we need to update the client's gun mode settings. If it was disabled before, then */
  1447.             /* the entire client settings (including gun mode settings) are reset above. */
  1448.             /*if (old_enabled)
  1449.             {
  1450.                 for (int i = 1; i <= MaxClients; i++)
  1451.                 {
  1452.                     if (IsClientConnected(i))
  1453.                         SetClientGunModeSettings(i);
  1454.                 }
  1455.             }
  1456.         }*/
  1457.         if (removeObjectives)
  1458.             RemoveC4();
  1459.         //SetGrenadeState();
  1460.         if (ffa)
  1461.             EnableFFA();
  1462.         //else
  1463.             //DisableFFA();
  1464.     }
  1465. }
  1466.  
  1467. /* Updates the occupation status of all spawn points. */
  1468. public Action UpdateSpawnPointStatus(Handle timer)
  1469. {
  1470.     if (enabled && (spawnPointCount > 0))
  1471.     {
  1472.         /* Retrieve player positions. */
  1473.         float playerPositions[MAXPLAYERS+1][3];
  1474.         int numberOfAlivePlayers = 0;
  1475.  
  1476.         for (int i = 1; i <= MaxClients; i++)
  1477.         {
  1478.             if (IsClientInGame(i) && (GetClientTeam(i) != CS_TEAM_SPECTATOR) && IsPlayerAlive(i))
  1479.             {
  1480.                 GetClientAbsOrigin(i, playerPositions[numberOfAlivePlayers]);
  1481.                 numberOfAlivePlayers++;
  1482.             }
  1483.         }
  1484.  
  1485.         /* Check each spawn point for occupation by proximity to alive players */
  1486.         for (int i = 0; i < spawnPointCount; i++)
  1487.         {
  1488.             spawnPointOccupied[i] = false;
  1489.             for (int j = 0; j < numberOfAlivePlayers; j++)
  1490.             {
  1491.                 float distance = GetVectorDistance(spawnPositions[i], playerPositions[j], true);
  1492.                 if (distance < 10000.0)
  1493.                 {
  1494.                     spawnPointOccupied[i] = true;
  1495.                     break;
  1496.                 }
  1497.             }
  1498.         }
  1499.     }
  1500.     return Plugin_Continue;
  1501. }
  1502.  
  1503. public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
  1504. {
  1505.     if (enabled)
  1506.     {
  1507.         if (removeObjectives)
  1508.             RemoveHostages();
  1509.         //if (removeWeapons)
  1510.         //  RemoveGroundWeapons(INVALID_HANDLE);
  1511.     }
  1512. }
  1513.  
  1514. public Action Event_Sound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &entity, int &channel, float &volume, int &level, int &pitch, int &flags)
  1515. {
  1516.     if (enabled)
  1517.     {
  1518.         if (spawnPointCount > 0)
  1519.         {
  1520.             int client;
  1521.             if ((entity > 0) && (entity <= MaxClients))
  1522.                 client = entity;
  1523.             //else
  1524.                 //client = GetEntDataEnt2(entity, ownerOffset);
  1525.  
  1526.             /* Block ammo pickup sounds. */
  1527.             if (StrContains(sample, "pickup") != -1)
  1528.                 return Plugin_Stop;
  1529.  
  1530.             /* Block all sounds originating from players not yet moved. */
  1531.             if ((client > 0) && (client <= MaxClients) && !playerMoved[client])
  1532.                 return Plugin_Stop;
  1533.         }
  1534.         if (ffa)
  1535.         {
  1536.             if (StrContains(sample, "friendlyfire") != -1)
  1537.                 return Plugin_Stop;
  1538.         }
  1539.         if (!hsSounds)
  1540.         {
  1541.             if (StrContains(sample, "physics/flesh/flesh_bloody") != -1 || StrContains(sample, "player/bhit_helmet") != -1 || StrContains(sample, "player/headshot") != -1)
  1542.                 return Plugin_Stop;
  1543.         }
  1544.         if (!bdSounds)
  1545.         {
  1546.             if (StrContains(sample, "physics/body") != -1 || StrContains(sample, "physics/flesh") != -1 || StrContains(sample, "player/kevlar") != -1)
  1547.                 return Plugin_Stop;
  1548.         }
  1549.     }
  1550.     return Plugin_Continue;
  1551. }
  1552.  
  1553. void RespawnAll()
  1554. {
  1555.     for (int i = 1; i <= MaxClients; i++)
  1556.         Respawn(INVALID_HANDLE, i);
  1557. }
  1558.  
  1559. void SetObjectives(const char[] status)
  1560. {
  1561.     int maxEntities = GetMaxEntities();
  1562.     char class[24];
  1563.  
  1564.     for (int i = MaxClients + 1; i < maxEntities; i++)
  1565.     {
  1566.         if (IsValidEdict(i))
  1567.         {
  1568.             GetEdictClassname(i, class, sizeof(class));
  1569.             if (StrEqual(class, "func_bomb_target") || StrEqual(class, "func_hostage_rescue"))
  1570.                 AcceptEntityInput(i, status);
  1571.         }
  1572.     }
  1573. }
  1574.  
  1575. void SetNoSpawnWeapons()
  1576. {
  1577.     SetConVarString(mp_ct_default_primary, "");
  1578.     SetConVarString(mp_t_default_primary, "");
  1579.     SetConVarString(mp_ct_default_secondary, "weapon_glock");
  1580.     SetConVarString(mp_t_default_secondary, "weapon_glock");
  1581.     SetConVarString(mp_t_default_melee, "");
  1582.     SetConVarString(mp_t_default_melee, "");
  1583. }
  1584.  
  1585. void RemoveC4()
  1586. {
  1587.     for (int i = 1; i <= MaxClients; i++)
  1588.     {
  1589.         if (StripC4(i))
  1590.             break;
  1591.     }
  1592. }
  1593.  
  1594. void CreateWeapon(int i)
  1595. {
  1596.     new index;
  1597.     char buffer[64];
  1598.     weapons.GetString(i,buffer,sizeof(buffer));
  1599.     TrimString(buffer);
  1600.     index=CreateEntityByName(buffer);
  1601.         if (index < 1)
  1602.         {
  1603.             LogError("Error during creating '%s'",buffer);
  1604.             return;
  1605.         }
  1606.      SetEntProp(index, Prop_Send, "m_iItemDefinitionIndex", GetWeaponIndex(i));
  1607.      DispatchKeyValueVector(index, "origin", spawnWeaponPositions[i]);
  1608.      //DispatchKeyValue(index, "ammo", "90");
  1609.      DispatchKeyValue(index, "spawnflags", "1");     
  1610.      DispatchSpawn(index);
  1611.      //SetEntProp(index, Prop_Send, "m_iPrimaryReserveAmmoCount", 90);
  1612.      //SetEntData(index, FindSendPropInfo("CBaseCombatWeapon", "m_iClip1"), 90);
  1613.      //DispatchKeyValue(index, "ammo", "90");
  1614.      
  1615.      SetPrimaryAmmo(index, 90);
  1616.     // SetWeaponAmmo(GetWeaponAmmoOffset(buffer), 90);
  1617.      
  1618.      SetSkin(index);
  1619. }
  1620.  
  1621. void SpawnWeapons()
  1622. {
  1623.    
  1624.     for(int i=0;i<spawnWeaponPointCount;i++)
  1625.     {
  1626.         CreateWeapon(i);
  1627.     }
  1628. }
  1629.  
  1630. int GetWeaponIndex(int i)
  1631. {
  1632.     int result;
  1633.     char buffer[64];
  1634.     weapons.GetString(i,buffer,sizeof(buffer));
  1635.     TrimString(buffer);
  1636.     if (StrEqual(buffer, "weapon_deagle"))
  1637.       result=1;
  1638.     else if (StrEqual(buffer, "weapon_elite"))
  1639.       result=2;
  1640.     else if (StrEqual(buffer, "weapon_fiveseven"))
  1641.       result=3;
  1642.     else if (StrEqual(buffer, "weapon_glock"))
  1643.       result=4;
  1644.     else if (StrEqual(buffer, "weapon_ak47"))
  1645.       result=7;
  1646.     else if (StrEqual(buffer, "weapon_aug"))
  1647.       result=8;
  1648.     else if (StrEqual(buffer, "weapon_awp"))
  1649.       result=9;
  1650.     else if (StrEqual(buffer, "weapon_famas"))
  1651.       result=10;
  1652.     else if (StrEqual(buffer, "weapon_g3sg1"))
  1653.       result=11;
  1654.     else if (StrEqual(buffer, "weapon_galil"))
  1655.       result=13;
  1656.     else if (StrEqual(buffer, "weapon_m249"))
  1657.       result=14;
  1658.     else if (StrEqual(buffer, "weapon_m4a1"))
  1659.       result=16;
  1660.     else if (StrEqual(buffer, "weapon_mac10"))
  1661.       result=17;
  1662.     else if (StrEqual(buffer, "weapon_p90"))
  1663.       result=19;
  1664.     else if (StrEqual(buffer, "weapon_ump45"))
  1665.       result=24;
  1666.     else if (StrEqual(buffer, "weapon_xm1014"))
  1667.       result=25;
  1668.     else if (StrEqual(buffer, "weapon_bizon"))
  1669.       result=26;
  1670.     else if (StrEqual(buffer, "weapon_mag7"))
  1671.       result=27;
  1672.     else if (StrEqual(buffer, "weapon_negev"))
  1673.       result=28;
  1674.     else if (StrEqual(buffer, "weapon_sawedoff"))
  1675.       result=29;
  1676.     else if (StrEqual(buffer, "weapon_tec9"))
  1677.       result=30;
  1678.     else if (StrEqual(buffer, "weapon_p2000"))
  1679.       result=32;
  1680.     else if (StrEqual(buffer, "weapon_mp7"))
  1681.       result=33;
  1682.     else if (StrEqual(buffer, "weapon_mp9"))
  1683.       result=34;
  1684.     else if (StrEqual(buffer, "weapon_nova"))
  1685.       result=35;
  1686.     else if (StrEqual(buffer, "weapon_p250"))
  1687.       result=36;
  1688.     else if (StrEqual(buffer, "weapon_scar20"))
  1689.       result=38;
  1690.     else if (StrEqual(buffer, "weapon_sg556"))
  1691.       result=39;
  1692.     else if (StrEqual(buffer, "weapon_ssg08"))
  1693.       result=40;
  1694.  
  1695. return result;
  1696.    
  1697. }
  1698.  
  1699.  
  1700.  
  1701. public Action:Timer_check(Handle:timer, any:client)
  1702. {
  1703.      PrintToChatAll("Check1");
  1704.     if(IsClientInGame(client))
  1705.     {
  1706.         if(GetClientCount(true) == GetMaxHumanPlayers())
  1707.         {
  1708.             SetConVarFloat(mp_warmup, 5.0);
  1709.             KillTimer(g_timer);
  1710.              PrintToChatAll("Check2");
  1711.         }
  1712.     }
  1713.     else if(!IsClientConnected(client))
  1714.     {
  1715.         KillTimer(g_timer);
  1716.     }
  1717. }
  1718.  
  1719. void SetSkin(int entity)
  1720. {
  1721.     SetEntProp(entity,Prop_Send,"m_iItemIDLow",-1);
  1722.     SetEntProp(entity,Prop_Send,"m_nFallbackPaintKit",217);
  1723.     SetEntPropFloat(entity,Prop_Send,"m_flFallbackWear",0.1);
  1724. // if(g_paints[theindex][pattern] >= 0)
  1725.     //SetEntProp(entity,Prop_Send,"m_nFallbackSeed",g_paints[theindex][pattern]);
  1726.     SetEntProp(entity,Prop_Send,"m_nFallbackStatTrak", 1337);
  1727. // if(g_paints[theindex][quality] != -2)
  1728.     //SetEntProp(entity,Prop_Send,"m_iEntityQuality",g_paints[theindex][quality]);
  1729. }
  1730.  
  1731.  
  1732. OnButtonPress(client, button)
  1733. {
  1734.     // do stuff
  1735. }
  1736.  
  1737. OnButtonRelease(client, button)
  1738. {
  1739.     // do stuff
  1740. }
  1741.  
  1742. stock SetPrimaryAmmo(weap, ammo)
  1743. {    
  1744.     //new myweapons = FindSendPropInfo("CCSPlayer", "m_hMyWeapons");  
  1745.     //new weap = GetEntDataEnt2(client, myweapons+ (slot*4));
  1746.     if(IsValidEntity(weap))
  1747.         return SetEntData(weap, FindSendPropInfo("CBaseCombatWeapon", "m_iClip1"), ammo);
  1748.     return 0;
  1749. }
  1750.  
  1751. /*stock SetWeaponAmmo(slot, ammo)
  1752. {
  1753.     new ammoOffset = FindSendPropInfo("CCSPlayer", "m_iAmmo");
  1754.     return SetEntData(client, ammoOffset+(slot*4), ammo);
  1755. }*/
  1756.  
  1757. public GetWeaponAmmoOffset(String:Weapon[])
  1758. {
  1759.     if(StrEqual(Weapon, "weapon_deagle", false))
  1760.     {
  1761.         return 1;
  1762.     }
  1763.     else if(StrEqual(Weapon, "weapon_ak47", false) || StrEqual(Weapon, "weapon_aug", false) || StrEqual(Weapon, "weapon_g3sg1", false) || StrEqual(Weapon, "weapon_scout", false))
  1764.     {
  1765.         return 2;
  1766.     }
  1767.     else if(StrEqual(Weapon, "weapon_famas", false) || StrEqual(Weapon, "weapon_galil", false) || StrEqual(Weapon, "weapon_m4a1", false) || StrEqual(Weapon, "weapon_sg550", false) || StrEqual(Weapon, "weapon_sg552", false))
  1768.     {
  1769.         return 3;
  1770.     }
  1771.     else if(StrEqual(Weapon, "weapon_m249", false))
  1772.     {
  1773.         return 4;
  1774.     }
  1775.     else if(StrEqual(Weapon, "weapon_awp", false))
  1776.     {
  1777.         return 5;
  1778.     }
  1779.     else if(StrEqual(Weapon, "weapon_elite", false) || StrEqual(Weapon, "weapon_glock", false) || StrEqual(Weapon, "weapon_mp5navy", false) || StrEqual(Weapon, "weapon_tmp", false))
  1780.     {
  1781.         return 6;
  1782.     }
  1783.     else if(StrEqual(Weapon, "weapon_xm1014", false) || StrEqual(Weapon, "weapon_m3", false))
  1784.     {
  1785.         return 7;
  1786.     }
  1787.     else if(StrEqual(Weapon, "weapon_mac10", false) || StrEqual(Weapon, "weapon_ump45", false) || StrEqual(Weapon, "weapon_usp", false))
  1788.     {
  1789.         return 8;
  1790.     }
  1791.     else if(StrEqual(Weapon, "weapon_p228", false))
  1792.     {
  1793.         return 9;
  1794.     }
  1795.     else if(StrEqual(Weapon, "weapon_fiveseven", false) || StrEqual(Weapon, "weapon_p90", false))
  1796.     {
  1797.         return 10;
  1798.     }
  1799.     else if(StrEqual(Weapon, "weapon_hegrenade", false))
  1800.     {
  1801.         return 11;
  1802.     }
  1803.     else if(StrEqual(Weapon, "weapon_flashbang", false))
  1804.     {
  1805.         return 12;
  1806.     }
  1807.     else if(StrEqual(Weapon, "weapon_smokegrenade", false))
  1808.     {
  1809.         return 13;
  1810.     }
  1811.     return -1;
  1812. }
  1813.  
  1814. public Action WarmupCheck()
  1815. {
  1816.     if(!b_MaxClients)
  1817.     {
  1818.         if(i_PlayerCount == MAXPLAYERS)
  1819.         {
  1820.             ServerCommand("mp_warmuptime 0");
  1821.             ServerCommand("mp_restartgame 1");
  1822.             b_MaxClients = true;
  1823.         }
  1824.     }
  1825. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement