Approved Class: Heroine

Gameplay Addons
Post Reply
User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 541
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 44 times
Age: 19
Contact:

Class: Heroine

#1

Post by Jack GamePlay » 8 Months Ago

Class: Heroine

Description:

This is heroine 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. Knockback.
  7. Multijump.
Cvars:
  1. ze_heroine_min_zombies // Minimum players to start choosing random player to be heroine? (D: 3).
  2. ze_heroine_knockback // How much knockback does the heroine get? (D: 1.5).
  3. ze_heroine_speed // How much speed does the heroine gain? (D: 400) (Note: Check 'ze_set_human_speed_factor' usage.
  4. ze_heroine_gravity // How much will the heroine's gravity be? (D: 0.08) (Note: The value you set will be the heroine's gravity, no increase or decrease.
Extra cvars:
  1. ze_screen_fade // Allow screen fade on turning to heroine? (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 heroine is (D: 255).
    1. #define HUDMESSAGE_RED
  4. Green color value used in the hud appears to notify server's players who the heroine is (D: 255).
    1. #define HUDMESSAGE_GREEN
  5. Blue color value used in the hud appears to notify server's players who the heroine is (D: 255).
    1. #define HUDMESSAGE_BLUE
Natives:
  1. Checks whether the player is heroine or not (id is player's index).
    1. native ze_is_user_heroine(id)
  2. Sets & unsets the player (id is player's index || if set = 1 --> set || if set = 0 --> unset).
    1. native ze_set_user_heroine(id, set)
Changelog:
  • Spoiler!
    Image
    • First Release.
    Image
    • Add speed, gravity & knockback.
    Image [Current Version]
    • Fixed speed & gravity.
    • Add screen fade effect on turning to heroine.
    • 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_HEROINE 20019419
  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 szHeroineModel[][] = { "mummmy" }
  30.  
  31. new bool:g_bHeroine[33]
  32. new Array:g_szHeroineModel
  33. new iHud, g_iMsgScreenFade
  34. new g_pCvarHeroineMinZombies,
  35.     g_pCvarHeroineGravity,
  36.     g_pCvarHeroineSpeed,
  37.     g_pCvarHeroineKnockback,
  38.     g_pCvarScreenFade,
  39.     g_pCvarScreenFadeColor[3]
  40.  
  41. public plugin_natives()
  42. {
  43.     register_native("ze_is_user_heroine", "native_ze_is_user_heroine", 1)
  44.     register_native("ze_set_user_heroine", "native_ze_set_user_heroine", 1)
  45. }
  46.  
  47. public plugin_precache()
  48. {
  49.     g_szHeroineModel = ArrayCreate(32, 1)
  50.  
  51.     amx_load_setting_string_arr(ZE_SETTING_RESOURCES, "Player Models", "HEROINE", g_szHeroineModel)
  52.    
  53.     new iIndex, PlayerModel[32], Model_Path[128]
  54.  
  55.     if (ArraySize(g_szHeroineModel) == 0)
  56.     {
  57.         for (iIndex = 0; iIndex < sizeof(szHeroineModel); iIndex++)
  58.             ArrayPushString(g_szHeroineModel, szHeroineModel[iIndex])
  59.        
  60.         amx_save_setting_string_arr(ZE_SETTING_RESOURCES, "Player Models", "HEROINE", g_szHeroineModel)
  61.     }
  62.  
  63.     for (iIndex = 0; iIndex < ArraySize(g_szHeroineModel); iIndex++)
  64.     {
  65.         ArrayGetString(g_szHeroineModel, 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: Heroine", "1.2", "Jack GamePlay")
  74.    
  75.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage")
  76.    
  77.     g_pCvarHeroineMinZombies = register_cvar("ze_heroine_min_zombies", "3")
  78.     g_pCvarHeroineSpeed = register_cvar("ze_heroine_speed", "400")
  79.     g_pCvarHeroineGravity = register_cvar("ze_heroine_gravity", ".08")
  80.     g_pCvarHeroineKnockback = register_cvar("ze_heroine_knockback", "600.0")
  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_fadeblue", "0")
  86.    
  87.     iHud = CreateHudSyncObj()
  88.  
  89.     g_iMsgScreenFade = get_user_msgid("ScreenFade")
  90. }
  91.  
  92. public ze_zombie_appear()
  93. {
  94.     set_task(5.0, "Make_Heroine_Task", TASK_MAKE_HEROINE)
  95. }
  96.  
  97. public Make_Heroine_Task(taskid)
  98. {  
  99.     new id, Zombies = ze_get_zombies_number()
  100.    
  101.     if (Zombies < get_pcvar_num(g_pCvarHeroineMinZombies))
  102.     {
  103.         ze_colored_print(0, "!tThere must be at least !y[!g%i!y] !tzombies to activate special class!y.", get_pcvar_num(g_pCvarHeroineMinZombies))
  104.         remove_task(taskid)
  105.         return
  106.     }
  107.  
  108.     id = GetRandomHeroine(random_num(1, Zombies))
  109.     Set_User_Heroine(id)
  110.     remove_task(taskid)
  111.     return
  112. }
  113.  
  114. public Set_User_Heroine(id)
  115. {
  116.     new HeroineModel[32], Heroine_Name[32]
  117.    
  118.     if (!ze_is_user_zombie(id))
  119.         ze_set_user_zombie(id)
  120.  
  121.     g_bHeroine[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_pCvarHeroineGravity) > 0.0)
  131.     {
  132.         set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHeroineGravity))
  133.     }
  134.     if (get_pcvar_num(g_pCvarHeroineSpeed) > 0.0)
  135.     {
  136.         ze_set_zombie_speed(id, get_pcvar_num(g_pCvarHeroineSpeed))
  137.     }
  138.  
  139.     ArrayGetString(g_szHeroineModel, random_num(0, ArraySize(g_szHeroineModel) - 1), HeroineModel, charsmax(HeroineModel))
  140.     rg_set_user_model(id, HeroineModel)
  141.     get_user_name(id, Heroine_Name, charsmax(Heroine_Name))
  142.     set_hudmessage(HUDMESSAGE_RED, HUDMESSAGE_GREEN, HUDMESSAGE_BLUE, -1.0, 0.15, 1, 2.0, 2.0)
  143.     ShowSyncHudMsg(0, iHud, "%s BECAME HEROIN!!!", Heroine_Name)
  144.     ze_colored_print(id, "!tYou became !gHeroine!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_Heroine(id)
  161. {
  162.     if (g_bHeroine[id])
  163.     {
  164.         g_bHeroine[id] = false
  165.  
  166.         if (get_pcvar_num(g_pCvarHeroineSpeed) > 0.0)
  167.         {
  168.             ze_reset_zombie_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_Heroine(id)
  183.     remove_task(TASK_MAKE_HEROINE)
  184. }
  185.  
  186. public ze_user_infected(victim)
  187. {
  188.     if (!is_user_alive(victim))
  189.         return
  190.        
  191.     Unset_User_Heroine(victim)
  192. }
  193.  
  194. public ze_user_humanized(id)
  195. {
  196.     if (!is_user_alive(id))
  197.         return
  198.        
  199.     Unset_User_Heroine(id)
  200. }
  201.  
  202. public Fw_TakeDamage(victim, inflector, attacker)
  203. {
  204.     if (victim == attacker || !is_user_alive(victim) || !is_user_alive(attacker) || !attacker)
  205.         return HC_CONTINUE
  206.  
  207.     if (g_bHeroine[victim] && get_pcvar_float(g_pCvarHeroineKnockback) > 0.0)
  208.     {
  209.         set_member(victim, m_flVelocityModifier, 1.0)
  210.        
  211.         static Float:flOrigin[3]
  212.         pev(attacker, pev_origin, flOrigin)
  213.         Set_Knockback(victim, flOrigin, get_pcvar_float(g_pCvarHeroineKnockback), 2)
  214.     }
  215.  
  216.     return HC_CONTINUE
  217. }
  218.  
  219. public ze_roundend()
  220. {
  221.     for (new id = 0; id <= get_member_game(m_nMaxPlayers); id++)
  222.     {
  223.         if (!g_bHeroine[id])
  224.             continue
  225.            
  226.         Unset_User_Heroine(id)
  227.         remove_task(TASK_MAKE_HEROINE)
  228.     }
  229. }
  230.  
  231. public native_ze_is_user_heroine(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_bHeroine[id]
  240. }
  241.  
  242. public native_ze_set_user_heroine(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_bHeroine[id])
  253.         {
  254.             log_error(AMX_ERR_NATIVE, "[ZE] Player isn't heroine (%d).", id)
  255.             return false
  256.         }
  257.        
  258.         Unset_User_Heroine(id)
  259.         return true
  260.     }
  261.  
  262.     if (set)
  263.     {
  264.         if (g_bHeroine[id])
  265.         {
  266.             log_error(AMX_ERR_NATIVE, "[ZE] Player is heroine (%d).", id)
  267.             return false
  268.         }
  269.  
  270.         Set_User_Heroine(id)
  271.         return true
  272.     }
  273.  
  274.     return false
  275. }
  276.  
  277. stock GetRandomHeroine(target_index)
  278. {
  279.     new iAliveZ, 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.             iAliveZ++
  285.        
  286.         if (iAliveZ == target_index)
  287.             return id
  288.     }
  289.     return -1
  290. }
Not interested in CS/Pawn anymore.
Accepting web projects.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest