HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Title: Bad Camper
  3. Author: Brad Jones
  4.  
  5. Current Version: 1.4.239
  6. Release Date: 2008-JUL-21
  7.  
  8. This plugin will automatically punish players who camp for too long.
  9.  
  10. There can be a combination of punishments that get applied to the player. Punishments
  11. start when the player's camping meter reaches 80%. They get worse at 90%. They finally
  12. come to a crescendo at 100%.
  13.  
  14. This plugin to be the successor to the great AntiCamping Advanced plugin.
  15. http://amxmodx.org/forums/viewtopic.php?t=751
  16.  
  17. Original design inspiration, many concepts, and code came from "AntiCamping Advanced".
  18. http://amxmodx.org/forums/viewtopic.php?t=751
  19.  
  20.  
  21. INSTALLATION
  22.  
  23. File Locations:
  24.  
  25. .\gamemod\addons\amxmodx\plugins\bad_camper.amxx
  26.  
  27. Modules:
  28.  
  29. fun (required)
  30. cstrike (required only if utilizing money reduction punishment)
  31. csx (required if running Counter-Strike or Counter-Strike: Condition Zero)
  32. dodx (required if running DoD)
  33. tfcx (required if running TFC)
  34.  
  35.  
  36. OPTIONS (CVARs)
  37.  
  38. badcamper_punish <iFlags>
  39.  
  40. Specifies how a player is to be punished when they camp too long.
  41. A value of 0 will disable this plugin.
  42.  
  43. The flags are additive.
  44. 1: Slap
  45. 2: Health Reduction
  46. 4: Sound (set sound via "badcamper_sound" CVAR)
  47. 8: Blind
  48. 16: Money Reduction (requires CSTRIKE module)
  49. 32: Snark Attack (requires Monster Mod)
  50.  
  51. The default is 12 (snore and blind).
  52.  
  53. badcamper_sound <iFlag>
  54.  
  55. Specifies the sound to use as a punishment when the "badcamper_punish" flag includes
  56. the sound punishment.
  57.  
  58. 1: Snore
  59. 2: Heartbeat
  60.  
  61. The default is 1.
  62.  
  63. badcamper_money <iPercentage>
  64.  
  65. Specifies the percentage of money taken away when a player's meter reaches 100% when
  66. using the "money reduction" punishment.
  67.  
  68. The default is 10 percent.
  69.  
  70. badcamper_limit <iSeconds>
  71.  
  72. Specifies the number of seconds a player can camp in one spot before their
  73. camping meter will reach 100%.
  74.  
  75. The default is 35 seconds.
  76.  
  77. badcamper_display <iPercentage>
  78.  
  79. Specifies the percentage at which the meter is displayed to the player.
  80. Valid values range from 0 (never show) to 100.
  81.  
  82. The default is 1 percent.
  83.  
  84. badcamper_show_spec <0|1>
  85.  
  86. Specifies whether to allow spectators to see other player's meters.
  87.  
  88. The default is 1, to allow it.
  89.  
  90. badcamper_check_all <0|1>
  91.  
  92. Specifies whether only the team with the current primary objective should be
  93. checked for camping or if both teams should.
  94.  
  95. 0: only check the team with the current primary objective
  96. 1: always check both teams
  97.  
  98. The default is 1.
  99.  
  100. The current primary objective is defined as follows:
  101.  
  102. - if the map is not a "de" map, the CTs have the primary objective
  103. - if the map is a "de" map and the bomb hasn't been planted, the Ts have the primary objective
  104. - if the map is a "de" map and the bomb has been planted, the CTs have the primary objective
  105.  
  106. badcamper_immunity_flags <cAccessLevels>
  107.  
  108. Specifies the access level flags needed for a player to have immunity. Immunity is achieved by
  109. standing completely still and not looking around for approximately 6 seconds. The camp meter
  110. will still increase until it reaches 65% or more at which time it'll stop until they move or
  111. look around again. If the meter is already at 80% or higher, the meter won't stop.
  112.  
  113. Set this CVAR to blank to disallow immunity.
  114.  
  115. For available flags, http://wiki.amxmodx.org/index.php/Adding_Admins_%28AMX_Mod_X%29#Access_Levels
  116.  
  117. The default is blank (no immunity).
  118.  
  119. A common value, when admin immunity is desired, is to use the "a" flag (ADMIN_IMMUNITY).
  120.  
  121. badcamper_start <iSeconds>
  122.  
  123. Specifies how many seconds after the freeze time ends each round that the
  124. meter will start.
  125.  
  126. The default is 4 seconds.
  127.  
  128. Note that camping is checked every 2 seconds so any value you put in here will
  129. effectively be rounded as such.
  130.  
  131. badcamper_damage_reset <iResetType>
  132.  
  133. Specifies if the attacker's or defender's meter gets reset when the player is
  134. injured by another.
  135.  
  136. 0: No meters are reset.
  137. 1: The attacker's meter is reset.
  138. 2: The defender's meter is reset.
  139. 3: Both meters are reset.
  140.  
  141. The default is 3.
  142.  
  143. badcamper_damage_restart <iSeconds>
  144.  
  145. Specifies how many seconds after a player either gives or receives damage that the
  146. meter will restart.
  147.  
  148. The default is 4 seconds.
  149.  
  150. Note that camping is checked every 2 seconds so any value you put in here will
  151. effectively be rounded up as such.
  152.  
  153. badcamper_health <iHealthPoints>
  154.  
  155. Specifies how many points of health to remove from the player every 2 seconds
  156. once their meter reaches 100%.
  157.  
  158. The default is 10 health points.
  159.  
  160. badcamper_allow <iPlayerCount|iPlayerPercent%>
  161.  
  162. Specifies when a team that is being checked for camping is allowed to camp.
  163. A value of 0 doesn't allow a team to camp.
  164.  
  165. The default is 0.
  166.  
  167. The value can either be expressed as a straight count or as a percentage.
  168. If the value is being expressed as a percentage, "%" has to follow the value.
  169. Examples below. If the value is a count, players can camp when the number of
  170. living players on their team falls to this value or lower. If the value is a
  171. percentage, players can camp when the percentage of living players on their team
  172. is at this value or lower when compared to the living players on the other team.
  173.  
  174. Examples:
  175.  
  176. badcamper_allow 2
  177.  
  178. Pretty straight-forward. Once there are 2 or fewer players left alive on
  179. your team, you can camp.
  180.  
  181. badcamper_allow 40%
  182.  
  183. More powerful and complex. Once your team comprises of living players that
  184. is 40% or less than the number of living players on the other team, you can
  185. camp. For instance (assume your team is listed first) the following match-ups
  186. would allow your team to camp: 1v4, 2v5, 3v8, 4v12, 5v13, 6v15.
  187.  
  188. badcamper_min_players <players>
  189.  
  190. Specifies the minimum number of players that have to be connected to the server
  191. before players are allowed to camp.
  192.  
  193. The default is 0 players.
  194.  
  195. This CVAR affects both "badcamper_check_all" and "badcamper_allow" functionality.
  196.  
  197. badcamper_announce <announcementType>
  198.  
  199. Specifies how to announce to the opposite team that a player is camping.
  200.  
  201. 0: Make no announcement.
  202. 1: Announce via chat.
  203. 2: Announce via HUD.
  204. 3: Announce via chat and HUD.
  205.  
  206. The default is 3.
  207.  
  208.  
  209. COMMANDS
  210.  
  211. badcamper list
  212.  
  213. Lists the punishments in the console and indicates which of them are active.
  214.  
  215.  
  216. CHANGE LOG
  217.  
  218. 2008-JUL-21 1.4.239
  219.  
  220. ! Compatible with AMXX 1.80 or higher only.
  221. - Fixed issue where the spectator meter would display in the spectated player's language
  222. rather than the spectator's language.
  223.  
  224. 2007-AUG-04 1.4
  225.  
  226. - Added CVAR to aid in debugging; allows meter to run when only one person is on server.
  227. - Removed BugBlatter's "Monster Mod" support. Rationale being that players could crash
  228. your server by typing "meta list" in their console when using it.
  229. - All snarks are now killed at the end of each round, if using Snark punishment.
  230. - Fixed discrepancy between documentation and code. Changed "badcamper_announce" CVAR to
  231. default to 3, as per the documenation.
  232. - Fixed issue where HLTV was counting as a player, thus affecting when camping is checked.
  233. - The camp meter will now affect bots that camp.
  234. Oh, and if your bot camps, you need a new bot or better waypoint files.
  235. - Fixed discrepancy between documenation and code. Changed who can camp (based on
  236. objectives) when not on a map with a bomb site. Changed from everyone can to only Ts can.
  237.  
  238. 2007-APR-03 1.3b
  239.  
  240. - Fixed issue where screen would go sideways if health reduction punishment was used.
  241.  
  242. 2007-APR-02 1.3a
  243.  
  244. - Fixed dumb bug that kinda broke everything else.
  245. Note to self: Don't make changes right before releasing.
  246.  
  247. 2007-APR-02 1.3
  248.  
  249. ! Compatible with AMXX 1.71 or higher only.
  250. ! The 'csx', 'dodx', or 'tfcx' module has to be enabled, depending on what
  251. game mod you are running.
  252. - Added DoD (tested) and TFC (untested) mod support.
  253. - Made more code optimizations.
  254. - Defuser's meter will now be paused when bomb is being defused.
  255. - Planter's meter will be more accurately paused than in previous versions.
  256. Previous versions would pause the player's meter for the full time it would
  257. take to plant the bomb, even if they stopped planting in the meantime.
  258. - Altered method of specifying admin immunity from define to CVAR.
  259. - Replaced badcamper_immunity CVAR with badcamper_immunity_flags.
  260. - Fixed overlapping "so and so is now camping" messages.
  261. - Added option to allow spectators to see players' meters. Default is to show the meter.
  262. - Fixed meter not always obeying "based on objectives" team. (thanks sasdad and arkshine!)
  263. - Fixed issue with ATAC 3.x whereas the health reduction could cause a player to get TAs.
  264.  
  265. 2006-MAR-12 1.2
  266.  
  267. ! Compatible with AMXX 1.70 or higher only.
  268. ! The 'fakemeta' module needs to be enabled.
  269. - Fixed issue where round end cleanup would not be performed if the round
  270. was restarted as opposed to ending normally.
  271. - Fixed "index out of bounds" error.
  272. - Auto-detects if you're using the supplied "Monster" metamod. If you are using
  273. a different version of "Monster", reverts to less fine control over snarks.
  274. - Removed need to recompile if using this plugin in a game mod other than
  275. Counter-Strike.
  276. - Removed need to recompile if using the "Snark Attack" punishment. Now, if you
  277. indicate to use "snark attack" as a punishment, but you don't have "Monster"
  278. installed, you'll get errors in your log files.
  279. - Disabled meter when there is only one person on the server. This is useful
  280. for when you want to sit on your server while waiting for others to join.
  281. - Implemented more accurate way of detecting if the map was a bomb map.
  282. - Optimized the code to use less CPU usage.
  283.  
  284. 2005-DEC-10 1.1
  285.  
  286. - Added "Snark attack" punishment. Requires "Monster Mod" to be installed.
  287. - Changed "Slap" punishment to increase in power as the meter gets higher.
  288. Note that when slapped, the player may actually get slapped far enough
  289. that it would lower the player's meter.
  290. - Added "badcamper_money" CVAR to specify what percentage of money to take
  291. away at 100% when using the "money reduction" punishment. Defaults to
  292. 10% as was the case before the option was introduced.
  293. - Added "badcamper_damage_reset" CVAR flag that specifies the meter(s) to
  294. reset when a player is attacked. Defaults to both attacker and defender
  295. having their meter reset as was the case before the option was introduced.
  296. - Replaced "snore" punishment with "sound" punishment. The type of sound can
  297. be defined by a new CVAR, "badcamper_sound". There are two types of
  298. sounds, "snore" (default value) and "heartbeat".
  299. - Fixed bug where if a player's meter was 100% and the blind punishment was
  300. being used, when the player attacked or was attacked by another, the blind
  301. player would stay blind instead of regaining vision immediately.
  302. - Added "badcamper list" command that lists available punishments and
  303. indicates which are currently active (active as per the badcamper_punish CVAR).
  304. - Added "badcamper_announce" CVAR flag to indicate how to announce that a player
  305. is camping and then when the player stops camping. Will announce the
  306. name of the camper at 90% and then again when the meter gets below 80%.
  307. Options are to print as chat, as a HUD message, both, or neither.
  308. - Fixed bug where the CVAR 'badcamper_allow' had no effect, thus if set to a
  309. value higher than 0 a team would still never be allowed to camp.
  310.  
  311. 2005-SEP-24 1.0
  312.  
  313. - Initial release.
  314.  
  315. Fordította: BBk - Death of Legend
  316. */
  317.  
  318.  
  319. #include <amxmodx>
  320. #include <amxmisc>
  321. #include <fakemeta>
  322. #include <fun>
  323. #include <cstrike> // don't worry if you're not running cstrike, it's all good
  324. #include <csx> // don't worry if you're not running cstrike, it's all good
  325.  
  326. #pragma semicolon 1
  327.  
  328. #define TASKID_CHECK_CAMPING 85809473
  329.  
  330. #define DBG_METER_ON_1 1
  331.  
  332. #define SND_STOP (1<<5)
  333.  
  334. #define TEAM1 1
  335. #define TEAM2 2
  336.  
  337. // Player Flags
  338. #define METER_PAUSE 1
  339. #define METER_IGNORE 2
  340. #define PLAYER_BLIND 4
  341. #define PLAYER_SOUND 8
  342. #define CAMPER_ANNOUNCED 16
  343.  
  344. #define FADE_IN (1<<0)
  345. #define FADE_OUT (1<<1)
  346. #define FADE_HOLD (1<<2)
  347.  
  348. #define FADE_LENGTH_PERM (1<<0)
  349.  
  350. #define PUNISH_SLAP 1
  351. #define PUNISH_HEALTH 2
  352. #define PUNISH_SOUND 4
  353. #define PUNISH_BLIND 8
  354. #define PUNISH_MONEY 16
  355. #define PUNISH_SNARKS 32
  356.  
  357. #define ANNOUNCE_CHAT 1
  358. #define ANNOUNCE_HUD 2
  359.  
  360. #define SOUNDTYPE_SNORE 1
  361. #define SOUNDTYPE_HEARTBEAT 2
  362.  
  363. #define DMG_RESET_DEFENDER 1
  364. #define DMG_RESET_ATTACKER 2
  365.  
  366. #define TOLERANCE_DEFENDING 180
  367. #define TOLERANCE_ATTACKING 220
  368.  
  369. #define MAX_PLAYER_CNT 32
  370. #define MAX_COORDTYPE_CNT 2
  371. #define MAX_VECTOR_CNT 4
  372. #define MAX_COORD_CNT 3
  373.  
  374. #define COORDTYPE_BODY 0
  375. #define COORDTYPE_EYES 1
  376.  
  377. new g_coordsBody[MAX_PLAYER_CNT + 1][MAX_VECTOR_CNT][MAX_COORD_CNT];
  378. new g_coordsEyes[MAX_PLAYER_CNT + 1][MAX_VECTOR_CNT][MAX_COORD_CNT];
  379. new g_meter[MAX_PLAYER_CNT + 1], g_playerFlags[MAX_PLAYER_CNT + 1], g_snarkCnt[MAX_PLAYER_CNT + 1];
  380. new g_bombPlanter, bool:g_bombPlanted;
  381. new g_bombDefuser;
  382. new g_msgFade, g_mapHasBomb;
  383. new g_cstrike;
  384. new g_immunityFlags[32];
  385. new g_maxPlayers;
  386. new g_campMeterMsgSync, g_isCampingMsgSync;
  387.  
  388. // declare CVAR pointers
  389. new g_cvarDebug, g_cvarPunish, g_cvarLimit, g_cvarDisplay, g_cvarCheckAll, g_cvarShowSpec;
  390. new g_cvarStart, g_cvarDamageReset, g_cvarDamageRestart, g_cvarHealth, g_cvarMoney;
  391. new g_cvarMinPlayers, g_cvarAllow, g_cvarAnnounce, g_cvarSound, g_cvarImmunityFlags;
  392.  
  393. public plugin_natives()
  394. {
  395. set_module_filter("filter_module");
  396. set_native_filter("filter_native");
  397. }
  398.  
  399. public filter_module(const module[])
  400. {
  401. return (equal(module, "cstrike") || equal(module, "csx")) ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
  402. }
  403.  
  404. public filter_native(const name[], index, trap)
  405. {
  406. return (!trap) ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
  407. }
  408.  
  409. public plugin_precache()
  410. {
  411. if (get_cvar_num("badcamper_sound") & SOUNDTYPE_SNORE) precache_sound("misc/snore.wav");
  412. precache_sound("player/heartbeat1.wav");
  413.  
  414. return PLUGIN_CONTINUE;
  415. }
  416.  
  417. public plugin_init()
  418. {
  419. new pluginVersion[] = "1.4 beta";
  420.  
  421. register_plugin("Bad Camper", pluginVersion, "Brad Jones");
  422.  
  423. register_cvar("badcamper_version", pluginVersion, FCVAR_SERVER|FCVAR_SPONLY);
  424. g_cvarDebug = register_cvar("badcamper_debug", "0");
  425.  
  426. register_dictionary("bad_camper.txt");
  427.  
  428. register_concmd("badcamper", "cmd_list", ADMIN_CVAR, "- lists available punishments and indicates which are active");
  429.  
  430. g_cvarPunish = register_cvar("badcamper_punish", "12"); // is camping to be punished and if so, how
  431. g_cvarLimit = register_cvar("badcamper_limit", "35"); // seconds allowed to camp
  432. g_cvarDisplay = register_cvar("badcamper_display", "1"); // at what percentage to display meter
  433. g_cvarCheckAll = register_cvar("badcamper_check_all", "1"); // check both teams or just team with primary objective
  434. g_cvarStart = register_cvar("badcamper_start", "4.0"); // number of seconds after the start of a round that the meter starts
  435. g_cvarDamageReset = register_cvar("badcamper_damage_reset", "3"); // flag that indicates which meter(s) get reset upon a player attack
  436. g_cvarDamageRestart = register_cvar("badcamper_damage_restart", "4.0"); // number of seconds after giving or taking damage that the meter restarts
  437. g_cvarHealth = register_cvar("badcamper_health", "10"); // health taken if 'health reduction' punishment flag set (at 100% camp meter)
  438. g_cvarMoney = register_cvar("badcamper_money", "10"); // percentage of player's money taken if 'money reduction' punishment flag set (at 100% camp meter)
  439. g_cvarMinPlayers = register_cvar("badcamper_min_players", "0"); // minimum players before camping is allowed
  440. g_cvarAllow = register_cvar("badcamper_allow", "0"); // when is camping allowed
  441. g_cvarAnnounce = register_cvar("badcamper_announce", "3"); // announce a player's camping status
  442. g_cvarSound = register_cvar("badcamper_sound", "1"); // type of sound to play when "badcamper_punish" includes the sound punishment
  443. g_cvarImmunityFlags = register_cvar("badcamper_immunity_flags", ""); // which access levels have immunity
  444. g_cvarShowSpec = register_cvar("badcamper_show_spec", "1"); // let spectators see a player's meter?
  445. }
  446.  
  447. public plugin_cfg()
  448. {
  449. g_msgFade = get_user_msgid("ScreenFade");
  450. g_maxPlayers = get_maxplayers();
  451. g_isCampingMsgSync = CreateHudSyncObj();
  452. g_campMeterMsgSync = CreateHudSyncObj();
  453.  
  454. get_pcvar_string(g_cvarImmunityFlags, g_immunityFlags, 31);
  455.  
  456. if (module_exists("cstrike"))
  457. {
  458. g_cstrike = true;
  459.  
  460. // register_event("StatusValue","set_spec_target","bd","1=2"); // from Kost
  461. register_event("SpecHealth2", "meter_display_spec_clear", "bd");
  462. register_event("BarTime", "event_bartime", "b");
  463. register_event("HLTV", "event_new_round", "a", "1=0", "2=0");
  464. register_logevent("event_round_start", 2, "1=Round_Start");
  465. register_logevent("event_round_end", 2, "1=Round_End");
  466. register_logevent("event_round_end", 2, "1&Restart_Round_");
  467.  
  468. g_mapHasBomb = engfunc(EngFunc_FindEntityByString,-1, "classname", "func_bomb_target");
  469. }
  470. else if (module_exists("dodx"))
  471. {
  472. register_event("RoundState", "event_round_start", "a", "1=1");
  473. register_event("RoundState", "event_round_end", "a", "1>2");
  474. register_event("ResetSens", "flags_reset", "b");
  475. }
  476. }
  477.  
  478. public cmd_list(id, level, cid)
  479. {
  480. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED;
  481.  
  482. new punishmentFlags = get_pcvar_num(g_cvarPunish);
  483. new punishSlap[32], punishHealth[32], punishSound[32], punishBlind[32], punishMoney[32], punishSnarks[32];
  484.  
  485. // List each of the punishments available and indicate which of them are currently active.
  486. formatex(punishSlap, 31, "%5i %-1.1s%L", 1, (punishmentFlags & PUNISH_SLAP) ? "*" : "", LANG_SERVER, "PUNISH_SLAP") ;
  487. formatex(punishHealth, 31, "%5i %-1.1s%L", 2, (punishmentFlags & PUNISH_HEALTH) ? "*" : "", LANG_SERVER, "PUNISH_HEALTH");
  488. formatex(punishSound, 31, "%5i %-1.1s%L (%L)", 4, (punishmentFlags & PUNISH_SOUND) ? "*" : "", LANG_SERVER, "PUNISH_SOUND", LANG_SERVER, (get_pcvar_num(g_cvarSound) & SOUNDTYPE_SNORE) ? "SOUND_SNORE" : "SOUND_HEART");
  489. formatex(punishBlind, 31, "%5i %-1.1s%L", 8, (punishmentFlags & PUNISH_BLIND) ? "*" : "", LANG_SERVER, "PUNISH_BLIND");
  490. formatex(punishMoney, 31, "%5i %-1.1s%L", 16, (punishmentFlags & PUNISH_MONEY) ? "*" : "", LANG_SERVER, "PUNISH_MONEY");
  491. formatex(punishSnarks, 31, "%5i %-1.1s%L", 32, (punishmentFlags & PUNISH_SNARKS) ? "*" : "", LANG_SERVER, "PUNISH_SNARKS");
  492.  
  493. if (id)
  494. {
  495. client_print(id, print_console, "%s", punishSlap);
  496. client_print(id, print_console, "%s", punishHealth);
  497. client_print(id, print_console, "%s", punishSound);
  498. client_print(id, print_console, "%s", punishBlind);
  499. client_print(id, print_console, "%s", punishMoney);
  500. client_print(id, print_console, "%s", punishSnarks);
  501. }
  502. else
  503. {
  504. server_print("%s", punishSlap);
  505. server_print("%s", punishHealth);
  506. server_print("%s", punishSound);
  507. server_print("%s", punishBlind);
  508. server_print("%s", punishMoney);
  509. server_print("%s", punishSnarks);
  510. }
  511. return PLUGIN_HANDLED;
  512. }
  513.  
  514. public check_camping()
  515. {
  516. /* don't check, if the plugin is disabled */
  517. new punishmentFlags = get_pcvar_num(g_cvarPunish);
  518. if (punishmentFlags == 0) return;
  519.  
  520. /* don't check, if there is only one player on server */
  521. new players[32], playerCnt;
  522. get_players(players, playerCnt, "ch"); // don't include bots or hltv
  523. if (playerCnt == 1 && !(get_pcvar_num(g_cvarDebug) && DBG_METER_ON_1)) return;
  524.  
  525. /* determine acceptable camping values */
  526. new allowCampValue = get_pcvar_num(g_cvarAllow);
  527. new s_allowCampValue[8];
  528. new bool:allowCampByRatio;
  529.  
  530. if (allowCampValue > 0)
  531. {
  532. get_pcvar_string(g_cvarAllow, s_allowCampValue, 7);
  533. allowCampByRatio = (contain(s_allowCampValue, "%") ==-1) ? false : true;
  534. allowCampValue = (allowCampByRatio) ? clamp(allowCampValue, 1, 100) : clamp(allowCampValue, 1, 32);
  535. }
  536.  
  537. /* determine if either team is allowed to camp */
  538. new bool:allowTeamCamp[3] = {false, ...}; // using elements 1 and 2 to correspond to the values for TEAM1 and TEAM2
  539. new playerCnt_team1, playerCnt_team2, teamID, id;
  540.  
  541. get_players(players, playerCnt, "h"); // don't include hltv
  542. if (playerCnt >= get_pcvar_num(g_cvarMinPlayers))
  543. {
  544. // based on their objective ...
  545. if (!get_pcvar_num(g_cvarCheckAll) && g_cstrike)
  546. {
  547. if (!g_mapHasBomb)
  548. allowTeamCamp[TEAM1] = true;
  549. else if (g_bombPlanted)
  550. allowTeamCamp[TEAM1] = true;
  551. else
  552. allowTeamCamp[TEAM2] = true;
  553. }
  554.  
  555. // ... and based on calculated camp allowance
  556. if (allowCampValue > 0)
  557. {
  558. // get living player counts for each team
  559. get_players(players, playerCnt, "ah"); // skip dead players and hltv
  560. for (new playerIdx = 0; playerIdx < playerCnt; ++playerIdx)
  561. {
  562. id = players[playerIdx];
  563. teamID = get_user_team(id);
  564. if (teamID == TEAM1)
  565. playerCnt_team1++;
  566. else if (teamID == TEAM2)
  567. playerCnt_team2++;
  568. }
  569.  
  570. if (allowCampByRatio)
  571. {
  572. // allow camp per ratio of players on player's team to players on other team
  573. if (!allowTeamCamp[TEAM1]) allowTeamCamp[TEAM1] = allowCampValue >= percent(playerCnt_team1, playerCnt_team2);
  574. if (!allowTeamCamp[TEAM2]) allowTeamCamp[TEAM2] = allowCampValue >= percent(playerCnt_team2, playerCnt_team1);
  575. }
  576. else
  577. {
  578. // allow camp per straight player count
  579. if (!allowTeamCamp[TEAM1]) allowTeamCamp[TEAM1] = (allowCampValue >= playerCnt_team1);
  580. if (!allowTeamCamp[TEAM2]) allowTeamCamp[TEAM2] = (allowCampValue >= playerCnt_team2);
  581. }
  582. }
  583. }
  584.  
  585. /* handle each player's camping needs */
  586. new stdDev, campTolerance;
  587. new prevMeter, bool:punishCamper, Float:punishPercentage;
  588. new announceCampStatus = get_pcvar_num(g_cvarAnnounce);
  589.  
  590. get_players(players, playerCnt, "ah"); // skip dead players and hltv
  591. for (new playerIdx = 0; playerIdx < playerCnt; ++playerIdx)
  592. {
  593. id = players[playerIdx];
  594.  
  595. // pause the meter (don't cycle coords) if needed
  596. if (g_playerFlags[id] & METER_PAUSE) continue;
  597.  
  598. // insert the current location of the player
  599. coords_insert(id, COORDTYPE_BODY);
  600.  
  601. // ignore the meter if the player can legally camp or the player's meter is being ignored
  602. teamID = get_user_team(id);
  603. if (allowTeamCamp[teamID] || g_playerFlags[id] & METER_IGNORE) continue;
  604.  
  605. // ignore if this player meets the immunity requirements
  606. if (has_flag(id, g_immunityFlags))
  607. {
  608. // insert the current coords of where the player's shot would hit, i.e. where the player is looking
  609. coords_insert(id, COORDTYPE_EYES);
  610.  
  611. if (standing_still(id) && !looking_around(id) && g_meter[id] >= 65 && g_meter[id] < 80) continue;
  612. }
  613.  
  614. // grab the standard deviation from the player coords
  615. stdDev = coords_stdv(id);
  616.  
  617. // grab the camping tolerance based on current objective
  618. campTolerance = (!g_mapHasBomb || g_bombPlanted) ? TOLERANCE_ATTACKING : TOLERANCE_DEFENDING;
  619.  
  620. // grab the current meter percentage
  621. prevMeter = g_meter[id];
  622.  
  623. // add new percentage points to the meter
  624. g_meter[id] += (campTolerance- stdDev) / get_pcvar_num(g_cvarLimit);
  625.  
  626. // ensure the meter falls within bounds
  627. g_meter[id] = clamp(g_meter[id], 0, 100);
  628.  
  629. // if the meter is trending down, give the player some love
  630. if (g_meter[id] < prevMeter)
  631. {
  632. if (g_meter[id] < 80)
  633. {
  634. // help the meter find it's way down
  635. g_meter[id]-= (prevMeter- g_meter[id]) / 3;
  636.  
  637. if (prevMeter >= 80)
  638. {
  639. // ensure player isn't still being punished
  640. punish_stop_all(id);
  641.  
  642. // announce that the player is no longer camping
  643. if (announceCampStatus && g_playerFlags[id] & CAMPER_ANNOUNCED) camper_announcement(id, false);
  644. }
  645. }
  646. }
  647.  
  648. // determine how severe the punishment should be, if at all
  649. punishCamper = true; // now prove me wrong
  650. if (g_meter[id] == 100) punishPercentage = 1.00;
  651. else if (g_meter[id] >= 90) punishPercentage = 0.50;
  652. else if (g_meter[id] >= 80) punishPercentage = 0.10;
  653. else punishCamper = false;
  654.  
  655. // punish the vile camper
  656. if (punishCamper)
  657. {
  658. if (punishmentFlags & PUNISH_SLAP) punish_slap(id, punishPercentage);
  659. if (punishmentFlags & PUNISH_HEALTH) punish_health_reduction(id, punishPercentage);
  660. if (punishmentFlags & PUNISH_BLIND) punish_blind(id, punishPercentage);
  661. if (punishmentFlags & PUNISH_SOUND) punish_sound(id, punishPercentage);
  662. if (punishmentFlags & PUNISH_MONEY) punish_money_reduction(id, punishPercentage);
  663. if (punishmentFlags & PUNISH_SNARKS) punish_snark_attack(id, punishPercentage);
  664.  
  665. // announce that the player is camping
  666. if (g_meter[id] >= 90 && !(g_playerFlags[id] & CAMPER_ANNOUNCED)) camper_announcement(id, true);
  667. }
  668.  
  669. // let them know how long they've camped
  670. meter_display(id);
  671. }
  672. }
  673.  
  674. camper_announcement(id, bool:isCamping)
  675. {
  676. // announce to the opposite team this player's camping status
  677. new camperName[32];
  678. get_user_name(id, camperName, 31);
  679.  
  680. new camperTeam = get_user_team(id);
  681.  
  682. new announcementType = get_pcvar_num(g_cvarAnnounce);
  683. if (announcementType)
  684. {
  685. new msgAnnouncement[16];
  686. copy(msgAnnouncement, 15, (isCamping) ? "CAMPING_STARTED" : "CAMPING_STOPPED");
  687.  
  688. new playerId, announcement[64];
  689.  
  690. for (playerId = 1; playerId <= g_maxPlayers; playerId++)
  691. {
  692. if (is_user_connected(playerId) && get_user_team(playerId) != camperTeam)
  693. {
  694. formatex(announcement, 63, "%L", playerId, msgAnnouncement, camperName);
  695.  
  696. if (announcementType & ANNOUNCE_CHAT)
  697. client_print(playerId, print_chat, "[BADCAMPER] %s", announcement);
  698.  
  699. if (announcementType & ANNOUNCE_HUD)
  700. {
  701. set_hudmessage(100, 100, 255,-1.0, 0.88, 0, 1.0, 6.0, 0.1, 0.1,-1);
  702. ShowSyncHudMsg(playerId, g_isCampingMsgSync, "%s", announcement);
  703. }
  704. }
  705. }
  706. g_playerFlags[id] += (isCamping) ? CAMPER_ANNOUNCED :-CAMPER_ANNOUNCED;
  707. }
  708. }
  709.  
  710. punish_health_reduction(id, Float:punishPercentage)
  711. {
  712. set_pev(id, pev_dmg_inflictor, id);
  713. // set_pev(id, pev_health, get_user_health(id)- floatround(get_pcvar_float(g_cvarHealth) * punishPercentage)); <-- apparently this does bad things
  714. set_user_health(id, get_user_health(id)- floatround(get_pcvar_float(g_cvarHealth) * punishPercentage));
  715. }
  716.  
  717. punish_sound(id, Float:punishPercentage)
  718. {
  719. new soundFile[32];
  720. formatex(soundFile, 31, (get_pcvar_num(g_cvarSound) & SOUNDTYPE_SNORE) ? "misc/snore.wav" : "player/heartbeat1.wav");
  721.  
  722. emit_sound(id, CHAN_VOICE, soundFile, punishPercentage, ATTN_NORM, 0, PITCH_NORM);
  723. if (!(g_playerFlags[id] & PLAYER_SOUND)) g_playerFlags[id] += PLAYER_SOUND;
  724. }
  725.  
  726. punish_sound_stop(id)
  727. {
  728. new soundFile[32];
  729. formatex(soundFile, 31, (get_pcvar_num(g_cvarSound) & SOUNDTYPE_SNORE) ? "misc/snore.wav" : "player/heartbeat1.wav");
  730.  
  731. emit_sound(id, CHAN_VOICE, soundFile, 0.0, ATTN_NORM, 0, PITCH_NORM);
  732. if (g_playerFlags[id] & PLAYER_SOUND) g_playerFlags[id]-= PLAYER_SOUND;
  733. }
  734.  
  735. punish_slap(id, Float:punishPercentage)
  736. {
  737. for (new slapCnt = 1; slapCnt <= floatround(3.0 * punishPercentage, floatround_ceil); slapCnt++)
  738. user_slap(id, 0);
  739. }
  740.  
  741. punish_money_reduction(id, Float:punishPercentage)
  742. {
  743. if (g_cstrike)
  744. {
  745. new Float:lossPercentage = (get_pcvar_float(g_cvarMoney) / 100.0) * punishPercentage;
  746. new Float:currentMoney = float(cs_get_user_money(id));
  747. new reducedMoney = floatround(currentMoney- (currentMoney * lossPercentage));
  748. cs_set_user_money(id, reducedMoney);
  749. }
  750. }
  751.  
  752. public meter_display(id)
  753. {
  754. new displayMeter = get_pcvar_num(g_cvarDisplay);
  755.  
  756. if (displayMeter > 0 && g_meter[id] >= displayMeter)
  757. {
  758. new r, g, b;
  759.  
  760. if (g_meter[id] > 90)
  761. r = 255;
  762. else if (g_meter[id] > 80)
  763. {
  764. r = 255;
  765. g = 100;
  766. }
  767. else if (g_meter[id] > 50)
  768. {
  769. r = 255;
  770. g = 255;
  771. }
  772. else if (g_meter[id] > 20)
  773. g = 255;
  774. else
  775. b = 255;
  776.  
  777. set_hudmessage(r, g, b,-1.0, 0.85, 0, 1.0, 2.0, 0.1, 0.1,-1);
  778. ShowSyncHudMsg(id, g_campMeterMsgSync, "%L", id, "CAMP_METER", g_meter[id]);
  779.  
  780. // if allowed and there's anyone specing this player, go ahead and show them the meter too
  781. if (g_cvarShowSpec)
  782. {
  783. new playerCnt, players[MAX_PLAYER_CNT], id_spectator;
  784. get_players(players, playerCnt, "bch"); // skip alive players, bots, and hltv
  785. for (new playerIdx = 0; playerIdx < playerCnt; ++playerIdx)
  786. {
  787. id_spectator = players[playerIdx];
  788.  
  789. if (pev(id_spectator, pev_iuser2) == id)
  790. {
  791. ShowSyncHudMsg(id_spectator, g_campMeterMsgSync, "%L", id_spectator, "CAMP_METER", g_meter[id]);
  792. }
  793. }
  794. }
  795. }
  796. }
  797.  
  798. public standing_still(id)
  799. {
  800. return vectors_same(id, COORDTYPE_BODY);
  801. }
  802.  
  803. public looking_around(id)
  804. {
  805. return !vectors_same(id, COORDTYPE_EYES);
  806. }
  807.  
  808. public vectors_same(id, coordType)
  809. {
  810. new curCoords[MAX_COORD_CNT], coordIdx;
  811.  
  812. // grab the current coordinates
  813. for (coordIdx = 0; coordIdx < MAX_COORD_CNT; ++coordIdx)
  814. curCoords[coordIdx] = (coordType == COORDTYPE_BODY) ? g_coordsBody[id][0][coordIdx] : g_coordsEyes[id][0][coordIdx];
  815.  
  816. for (new vectorIdx = 1; vectorIdx < MAX_VECTOR_CNT; ++vectorIdx)
  817. for (coordIdx = 0; coordIdx < MAX_COORD_CNT; ++coordIdx)
  818. if (curCoords[coordIdx] != ((coordType == COORDTYPE_BODY) ? g_coordsBody[id][vectorIdx][coordIdx] : g_coordsEyes[id][vectorIdx][coordIdx]))
  819. return false;
  820.  
  821. return true;
  822. }
  823.  
  824. public coords_stdv(id)
  825. {
  826. // get the total variance of all the coords
  827. new sum, avg, variance, varianceTot;
  828. new coordIdx, vectorIdx;
  829.  
  830. for (coordIdx = 0; coordIdx < MAX_COORD_CNT; ++coordIdx)
  831. {
  832. // initialize our working variables
  833. sum = 0;
  834. variance = 0;
  835.  
  836. // get the average of the coordinate
  837. for (vectorIdx = 0; vectorIdx < MAX_VECTOR_CNT; ++vectorIdx)
  838. sum += g_coordsBody[id][vectorIdx][coordIdx];
  839.  
  840. avg = sum / MAX_VECTOR_CNT;
  841.  
  842. // get the variance of the coordinate
  843. for (vectorIdx = 0; vectorIdx < MAX_VECTOR_CNT; ++vectorIdx)
  844. variance += power(g_coordsBody[id][vectorIdx][coordIdx]- avg, 2);
  845.  
  846. variance = variance / (MAX_VECTOR_CNT- 1);
  847.  
  848. // increment the total variance of all coordinates
  849. varianceTot += variance;
  850. }
  851.  
  852. // return the standard deviation (std dev = the square root of the variance)
  853. return sqroot(varianceTot);
  854. }
  855.  
  856. public coords_insert(id, coordType)
  857. {
  858. // move each vector up one level, making room at the bottom for the new coords
  859. for (new vectorIdx = MAX_VECTOR_CNT- 1; vectorIdx > 0;--vectorIdx)
  860. {
  861. for (new coordIdx = 0; coordIdx < MAX_COORD_CNT; ++coordIdx)
  862. {
  863. if (coordType == COORDTYPE_BODY)
  864. g_coordsBody[id][vectorIdx][coordIdx] = g_coordsBody[id][vectorIdx- 1][coordIdx];
  865. else
  866. g_coordsEyes[id][vectorIdx][coordIdx] = g_coordsEyes[id][vectorIdx- 1][coordIdx];
  867. }
  868. }
  869.  
  870. // now that space is cleared for them, insert the current coords into the lowest vector
  871. if (is_user_connected(id))
  872. {
  873. if (coordType == COORDTYPE_BODY)
  874. get_user_origin(id, g_coordsBody[id][0], 0);
  875. else
  876. get_user_origin(id, g_coordsEyes[id][0], 3);
  877. }
  878. }
  879.  
  880. public punish_snark_attack(id, Float:punishPercentage)
  881. {
  882. new maxSnarkCnt = floatround(punishPercentage * 16.0);
  883.  
  884. if (g_snarkCnt[id] < maxSnarkCnt)
  885. {
  886. // send the snarks out, two at a time
  887. server_cmd("monster snark #%i", id);
  888. server_cmd("monster snark #%i", id);
  889.  
  890. g_snarkCnt[id] += 2;
  891. }
  892. }
  893.  
  894. public punish_blind(id, Float:punishPercentage)
  895. {
  896. new duration = (punishPercentage == 1.0) ? FADE_LENGTH_PERM : 1<<12;
  897. new holdTime = (punishPercentage == 1.0) ? FADE_LENGTH_PERM : 1<<8;
  898. new fadeType = (punishPercentage == 1.0) ? FADE_HOLD : FADE_IN;
  899. new blindness = 127 + floatround(128.0 * punishPercentage);
  900.  
  901. if (is_user_alive(id))
  902. {
  903. if (!(g_playerFlags[id] & PLAYER_BLIND)) g_playerFlags[id] += PLAYER_BLIND;
  904.  
  905. message_begin(MSG_ONE, g_msgFade, {0,0,0}, id); // use the magic #1 for "one client"
  906. write_short(duration); // fade lasts this long duration
  907. write_short(holdTime); // fade lasts this long hold time
  908. write_short(fadeType); // fade type
  909. write_byte(0); // fade red
  910. write_byte(0); // fade green
  911. write_byte(0); // fade blue
  912. write_byte(blindness); // fade alpha
  913. message_end();
  914. }
  915. }
  916.  
  917. public punish_blind_stop(id)
  918. {
  919. if (g_playerFlags[id] & PLAYER_BLIND) g_playerFlags[id]-= PLAYER_BLIND;
  920.  
  921. message_begin(MSG_ONE, g_msgFade, {0,0,0}, id); // use the magic #1 for "one client"
  922. write_short(1<<12); // fade lasts this long duration
  923. write_short(1<<8); // fade lasts this long hold time
  924. write_short(FADE_OUT); // fade type
  925. write_byte(0); // fade red
  926. write_byte(0); // fade green
  927. write_byte(0); // fade blue
  928. write_byte(255); // fade alpha
  929. message_end();
  930. }
  931.  
  932. public meter_dmg_reset(id)
  933. {
  934. // forgive previous camping transgressions
  935. punish_stop_all(id);
  936. g_meter[id] = 0;
  937. g_playerFlags[id] = 0;
  938.  
  939. // the player has been through enough trauma (getting or giving damage)
  940. // so let's just ignore the camp meter for awhile
  941. meter_ignore(id);
  942.  
  943. remove_task(id);
  944. set_task(get_pcvar_float(g_cvarDamageRestart), "meter_unignore", id);
  945. }
  946.  
  947. public meter_pause(id)
  948. {
  949. if (!(g_playerFlags[id] & METER_PAUSE)) g_playerFlags[id] += METER_PAUSE;
  950. }
  951.  
  952. public meter_ignore(id)
  953. {
  954. if (!(g_playerFlags[id] & METER_IGNORE)) g_playerFlags[id] += METER_IGNORE;
  955. }
  956.  
  957. public meter_unpause(id)
  958. {
  959. if (g_playerFlags[id] & METER_PAUSE) g_playerFlags[id]-= METER_PAUSE;
  960. }
  961.  
  962. public meter_unignore(id)
  963. {
  964. if (g_playerFlags[id] & METER_IGNORE) g_playerFlags[id]-= METER_IGNORE;
  965. }
  966.  
  967. public start_checking()
  968. {
  969. for (new id = 1; id <= 32; id++)
  970. meter_unignore(id);
  971. }
  972.  
  973. public bomb_planting(planter)
  974. {
  975. g_bombPlanter = planter;
  976. meter_pause(planter);
  977. }
  978.  
  979. public event_bartime(id)
  980. {
  981. if (read_data(1) == 0)
  982. {
  983. if (id == g_bombPlanter)
  984. g_bombPlanter = 0;
  985. else if (id == g_bombDefuser)
  986. g_bombDefuser = 0;
  987. else
  988. return;
  989.  
  990. meter_unpause(id);
  991. }
  992. }
  993.  
  994. public bomb_planted(planter)
  995. {
  996. g_bombPlanter = 0;
  997. g_bombPlanted = true;
  998. meter_unpause(planter);
  999. }
  1000.  
  1001. public bomb_defusing(defuser)
  1002. {
  1003. g_bombDefuser = defuser;
  1004. meter_pause(defuser);
  1005. }
  1006.  
  1007. public bomb_defused(defuser)
  1008. {
  1009. g_bombDefuser = 0;
  1010. meter_unpause(defuser);
  1011. }
  1012.  
  1013. public client_damage(attacker, victim, damage, wpnindex, hitplace, TA)
  1014. {
  1015. if (attacker && victim && attacker != victim && !TA)
  1016. {
  1017. new damageResetFlag = get_pcvar_num(g_cvarDamageReset);
  1018. if (damageResetFlag & DMG_RESET_DEFENDER)
  1019. meter_dmg_reset(victim);
  1020. if (damageResetFlag & DMG_RESET_ATTACKER)
  1021. meter_dmg_reset(attacker);
  1022. }
  1023. }
  1024.  
  1025. public event_round_end()
  1026. {
  1027. // stop checking for camping
  1028. remove_task(TASKID_CHECK_CAMPING);
  1029. }
  1030.  
  1031. public event_new_round()
  1032. {
  1033. // make sure any straggling monsters are sent away to a better place
  1034. if (get_pcvar_num(g_cvarPunish) & PUNISH_SNARKS)
  1035. {
  1036. monsters_kill();
  1037. }
  1038. }
  1039.  
  1040. public event_round_start()
  1041. {
  1042. g_bombPlanted = false;
  1043.  
  1044. if (get_pcvar_num(g_cvarPunish))
  1045. {
  1046. // reset all the flags
  1047. for (new id = 1; id <= 32; id++)
  1048. {
  1049. flags_reset(id);
  1050. meter_ignore(id);
  1051. }
  1052. set_task(get_pcvar_float(g_cvarStart), "start_checking");
  1053. set_task(2.0, "check_camping", TASKID_CHECK_CAMPING, _, _, "b");
  1054. }
  1055. }
  1056.  
  1057. monsters_kill()
  1058. {
  1059. // this function will kill ALL monsters on the map, it doesn't make a distinction
  1060. // between monsters spawned by THIS plugin and monsters spawned some other way.
  1061. // if it's a monster, it'll be killed.
  1062. new Float:health;
  1063. new maxEntities = global_get(glb_maxEntities);
  1064. for (new entity = 1; entity < maxEntities; ++entity)
  1065. {
  1066. if (pev_valid(entity) && pev(entity, pev_flags) & FL_MONSTER)
  1067. {
  1068. set_pev(entity, pev_dmg_inflictor, 0); // set the damage inflictor to "world"
  1069. pev(entity, pev_health, health); // grab the monster's current health
  1070. set_pev(entity, pev_health, 0.0); // kill the monster by taking away all it's health //pev_fuser4
  1071. }
  1072. }
  1073. }
  1074.  
  1075. public flags_reset(id)
  1076. {
  1077. g_meter[id] = 0;
  1078. g_playerFlags[id] = 0;
  1079. g_snarkCnt[id] = 0;
  1080. coords_reset(id);
  1081. }
  1082.  
  1083. public coords_reset(id)
  1084. {
  1085. for (new vectorIdx = 0; vectorIdx < MAX_VECTOR_CNT; vectorIdx++)
  1086. coords_insert(id, COORDTYPE_BODY);
  1087. }
  1088.  
  1089. public punish_stop_all(id)
  1090. {
  1091. if (g_playerFlags[id] & PLAYER_BLIND) punish_blind_stop(id);
  1092. if (g_playerFlags[id] & PLAYER_SOUND) punish_sound_stop(id);
  1093. g_snarkCnt[id] = 0;
  1094. }
  1095.  
  1096. percent(is, of)
  1097. {
  1098. return (of != 0) ? floatround(floatmul(float(is)/float(of), 100.0)) : 0;
  1099. }
  1100.  
  1101. /*
  1102. stock debug_log(const textID[] = "", const text[] = "", {Float,Sql,Result,_}:...)
  1103. {
  1104. new debugger = get_cvar_num("badcamper_debug");
  1105. if (debugger || debugger ==-1)
  1106. {
  1107. // format the text as needed
  1108. new formattedText[1024];
  1109. format_args(formattedText, 1023, 1);
  1110. // if there's a text identifier, add it
  1111. if (textID[0])
  1112. format(formattedText, 1023, "[%s] %s", textID, formattedText);
  1113. // log text to file
  1114. log_to_file("_badcamper.log", formattedText);
  1115. // if there's someone to show text to, do so
  1116. if (debugger && is_user_connected(debugger))
  1117. client_print(debugger, print_chat, formattedText);
  1118. }
  1119. // not needed but gets rid of stupid compiler error
  1120. if (text[0] == 0) return;
  1121. }
  1122. */
  1123.  
  1124. /*
  1125. stock has_flag(id, flags[])
  1126. {
  1127. return (get_user_flags(id) & read_flags(flags));
  1128. }
  1129. */
  1130.  
  1131. public meter_display_spec_clear(id)
  1132. {
  1133. ClearSyncHud(id, g_campMeterMsgSync);
  1134. }