Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <reapi>
- #include <config>
- const TASK_ID_START_INFECT = 10003;
- enum PlayerVariables {
- bool: affected
- };
- enum GameEvents {
- game_started,
- player_affected,
- player_infected,
- player_cured
- };
- new bool: GameStarted;
- new GlobalGameEvents[GameEvents];
- new GlobalPlayerVariables[MAX_PLAYERS + 1][PlayerVariables];
- public plugin_init() {
- register_plugin("Bio: Core", "1.0.0", "ufame");
- CreateEvents();
- RegisterHookChain(RG_CBasePlayer_Spawn, "HookEvent_PlayerSpawn", .post = 1);
- RegisterHookChain(RG_CSGameRules_RestartRound, "HookEvent_RestartRound", .post = 1);
- RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "HookEvent_OnRoundFreezeEnd", .post = 1);
- }
- public plugin_natives() {
- register_native("bio_is_game_started", "native_is_game_started");
- register_native("bio_is_player_affected", "native_is_player_affected");
- }
- public bool: native_is_game_started() {
- return GameStarted;
- }
- public bool: native_is_player_affected() {
- enum {
- arg_player_id = 1
- };
- new player_id = get_param(arg_player_id);
- return GlobalPlayerVariables[player_id][affected];
- }
- CreateEvents() {
- GlobalGameEvents[game_started] = CreateMultiForward("bio_game_started", ET_IGNORE);
- GlobalGameEvents[player_affected] = CreateMultiForward("bio_player_affected", ET_IGNORE, FP_CELL);
- GlobalGameEvents[player_infected] = CreateMultiForward("bio_player_infected", ET_IGNORE, FP_CELL);
- GlobalGameEvents[player_cured] = CreateMultiForward("bio_player_cured", ET_IGNORE, FP_CELL);
- }
- public client_disconnected(player_id) {
- GlobalPlayerVariables[player_id][affected] = false;
- }
- public HookEvent_RestartRound() {
- for (new player_id = 1; player_id <= MaxClients; player_id++) {
- if (!is_user_connected(player_id))
- continue;
- rg_remove_all_items(player_id);
- rg_give_item(player_id, "weapon_knife");
- SetPlayerHuman(player_id);
- }
- }
- public HookEvent_OnRoundFreezeEnd() {
- new playersCount = get_playersnum_ex(GetPlayers_ExcludeDead);
- if (playersCount < config_get_value(min_players)) {
- client_print_color(0, print_team_default, "^4--- ^1Слишком мало игроков для старта инфекции.");
- return;
- }
- new Float: minZombiesPercent = config_get_value(min_zombies_percent);
- new Float: maxZombiesPercent = config_get_value(max_zombies_percent);
- new Float: zombiesPercent = CalculateZombiesPercent(playersCount, minZombiesPercent, maxZombiesPercent);
- MakeAffectedPlayers(zombiesPercent);
- set_task_ex(config_get_value(infection_time), "StartInfection", TASK_ID_START_INFECT);
- }
- public HookEvent_PlayerSpawn(const player_id) {
- if (!is_user_alive(player_id))
- return;
- if (GameStarted && config_get_value(respawn_as_zombie))
- SetPlayerZombie(player_id);
- }
- public StartInfection() {
- for (new player_id = 1; player_id <= MaxClients; player_id++) {
- if (!is_user_alive(player_id))
- continue;
- if (GlobalPlayerVariables[player_id][affected]) {
- SetPlayerZombie(player_id);
- GlobalPlayerVariables[player_id][affected] = false;
- continue;
- }
- SetPlayerHuman(player_id);
- }
- GameStarted = true;
- ExecuteForward(GlobalGameEvents[game_started]);
- }
- MakeAffectedPlayers(const Float: zombies_percent) {
- new players[MAX_PLAYERS], playersCount;
- get_players_ex(players, playersCount, GetPlayers_ExcludeDead);
- SortIntegers(players, playersCount, Sort_Random);
- new zombiesCount = floatround(playersCount / 100.0 * zombies_percent, floatround_ceil);
- client_print_color(0, print_team_default, "^4--- ^1Количество зомби на раунд: ^3%d ^1(^3%.1f^1)", zombiesCount, zombies_percent);
- for (new i; i <= zombiesCount; i++) {
- new player_id = players[i];
- GlobalPlayerVariables[player_id][affected] = true;
- ExecuteForward(GlobalGameEvents[player_affected], _, player_id);
- }
- }
- SetPlayerHuman(const player_id, const bool: change_team = false) {
- rg_reset_user_model(player_id);
- if (change_team)
- rg_set_user_team(player_id, TEAM_CT, .check_win_conditions = true);
- ExecuteForward(GlobalGameEvents[player_cured], _, player_id);
- }
- SetPlayerZombie(const player_id) {
- rg_set_user_team(player_id, TEAM_TERRORIST, .check_win_conditions = true);
- rg_remove_all_items(player_id);
- rg_give_item(player_id, "weapon_knife");
- ExecuteForward(GlobalGameEvents[player_infected], _, player_id);
- }
- Float: CalculateZombiesPercent(
- const playersCount,
- const Float: minZombiesPercent,
- const Float: maxZombiesPercent
- ) {
- new Float: dynamicZombiesPercent =
- minZombiesPercent + (playersCount / MaxClients - 1) * (maxZombiesPercent - minZombiesPercent);
- if (dynamicZombiesPercent > maxZombiesPercent)
- dynamicZombiesPercent = maxZombiesPercent;
- return dynamicZombiesPercent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement