Replace disconnected player
Posted: 06 Feb 2019, 16:29
| Description:
- This plugin is going to replace the disconnected player' with another randomly chosen player to be the zombie/human instead of his place.
- #include <zombie_escape>
- public plugin_init()
- {
- register_plugin("[ZE] Addon: Replace disconnected players", "1.0", "Jack")
- }
- public ze_player_disconnect(id)
- {
- // Game wasn't started? || Wasn't alive? || Last player?
- if (!ze_is_game_started() || !is_user_alive(id) || GetAllAlivePlayersNum() <= 1)
- return 0; // Continue
- // We are in freeze time?
- if (!get_member_game(m_bFreezePeriod))
- {
- new iIndex
- // Last Zombie
- if (ze_is_user_zombie(id) && ze_get_zombies_number() == 1)
- {
- if (ze_get_humans_number() == 1)
- return 0; // Continue
- // Find replacement
- while ((iIndex = GetRandomAlive(random_num(1, ze_get_humans_number()))) == id) { /* keep looping */ }
- new name[32]
- get_user_name(iIndex, name, charsmax(name))
- ze_colored_print(0, "!tThe last zombie has left!y. !g%s !thas been the new zombie!y.", name)
- ze_set_user_zombie(iIndex)
- UpdateOrigin(iIndex, id)
- return 1; // Stop main function
- }
- // Last Human
- else if (!ze_is_user_zombie(id) && ze_get_humans_number() == 1)
- {
- if (ze_get_zombies_number() == 1)
- return 0;
- // Find replacement
- while ((iIndex = GetRandomAlive(random_num(1, ze_get_zombies_number()))) == id) { /* keep looping */ }
- new name[32]
- get_user_name(iIndex, name, charsmax(name))
- ze_colored_print(0, "!tThe last human has left!y. !g%s !thas been the new human!y.", name)
- ze_set_user_human(iIndex)
- UpdateOrigin(iIndex, id)
- return 1; // Stop main function
- }
- }
- return 0; // Continue
- }
- UpdateOrigin(iIndex, id)
- {
- new Float:flOrigin[3]
- get_entvar(id, var_origin, flOrigin)
- set_entvar(iIndex, var_origin, flOrigin)
- }