Approved Class: Hero

Plug-ins compatibility with Zombie Escape 1.x only!


Post Reply
User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

Class: Hero

#1

Post by Night Fury » 5 years ago

Class: Hero

Description:

This is hero class. An addition class for zombie escape mod. This plugin chooses a player randomly and gives him extra features for 1 round. Some of the features are:
  1. Speed.
  2. Gravity.
  3. Extra damage.
  4. Different model.
  5. Parachute.
  6. Multijump.
Cvars:
  1. ze_hero_min_humans // Minimum players to start choosing random player to be hero? (D: 10).
  2. ze_hero_damage // How much damage does the hero get? (D: 1.5).
  3. ze_hero_speed // How much speed does the hero gain? (D: 300) (Note: Check 'ze_set_human_speed_factor' usage.
  4. ze_hero_gravity // How much will the hero's gravity be? (D: 1.2) (Note: The value you set will be the hero's gravity, no increase or decrease.
Extra cvars:
  1. ze_screen_fade // Allow screen fade on turning to hero? (0 = Disable || 1 = Enable) (D: 1).
  2. ze_screen_fade_red // How much the red color will be? (D: 0).
  3. ze_screen_fade_green // How much the green color will be? (D: 150).
  4. ze_screen_fade_blue // How much the blue color will be? (D: 0).
Defines:
  1. Uncomment to use parachute.
    1. //#define PARACHUTE
  2. Uncomment to use multijump.
    1. //#define MULTIJUMP
  3. Red color value used in the hud appears to notify server's players who the hero is (D: 255).
    1. #define HUDMESSAGE_RED
  4. Green color value used in the hud appears to notify server's players who the hero is (D: 255).
    1. #define HUDMESSAGE_GREEN
  5. Blue color value used in the hud appears to notify server's players who the hero is (D: 255).
    1. #define HUDMESSAGE_BLUE
Natives:
  1. Checks whether the player is hero or not (id is player's index).
    1. native ze_is_user_hero(id)
  2. Sets & unsets the player (id is player's index || if set = 1 --> set || if set = 0 --> unset).
    1. native ze_set_user_hero(id, set)
Changelog:
  • Spoiler!
    Image
    • First Release.
    Image
    • Add speed & gravity.
    Image [Current Version]
    • Fixed speed & gravity.
    • Add screen fade effect on turning to hero.
    • Added new natives.
    • Minor bug fixes.
    • New code style.

Code:
  1. // Uncomment to use parachute
  2. //#define PARACHUTE
  3. // Uncomment to use multijump
  4. //#define MULTIJUMP
  5.  
  6. #include <zombie_escape>
  7. #if defined PARACHUTE
  8.     #include <ze_parachute>
  9. #endif
  10. #if defined MULTIJUMP
  11.     #include <ze_multijump>
  12. #endif
  13.  
  14. #define TASK_MAKE_HERO 10014949
  15. #define HUDMESSAGE_RED 255
  16. #define HUDMESSAGE_GREEN 255
  17. #define HUDMESSAGE_BLUE 255
  18. #define FFADE_IN 0x0000
  19. #define UNIT_SECOND (1<<12)
  20.  
  21. enum {
  22.     Red = 0,
  23.     Green,
  24.     Blue
  25. }
  26.  
  27. new const ZE_SETTING_RESOURCES[] = "zombie_escape.ini"
  28.  
  29. new const szHeroModel[][] = { "vip" }
  30.  
  31. new bool:g_bHero[33]
  32. new Array:g_szHeroModel
  33. new iHud, g_iMsgScreenFade
  34. new g_pCvarHeroMinHumans,
  35.     g_pCvarHeroDamage,
  36.     g_pCvarHeroGravity,
  37.     g_pCvarHeroSpeed,
  38.     g_pCvarScreenFade,
  39.     g_pCvarScreenFadeColor[3]
  40.  
  41. public plugin_natives()
  42. {
  43.     register_native("ze_is_user_hero", "native_ze_is_user_hero", 1)
  44.     register_native("ze_set_user_hero", "native_ze_set_user_hero", 1)
  45. }
  46.  
  47. public plugin_precache()
  48. {
  49.     g_szHeroModel = ArrayCreate(32, 1)
  50.  
  51.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Player Models", "HERO", g_szHeroModel)
  52.    
  53.     new iIndex, PlayerModel[32], Model_Path[128]
  54.  
  55.     if (ArraySize(g_szHeroModel) == 0)
  56.     {
  57.         for (iIndex = 0; iIndex < sizeof(szHeroModel); iIndex++)
  58.             ArrayPushString(g_szHeroModel, szHeroModel[iIndex])
  59.        
  60.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Player Models", "HERO", g_szHeroModel)
  61.     }
  62.  
  63.     for (iIndex = 0; iIndex < ArraySize(g_szHeroModel); iIndex++)
  64.     {
  65.         ArrayGetString(g_szHeroModel, iIndex, PlayerModel, charsmax(PlayerModel))
  66.         formatex(Model_Path, charsmax(Model_Path), "models/player/%s/%s.mdl", PlayerModel, PlayerModel)
  67.         precache_model(Model_Path)
  68.     }
  69. }
  70.  
  71. public plugin_init()
  72. {
  73.     register_plugin("[ZE] Addons: Hero", "1.2", "Jack GamePlay")
  74.    
  75.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  76.    
  77.     g_pCvarHeroMinHumans = register_cvar("ze_hero_min_humans", "10")
  78.     g_pCvarHeroDamage = register_cvar("ze_hero_damage", "1.5")
  79.     g_pCvarHeroSpeed = register_cvar("ze_hero_speed", "300")
  80.     g_pCvarHeroGravity = register_cvar("ze_hero_gravity", "1.2")
  81.  
  82.     g_pCvarScreenFade = register_cvar("ze_screen_fade", "1")
  83.     g_pCvarScreenFadeColor[Red] = register_cvar("ze_screen_fade_red", "0")
  84.     g_pCvarScreenFadeColor[Green] = register_cvar("ze_screen_fade_green", "150")
  85.     g_pCvarScreenFadeColor[Blue] = register_cvar("ze_screen_fade_blue", "0")
  86.    
  87.     iHud = CreateHudSyncObj()
  88.  
  89.     g_iMsgScreenFade = get_user_msgid("ScreenFade")
  90. }
  91.  
  92. public ze_zombie_appear()
  93. {
  94.     set_task(2.5, "Make_Hero_Task", TASK_MAKE_HERO)
  95. }
  96.  
  97. public Make_Hero_Task(taskid)
  98. {
  99.     new id, Humans = ze_get_humans_number()
  100.    
  101.     if (Humans < get_pcvar_num(g_pCvarHeroMinHumans))
  102.     {
  103.         ze_colored_print(0, "!tThere must be at least !y[!g%i!y] !thumans to activate special class!y.", get_pcvar_num(g_pCvarHeroMinHumans))
  104.         remove_task(taskid)
  105.         return
  106.     }
  107.  
  108.     id = GetRandomHero(random_num(1, Humans))
  109.     Set_User_Hero(id)
  110.     remove_task(taskid)
  111.     return
  112. }
  113.  
  114. public Set_User_Hero(id)
  115. {
  116.     new HeroModel[32], HeroName[32]
  117.    
  118.     if (ze_is_user_zombie(id))
  119.         ze_set_user_human(id)
  120.  
  121.     g_bHero[id] = true
  122.  
  123.     #if defined PARACHUTE
  124.         ze_give_user_parachute(id)
  125.     #endif
  126.     #if defined MULTIJUMP
  127.         ze_give_user_multijump(id)
  128.     #endif
  129.  
  130.     if (get_pcvar_float(g_pCvarHeroGravity) > 0.0)
  131.     {
  132.         set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHeroGravity))
  133.     }
  134.     if (get_pcvar_num(g_pCvarHeroSpeed) > 0.0)
  135.     {
  136.         ze_set_human_speed_factor(id, get_pcvar_num(g_pCvarHeroSpeed))
  137.     }
  138.  
  139.     ArrayGetString(g_szHeroModel, random_num(0, ArraySize(g_szHeroModel) - 1), HeroModel, charsmax(HeroModel))
  140.     rg_set_user_model(id, HeroModel)
  141.     get_user_name(id, HeroName, charsmax(HeroName))
  142.     set_hudmessage(HUDMESSAGE_RED, HUDMESSAGE_GREEN, HUDMESSAGE_BLUE, -1.0, 0.15, 1, 2.0, 2.0)
  143.     ShowSyncHudMsg(0, iHud, "%s BECAME HERO!!!", HeroName)
  144.     ze_colored_print(id, "!tYou became !gHero!y.")
  145.    
  146.     if (get_pcvar_num(g_pCvarScreenFade))
  147.     {
  148.         message_begin(MSG_ONE_UNRELIABLE, g_iMsgScreenFade, _, id)
  149.         write_short(UNIT_SECOND) // duration
  150.         write_short(0) // hold time
  151.         write_short(FFADE_IN) // fade type
  152.         write_byte(get_pcvar_num(g_pCvarScreenFadeColor[Red])) // r
  153.         write_byte(get_pcvar_num(g_pCvarScreenFadeColor[Green])) // g
  154.         write_byte(get_pcvar_num(g_pCvarScreenFadeColor[Blue])) // b
  155.         write_byte (255) // alpha
  156.         message_end()
  157.     }
  158. }
  159.  
  160. public Unset_User_Hero(id)
  161. {
  162.     if (g_bHero[id])
  163.     {
  164.         g_bHero[id] = false
  165.  
  166.         if (get_pcvar_num(g_pCvarHeroSpeed) > 0.0)
  167.         {
  168.             ze_reset_human_speed(id)
  169.         }
  170.  
  171.         #if defined PARACHUTE
  172.             ze_remove_user_parachute(id)
  173.         #endif
  174.         #if defined MULTIJUMP
  175.             ze_remove_user_multijump(id)
  176.         #endif
  177.     }
  178. }
  179.  
  180. public client_disconnected(id)
  181. {
  182.     Unset_User_Hero(id)
  183.     remove_task(TASK_MAKE_HERO)
  184. }
  185.  
  186. public ze_user_infected(victim)
  187. {
  188.     if (!is_user_alive(victim))
  189.         return
  190.        
  191.     Unset_User_Hero(victim)
  192. }
  193.  
  194. public ze_user_humanized(id)
  195. {
  196.     if (!is_user_alive(id))
  197.         return
  198.        
  199.     Unset_User_Hero(id)
  200. }
  201.  
  202. public Fw_TakeDamage_Post(victim, inflector, attacker, Float:Damage)
  203. {
  204.     if (victim == attacker || !is_user_alive(victim) || !is_user_alive(attacker) || !attacker || ze_is_user_zombie(attacker))
  205.         return HC_CONTINUE
  206.  
  207.     if (g_bHero[attacker])
  208.     {
  209.         if (inflector == attacker)
  210.         {
  211.             SetHookChainArg(4, ATYPE_FLOAT, Damage * get_pcvar_float(g_pCvarHeroDamage))
  212.             return HC_CONTINUE
  213.         }
  214.     }
  215.  
  216.     return HC_SUPERCEDE
  217. }
  218.  
  219. public ze_roundend()
  220. {
  221.     for (new id = 0; id <= get_member_game(m_nMaxPlayers); id++)
  222.     {
  223.         if (!g_bHero[id])
  224.             continue
  225.            
  226.         Unset_User_Hero(id)
  227.         remove_task(TASK_MAKE_HERO)
  228.     }
  229. }
  230.  
  231. public native_ze_is_user_hero(id)
  232. {
  233.     if (!is_user_connected(id))
  234.     {
  235.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  236.         return false
  237.     }
  238.  
  239.     return g_bHero[id]
  240. }
  241.  
  242. public native_ze_set_user_hero(id, set)
  243. {
  244.     if (!is_user_connected(id))
  245.     {
  246.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d).", id)
  247.         return false
  248.     }
  249.  
  250.     if (!set)
  251.     {
  252.         if (!g_bHero[id])
  253.         {
  254.             log_error(AMX_ERR_NATIVE, "[ZE] Player isn't hero (%d).", id)
  255.             return false
  256.         }
  257.        
  258.         Unset_User_Hero(id)
  259.         return true
  260.     }
  261.  
  262.     if (set)
  263.     {
  264.         if (g_bHero[id])
  265.         {
  266.             log_error(AMX_ERR_NATIVE, "[ZE] Player is hero (%d).", id)
  267.             return false
  268.         }
  269.  
  270.         Set_User_Hero(id)
  271.         return true
  272.     }
  273.  
  274.     return false
  275. }
  276.  
  277. stock GetRandomHero(target_index)
  278. {
  279.     new iAliveH, id
  280.    
  281.     for (id = 1; id <= get_member_game(m_nMaxPlayers); id++)
  282.     {
  283.         if (is_user_alive(id) && !ze_is_user_zombie(id))
  284.             iAliveH++
  285.        
  286.         if (iAliveH == target_index)
  287.             return id
  288.     }
  289.     return -1
  290. }
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#2

Post by czirimbolo » 5 years ago

where can I find the models?
Image

User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

#3

Post by Night Fury » 5 years ago

czirimbolo wrote: 5 years ago where can I find the models?
I have not added models.
Once you do run to the plugin for the first time, it will automatically make a path in zombie_escape.ini in [Player Models] section with name "HERO"
It will be something like this:
HERO = vip
You can change vip to your model
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 0 guests