TuttiFrutti

AMX - CT Score Penalty

Dec 29th, 2019 (edited)
356
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.93 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <cstrike>
  5.  
  6. #define PLUGIN "CT Score Penalty"
  7. #define VERSION "3.4"
  8. #define AUTHOR "TuttiFrutti"
  9.  
  10. // Max distance for penalty
  11. #define MAX_DISTANCE 1000.0  
  12.  
  13. // d2 locs - cat, ctspawn, tunnel, pit, tpsawn, bsite A and B
  14. new const Float:catwalkMin[3] = {-1600.0, -50.0, -100.0};
  15. new const Float:catwalkMax[3] = {500.0, -600.0, 100.0};
  16.  
  17. new const Float:ctSpawnMin[3] = {-2000.0, -200.0, -100.0};
  18. new const Float:ctSpawnMax[3] = {-1500.0, 1500.0, 50.0};
  19.  
  20. new const Float:pitMin[3] = {-2200.0, 500.0, -100.0};
  21. new const Float:pitMax[3] = {-1700.0, 1000.0, 200.0};
  22.  
  23. new const Float:tunnelMin[3] = {700.0, 200.0, -100.0};
  24. new const Float:tunnelMax[3] = {1200.0, 500.0, 300.0};
  25.  
  26. new const Float:tSpawnMin[3] = {1400.0, 300.0, -100.0};
  27. new const Float:tSpawnMax[3] = {1800.0, 800.0, 200.0};
  28.  
  29. new const Float:bombsiteA[3] = {-1800.0, 1250.0, 0.0};
  30. new const Float:bombsiteB[3] = {950.0, 290.0, 0.0};
  31.  
  32. // track c4 explosion
  33. new bool:g_bombExploded = false;
  34.  
  35. public plugin_init() {
  36.     register_plugin(PLUGIN, VERSION, AUTHOR);
  37.     register_event("HLTV", "on_bomb_exploded", "a", "1=3", "2=1"); // boom!
  38. }
  39.  
  40. public on_bomb_exploded() {
  41.     g_bombExploded = true;
  42.     set_task(1.0, "checkCtPenaltyAfterExplosion", _, _, _, "b"); // check after 1 sec
  43. }
  44.  
  45. public checkCtPenaltyAfterExplosion() {
  46.     // Only check if bomb exploded
  47.     if (!g_bombExploded) {
  48.         return;
  49.     }
  50.  
  51.     // Check all CTs after explosion
  52.     for (new id = 1; id <= 32; id++) {
  53.         if (!is_user_connected(id) || !is_user_alive(id) || cs_get_user_team(id) != CS_TEAM_CT) {
  54.             continue; // skip non-CTs
  55.         }
  56.  
  57.         // Check if player is defusing
  58.         if (cs_get_user_defuse(id)) {
  59.             new defusePos[3];
  60.             pev(id, pev_origin, defusePos);
  61.  
  62.             // Check if other CTs nearby and alive
  63.             bool isOtherCTNearby = false;
  64.             for (new otherId = 1; otherId <= 32; otherId++) {
  65.                 if (otherId == id || !is_user_connected(otherId) || !is_user_alive(otherId) || cs_get_user_team(otherId) != CS_TEAM_CT) {
  66.                     continue;
  67.                 }
  68.  
  69.                 new Float:otherPos[3];
  70.                 pev(otherId, pev_origin, otherPos);
  71.                
  72.                 // If any CT is close enough, no penalty
  73.                 if (get_distance_f(defusePos, otherPos) <= MAX_DISTANCE) {
  74.                     isOtherCTNearby = true;
  75.                     break;
  76.                 }
  77.             }
  78.  
  79.             // No nearby CTs? Then check position for penalty
  80.             if (!isOtherCTNearby) {
  81.                 new Float:pos[3];
  82.                 pev(id, pev_origin, pos);
  83.  
  84.                 // If out of bounds or in the wrong areas
  85.                 if (get_distance_f(pos, bombsiteA) > MAX_DISTANCE || isInArea(pos, catwalkMin, catwalkMax) ||
  86.                     isInArea(pos, ctSpawnMin, ctSpawnMax) || isInArea(pos, pitMin, pitMax)) {
  87.  
  88.                     adjustScore(id, -1); // Penalize
  89.                 }
  90.  
  91.                 // Same for bombsite B
  92.                 if (get_distance_f(pos, bombsiteB) > MAX_DISTANCE || isInArea(pos, tunnelMin, tunnelMax) ||
  93.                     isInArea(pos, tSpawnMin, tSpawnMax)) {
  94.  
  95.                     adjustScore(id, -1); // Penalize
  96.                 }
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102. // Check if player is in specific area
  103. bool:isInArea(const Float:pos[3], const Float:min[3], const Float:max[3]) {
  104.     return (pos[0] >= min[0] && pos[0] <= max[0] &&
  105.             pos[1] >= min[1] && pos[1] <= max[1] &&
  106.             pos[2] >= min[2] && pos[2] <= max[2]);
  107. }
  108.  
  109. // Give penalty score for not defusing
  110. adjustScore(id, points) {
  111.     new score = get_user_frags(id) + points;
  112.     set_user_frags(id, score);
  113.  
  114.     // Display to all about the penalty
  115.     if (points < 0) { // penalty
  116.         client_print(0, print_chat, "+1 death for '%s' for not defusing", get_user_name(id));
  117.     }
  118. }
  119.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment