Advertisement
ufame

core

Dec 11th, 2023
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.85 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <reapi>
  4.  
  5. #include <config>
  6.  
  7. const TASK_ID_START_INFECT = 10003;
  8.  
  9. enum PlayerVariables {
  10.   bool: affected
  11. };
  12.  
  13. enum GameEvents {
  14.   game_started,
  15.   player_affected,
  16.   player_infected,
  17.   player_cured
  18. };
  19.  
  20. new bool: GameStarted;
  21.  
  22. new GlobalGameEvents[GameEvents];
  23. new GlobalPlayerVariables[MAX_PLAYERS + 1][PlayerVariables];
  24.  
  25. public plugin_init() {
  26.   register_plugin("Bio: Core", "1.0.0", "ufame");
  27.  
  28.   CreateEvents();
  29.  
  30.   RegisterHookChain(RG_CBasePlayer_Spawn, "HookEvent_PlayerSpawn", .post = 1);
  31.   RegisterHookChain(RG_CSGameRules_RestartRound, "HookEvent_RestartRound", .post = 1);
  32.   RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "HookEvent_OnRoundFreezeEnd", .post = 1);
  33. }
  34.  
  35. public plugin_natives() {
  36.   register_native("bio_is_game_started", "native_is_game_started");
  37.   register_native("bio_is_player_affected", "native_is_player_affected");
  38. }
  39.  
  40. public bool: native_is_game_started() {
  41.   return GameStarted;
  42. }
  43.  
  44. public bool: native_is_player_affected() {
  45.   enum {
  46.     arg_player_id = 1
  47.   };
  48.  
  49.   new player_id = get_param(arg_player_id);
  50.   return GlobalPlayerVariables[player_id][affected];
  51. }
  52.  
  53. CreateEvents() {
  54.   GlobalGameEvents[game_started] = CreateMultiForward("bio_game_started", ET_IGNORE);
  55.   GlobalGameEvents[player_affected] = CreateMultiForward("bio_player_affected", ET_IGNORE, FP_CELL);
  56.   GlobalGameEvents[player_infected] = CreateMultiForward("bio_player_infected", ET_IGNORE, FP_CELL);
  57.   GlobalGameEvents[player_cured] = CreateMultiForward("bio_player_cured", ET_IGNORE, FP_CELL);
  58. }
  59.  
  60. public client_disconnected(player_id) {
  61.   GlobalPlayerVariables[player_id][affected] = false;
  62. }
  63.  
  64. public HookEvent_RestartRound() {
  65.   for (new player_id = 1; player_id <= MaxClients; player_id++) {
  66.     if (!is_user_connected(player_id))
  67.       continue;
  68.  
  69.     rg_remove_all_items(player_id);
  70.     rg_give_item(player_id, "weapon_knife");
  71.  
  72.     SetPlayerHuman(player_id);
  73.   }
  74. }
  75.  
  76. public HookEvent_OnRoundFreezeEnd() {
  77.   new playersCount = get_playersnum_ex(GetPlayers_ExcludeDead);
  78.  
  79.   if (playersCount < config_get_value(min_players)) {
  80.     client_print_color(0, print_team_default, "^4--- ^1Слишком мало игроков для старта инфекции.");
  81.  
  82.     return;
  83.   }
  84.  
  85.   new Float: minZombiesPercent = config_get_value(min_zombies_percent);
  86.   new Float: maxZombiesPercent = config_get_value(max_zombies_percent);
  87.  
  88.   new Float: zombiesPercent = CalculateZombiesPercent(playersCount, minZombiesPercent, maxZombiesPercent);
  89.  
  90.   MakeAffectedPlayers(zombiesPercent);
  91.   set_task_ex(config_get_value(infection_time), "StartInfection", TASK_ID_START_INFECT);
  92. }
  93.  
  94. public HookEvent_PlayerSpawn(const player_id) {
  95.   if (!is_user_alive(player_id))
  96.     return;
  97.  
  98.   if (GameStarted && config_get_value(respawn_as_zombie))
  99.     SetPlayerZombie(player_id);
  100. }
  101.  
  102. public StartInfection() {
  103.   for (new player_id = 1; player_id <= MaxClients; player_id++) {
  104.     if (!is_user_alive(player_id))
  105.       continue;
  106.  
  107.     if (GlobalPlayerVariables[player_id][affected]) {
  108.       SetPlayerZombie(player_id);
  109.       GlobalPlayerVariables[player_id][affected] = false;
  110.  
  111.       continue;
  112.     }
  113.  
  114.     SetPlayerHuman(player_id);
  115.   }
  116.  
  117.   GameStarted = true;
  118.   ExecuteForward(GlobalGameEvents[game_started]);
  119. }
  120.  
  121. MakeAffectedPlayers(const Float: zombies_percent) {
  122.   new players[MAX_PLAYERS], playersCount;
  123.  
  124.   get_players_ex(players, playersCount, GetPlayers_ExcludeDead);
  125.   SortIntegers(players, playersCount, Sort_Random);
  126.  
  127.   new zombiesCount = floatround(playersCount / 100.0 * zombies_percent, floatround_ceil);
  128.  
  129.   client_print_color(0, print_team_default, "^4--- ^1Количество зомби на раунд: ^3%d ^1(^3%.1f^1)", zombiesCount, zombies_percent);
  130.  
  131.   for (new i; i <= zombiesCount; i++) {
  132.     new player_id = players[i];
  133.  
  134.     GlobalPlayerVariables[player_id][affected] = true;
  135.     ExecuteForward(GlobalGameEvents[player_affected], _, player_id);
  136.   }
  137. }
  138.  
  139. SetPlayerHuman(const player_id, const bool: change_team = false) {
  140.   rg_reset_user_model(player_id);
  141.  
  142.   if (change_team)
  143.     rg_set_user_team(player_id, TEAM_CT, .check_win_conditions = true);
  144.  
  145.   ExecuteForward(GlobalGameEvents[player_cured], _, player_id);
  146. }
  147.  
  148. SetPlayerZombie(const player_id) {
  149.   rg_set_user_team(player_id, TEAM_TERRORIST, .check_win_conditions = true);
  150.  
  151.   rg_remove_all_items(player_id);
  152.   rg_give_item(player_id, "weapon_knife");
  153.  
  154.   ExecuteForward(GlobalGameEvents[player_infected], _, player_id);
  155. }
  156.  
  157. Float: CalculateZombiesPercent(
  158.   const playersCount,
  159.   const Float: minZombiesPercent,
  160.   const Float: maxZombiesPercent
  161. ) {
  162.   new Float: dynamicZombiesPercent =
  163.     minZombiesPercent + (playersCount / MaxClients - 1) * (maxZombiesPercent - minZombiesPercent);
  164.  
  165.   if (dynamicZombiesPercent > maxZombiesPercent)
  166.     dynamicZombiesPercent = maxZombiesPercent;
  167.  
  168.   return dynamicZombiesPercent;
  169. }
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement