Page 1 of 1

Replace disconnected player

Posted: 06 Feb 2019, 16:29
by Night Fury
| Description:
  • This plugin is going to replace the disconnected player' with another randomly chosen player to be the zombie/human instead of his place.
| Code:
    1. #include <zombie_escape>
    2.  
    3. public plugin_init()
    4. {
    5.     register_plugin("[ZE] Addon: Replace disconnected players", "1.0", "Jack")
    6. }
    7.  
    8. public ze_player_disconnect(id)
    9. {
    10.     // Game wasn't started? ||  Wasn't alive? || Last player?
    11.     if (!ze_is_game_started() || !is_user_alive(id) || GetAllAlivePlayersNum() <= 1)
    12.         return 0; // Continue
    13.  
    14.     // We are in freeze time?
    15.     if (!get_member_game(m_bFreezePeriod))
    16.     {
    17.         new iIndex
    18.         // Last Zombie
    19.         if (ze_is_user_zombie(id) && ze_get_zombies_number() == 1)
    20.         {
    21.             if (ze_get_humans_number() == 1)
    22.                 return 0; // Continue
    23.            
    24.             // Find replacement
    25.             while ((iIndex = GetRandomAlive(random_num(1, ze_get_humans_number()))) == id) { /* keep looping */ }
    26.            
    27.             new name[32]
    28.             get_user_name(iIndex, name, charsmax(name))
    29.             ze_colored_print(0, "!tThe last zombie has left!y. !g%s !thas been the new zombie!y.", name)
    30.             ze_set_user_zombie(iIndex)
    31.             UpdateOrigin(iIndex, id)
    32.            
    33.             return 1; // Stop main function
    34.         }
    35.         // Last Human
    36.         else if (!ze_is_user_zombie(id) && ze_get_humans_number() == 1)
    37.         {
    38.             if (ze_get_zombies_number() == 1)
    39.                 return 0;
    40.            
    41.             // Find replacement
    42.             while ((iIndex = GetRandomAlive(random_num(1, ze_get_zombies_number()))) == id) { /* keep looping */ }
    43.            
    44.             new name[32]
    45.             get_user_name(iIndex, name, charsmax(name))
    46.             ze_colored_print(0, "!tThe last human has left!y. !g%s !thas been the new human!y.", name)
    47.             ze_set_user_human(iIndex)
    48.             UpdateOrigin(iIndex, id)
    49.            
    50.             return 1; // Stop main function
    51.         }
    52.     }
    53.    
    54.     return 0; // Continue
    55. }
    56.  
    57. UpdateOrigin(iIndex, id)
    58. {
    59.     new Float:flOrigin[3]
    60.     get_entvar(id, var_origin, flOrigin)
    61.     set_entvar(iIndex, var_origin, flOrigin)
    62. }

Re: Replace disconnected player

Posted: 09 Feb 2019, 08:38
by th3_king
Good Work,
New Idea: Better than choosing randomly, >> Choose the player who has the lowest played time << You can also make the both Ideas ( Random Choose And My Idea with Cvar ).