Bomb Infection

Unpaid Requests, Public Plugins
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#11

Post by Raheem » 4 years ago

czirimbolo wrote: 4 years ago Thanks mate. In my opinion its too powerful item. So I have small request. If humans have more armor than 55 (>55), this bomb will not infect a human. Can you make it?
  1. #include <zombie_escape>
  2. #include <fun>
  3.  
  4. // Settings file
  5. new const ZE_SETTING_FILE[] = "zombie_escape.ini"
  6.  
  7. // Default sounds
  8. new const sound_grenade_infect_explode[][] = { "zombie_escape/grenade_infect.wav" }
  9. new const sound_grenade_infect_player[][] = { "scientist/scream20.wav" , "scientist/scream22.wav" , "scientist/scream05.wav" }
  10.  
  11. #define MODEL_MAX_LENGTH 64
  12. #define SOUND_MAX_LENGTH 64
  13. #define SPRITE_MAX_LENGTH 64
  14.  
  15. // Models
  16. new g_model_grenade_infect[MODEL_MAX_LENGTH] = "models/zombie_escape/v_grenade_infect.mdl"
  17.  
  18. // Sprites
  19. new g_sprite_grenade_trail[SPRITE_MAX_LENGTH] = "sprites/laserbeam.spr"
  20. new g_sprite_grenade_ring[SPRITE_MAX_LENGTH] = "sprites/shockwave.spr"
  21. new g_sprite_grenade_gibs[SPRITE_MAX_LENGTH] = "sprites/zombie_escape/infect_gibs.spr"
  22.  
  23. new Array:g_sound_grenade_infect_explode
  24. new Array:g_sound_grenade_infect_player
  25. new Array:g_sound_grenade_infect_gibs
  26.  
  27. // Explosion radius for custom grenades
  28. const Float:NADE_EXPLOSION_RADIUS = 240.0
  29.  
  30. // HACK: pev_ field used to store custom nade types and their values
  31. const PEV_NADE_TYPE = pev_flTimeStepSound
  32. const NADE_TYPE_INFECTION = 1111
  33.  
  34. new g_trailSpr, g_exploSpr, g_gibsSpr
  35.  
  36. new g_ItemID
  37. new g_InfectionBombCounter, cvar_infection_bomb_round_limit, cvar_infection_reduis
  38.  
  39. new bool:g_bHasInfection[33]
  40.  
  41. public plugin_init()
  42. {
  43.     register_plugin("[ZE] Item: Infection Bomb", ZE_VERSION, AUTHORS)
  44.    
  45.     register_forward(FM_SetModel, "fw_SetModel")
  46.     RegisterHam(Ham_Think, "grenade", "fw_ThinkGrenade")
  47.    
  48.     g_ItemID = ze_register_item("Infection Bomb", 50, 0)
  49.     cvar_infection_bomb_round_limit = register_cvar("ze_infection_bomb_round_limit", "3")
  50.     cvar_infection_reduis = register_cvar("ze_infection_bomb_reduis", "240")
  51. }
  52.  
  53. public plugin_precache()
  54. {
  55.     // Initialize arrays
  56.     g_sound_grenade_infect_explode = ArrayCreate(SOUND_MAX_LENGTH, 1)
  57.     g_sound_grenade_infect_player = ArrayCreate(SOUND_MAX_LENGTH, 1)
  58.     g_sound_grenade_infect_gibs = ArrayCreate(SOUND_MAX_LENGTH, 1)
  59.    
  60.     // Load from external file
  61.     amx_load_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT EXPLODE", g_sound_grenade_infect_explode)
  62.     amx_load_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT PLAYER", g_sound_grenade_infect_player)
  63.    
  64.     // If we couldn't load custom sounds from file, use and save default ones
  65.     new index
  66.     if (ArraySize(g_sound_grenade_infect_explode) == 0)
  67.     {
  68.         for (index = 0; index < sizeof sound_grenade_infect_explode; index++)
  69.             ArrayPushString(g_sound_grenade_infect_explode, sound_grenade_infect_explode[index])
  70.        
  71.         // Save to external file
  72.         amx_save_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT EXPLODE", g_sound_grenade_infect_explode)
  73.     }
  74.     if (ArraySize(g_sound_grenade_infect_player) == 0)
  75.     {
  76.         for (index = 0; index < sizeof sound_grenade_infect_player; index++)
  77.             ArrayPushString(g_sound_grenade_infect_player, sound_grenade_infect_player[index])
  78.        
  79.         // Save to external file
  80.         amx_save_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT PLAYER", g_sound_grenade_infect_player)
  81.     }
  82.    
  83.     // Load from external file, save if not found
  84.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Weapon Models", "GRENADE INFECT", g_model_grenade_infect, charsmax(g_model_grenade_infect)))
  85.         amx_save_setting_string(ZE_SETTING_FILE, "Weapon Models", "GRENADE INFECT", g_model_grenade_infect)
  86.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT TRAIL", g_sprite_grenade_trail, charsmax(g_sprite_grenade_trail)))
  87.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT TRAIL", g_sprite_grenade_trail)
  88.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT GIBS", g_sprite_grenade_gibs, charsmax(g_sprite_grenade_gibs)))
  89.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT GIBS", g_sprite_grenade_gibs)
  90.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "RING", g_sprite_grenade_ring, charsmax(g_sprite_grenade_ring)))
  91.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "RING", g_sprite_grenade_ring)
  92.    
  93.     // Precache sounds
  94.     new sound[SOUND_MAX_LENGTH]
  95.     for (index = 0; index < ArraySize(g_sound_grenade_infect_explode); index++)
  96.     {
  97.         ArrayGetString(g_sound_grenade_infect_explode, index, sound, charsmax(sound))
  98.         precache_sound(sound)
  99.     }
  100.     for (index = 0; index < ArraySize(g_sound_grenade_infect_player); index++)
  101.     {
  102.         ArrayGetString(g_sound_grenade_infect_player, index, sound, charsmax(sound))
  103.         precache_sound(sound)
  104.     }
  105.    
  106.     // Precache models
  107.     precache_model(g_model_grenade_infect)
  108.     g_trailSpr = precache_model(g_sprite_grenade_trail)
  109.     g_exploSpr = precache_model(g_sprite_grenade_ring)
  110.     g_gibsSpr = precache_model(g_sprite_grenade_gibs)
  111. }
  112.  
  113. public ze_game_started()
  114. {
  115.     g_InfectionBombCounter = 0
  116. }
  117.  
  118. public ze_select_item_pre(id, itemid)
  119. {
  120.     // This is not our item
  121.     if (itemid != g_ItemID)
  122.         return ZE_ITEM_AVAILABLE;
  123.    
  124.     // Available for Humans only, So don't show it for zombies
  125.     if (!ze_is_user_zombie(id))
  126.         return ZE_ITEM_DONT_SHOW
  127.    
  128.     // Display remaining item count for this round
  129.     static text[32]
  130.     formatex(text, charsmax(text), "[%d/%d]", g_InfectionBombCounter, get_pcvar_num(cvar_infection_bomb_round_limit))
  131.     ze_add_text_to_item(text)
  132.    
  133.     // Reached infection bomb limit for this round
  134.     if (g_InfectionBombCounter >= get_pcvar_num(cvar_infection_bomb_round_limit))
  135.         return ZE_ITEM_UNAVAILABLE;
  136.    
  137.     // Player already owns infection bomb
  138.     if (g_bHasInfection[id])
  139.         return ZE_ITEM_UNAVAILABLE;
  140.    
  141.     return ZE_ITEM_AVAILABLE
  142. }
  143.  
  144. public ze_select_item_post(player, itemid)
  145. {
  146.     if (itemid != g_ItemID)
  147.         return
  148.    
  149.     // Give infection bomb
  150.     give_item(player, "weapon_hegrenade")
  151.     g_InfectionBombCounter++
  152.     g_bHasInfection[player]
  153. }
  154.  
  155. public ze_user_humanized(id)
  156. {
  157.     // Remove custom grenade model
  158.     g_bHasInfection[id] = false
  159. }
  160.  
  161. public ze_user_infected(id, attacker)
  162. {
  163.     // Set custom grenade model
  164.     cs_set_player_view_model(id, CSW_HEGRENADE, g_model_grenade_infect)
  165. }
  166.  
  167. // Forward Set Model
  168. public fw_SetModel(entity, const model[])
  169. {
  170.     // We don't care
  171.     if (strlen(model) < 8)
  172.         return;
  173.    
  174.     // Narrow down our matches a bit
  175.     if (model[7] != 'w' || model[8] != '_')
  176.         return;
  177.    
  178.     // Get damage time of grenade
  179.     static Float:dmgtime
  180.     pev(entity, pev_dmgtime, dmgtime)
  181.    
  182.     // Grenade not yet thrown
  183.     if (dmgtime == 0.0)
  184.         return;
  185.    
  186.     // Grenade's owner isn't zombie?
  187.     if (!ze_is_user_zombie(pev(entity, pev_owner)))
  188.         return;
  189.    
  190.     // HE Grenade
  191.     if (model[9] == 'h' && model[10] == 'e')
  192.     {
  193.         // Give it a glow
  194.         fm_set_rendering(entity, kRenderFxGlowShell, 0, 200, 0, kRenderNormal, 16);
  195.        
  196.         // And a colored trail
  197.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  198.         write_byte(TE_BEAMFOLLOW) // TE id
  199.         write_short(entity) // entity
  200.         write_short(g_trailSpr) // sprite
  201.         write_byte(10) // life
  202.         write_byte(10) // width
  203.         write_byte(0) // r
  204.         write_byte(200) // g
  205.         write_byte(0) // b
  206.         write_byte(200) // brightness
  207.         message_end()
  208.        
  209.         // Set grenade type on the thrown grenade entity
  210.         set_pev(entity, PEV_NADE_TYPE, NADE_TYPE_INFECTION)
  211.     }
  212. }
  213.  
  214. // Ham Grenade Think Forward
  215. public fw_ThinkGrenade(entity)
  216. {
  217.     // Invalid entity
  218.     if (!pev_valid(entity)) return HAM_IGNORED;
  219.    
  220.     // Get damage time of grenade
  221.     static Float:dmgtime
  222.     pev(entity, pev_dmgtime, dmgtime)
  223.    
  224.     // Check if it's time to go off
  225.     if (dmgtime > get_gametime())
  226.         return HAM_IGNORED;
  227.    
  228.     // Check if it's one of our custom nades
  229.     switch (pev(entity, PEV_NADE_TYPE))
  230.     {
  231.         case NADE_TYPE_INFECTION: // Infection Bomb
  232.         {
  233.             infection_explode(entity)
  234.             return HAM_SUPERCEDE;
  235.         }
  236.     }
  237.    
  238.     return HAM_IGNORED;
  239. }
  240.  
  241. // Infection Bomb Explosion
  242. infection_explode(ent)
  243. {
  244.     // Get origin
  245.     static Float:origin[3]
  246.     pev(ent, pev_origin, origin)
  247.    
  248.     // Make the explosion
  249.     create_blast(origin)
  250.    
  251.     // Infection nade explode sound
  252.     static sound[SOUND_MAX_LENGTH]
  253.     ArrayGetString(g_sound_grenade_infect_explode, random_num(0, ArraySize(g_sound_grenade_infect_explode) - 1), sound, charsmax(sound))
  254.     emit_sound(ent, CHAN_WEAPON, sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  255.    
  256.     // Get attacker
  257.     new attacker = pev(ent, pev_owner)
  258.    
  259.     // Infection bomb owner disconnected or not zombie anymore?
  260.     if (!is_user_connected(attacker) || !ze_is_user_zombie(attacker))
  261.     {
  262.         // Get rid of the grenade
  263.         engfunc(EngFunc_RemoveEntity, ent)
  264.         return;
  265.     }
  266.    
  267.     // Collisions
  268.     new victim = -1
  269.    
  270.     while ((victim = engfunc(EngFunc_FindEntityInSphere, victim, origin, cvar_infection_reduis)) != 0)
  271.     {
  272.         // Only effect alive humans
  273.         if (!is_user_alive(victim) || ze_is_user_zombie(victim))
  274.             continue;
  275.        
  276.         if (ze_get_humans_number() == 1)
  277.             continue;
  278.        
  279.         new iArmor = floatround(get_entvar(victim, var_armorvalue))
  280.        
  281.         if (iArmor > 55)
  282.             continue;
  283.        
  284.         // Turn into zombie
  285.         ze_set_user_zombie(victim)
  286.        
  287.         // Victim's sound
  288.         ArrayGetString(g_sound_grenade_infect_player, random_num(0, ArraySize(g_sound_grenade_infect_player) - 1), sound, charsmax(sound))
  289.         emit_sound(victim, CHAN_VOICE, sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  290.     }
  291.    
  292.     // Get rid of the grenade
  293.     engfunc(EngFunc_RemoveEntity, ent)
  294. }
  295.  
  296. // Infection Bomb: Green Blast
  297. create_blast(const Float:origin[3])
  298. {
  299.     // Smallest ring
  300.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  301.     write_byte(TE_BEAMCYLINDER) // TE id
  302.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  303.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  304.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  305.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  306.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  307.     engfunc(EngFunc_WriteCoord, origin[2]+385.0) // z axis
  308.     write_short(g_exploSpr) // sprite
  309.     write_byte(0) // startframe
  310.     write_byte(0) // framerate
  311.     write_byte(4) // life
  312.     write_byte(60) // width
  313.     write_byte(0) // noise
  314.     write_byte(0) // red
  315.     write_byte(200) // green
  316.     write_byte(0) // blue
  317.     write_byte(200) // brightness
  318.     write_byte(0) // speed
  319.     message_end()
  320.    
  321.     // Medium ring
  322.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  323.     write_byte(TE_BEAMCYLINDER) // TE id
  324.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  325.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  326.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  327.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  328.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  329.     engfunc(EngFunc_WriteCoord, origin[2]+470.0) // z axis
  330.     write_short(g_exploSpr) // sprite
  331.     write_byte(0) // startframe
  332.     write_byte(0) // framerate
  333.     write_byte(4) // life
  334.     write_byte(60) // width
  335.     write_byte(0) // noise
  336.     write_byte(0) // red
  337.     write_byte(200) // green
  338.     write_byte(0) // blue
  339.     write_byte(200) // brightness
  340.     write_byte(0) // speed
  341.     message_end()
  342.    
  343.     // Largest ring
  344.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  345.     write_byte(TE_BEAMCYLINDER) // TE id
  346.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  347.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  348.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  349.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  350.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  351.     engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
  352.     write_short(g_exploSpr) // sprite
  353.     write_byte(0) // startframe
  354.     write_byte(0) // framerate
  355.     write_byte(4) // life
  356.     write_byte(60) // width
  357.     write_byte(0) // noise
  358.     write_byte(0) // red
  359.     write_byte(200) // green
  360.     write_byte(0) // blue
  361.     write_byte(200) // brightness
  362.     write_byte(0) // speed
  363.     message_end()
  364. }
  365.  
  366. // Set entity's rendering type (from fakemeta_util)
  367. stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
  368. {
  369.     static Float:color[3]
  370.     color[0] = float(r)
  371.     color[1] = float(g)
  372.     color[2] = float(b)
  373.    
  374.     set_pev(entity, pev_renderfx, fx)
  375.     set_pev(entity, pev_rendercolor, color)
  376.     set_pev(entity, pev_rendermode, render)
  377.     set_pev(entity, pev_renderamt, float(amount))
  378. }
  379.  
He who fails to plan is planning to fail

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

#12

Post by czirimbolo » 4 years ago

Raheem wrote: 4 years ago
czirimbolo wrote: 4 years ago Thanks mate. In my opinion its too powerful item. So I have small request. If humans have more armor than 55 (>55), this bomb will not infect a human. Can you make it?
  1. #include <zombie_escape>
  2. #include <fun>
  3.  
  4. // Settings file
  5. new const ZE_SETTING_FILE[] = "zombie_escape.ini"
  6.  
  7. // Default sounds
  8. new const sound_grenade_infect_explode[][] = { "zombie_escape/grenade_infect.wav" }
  9. new const sound_grenade_infect_player[][] = { "scientist/scream20.wav" , "scientist/scream22.wav" , "scientist/scream05.wav" }
  10.  
  11. #define MODEL_MAX_LENGTH 64
  12. #define SOUND_MAX_LENGTH 64
  13. #define SPRITE_MAX_LENGTH 64
  14.  
  15. // Models
  16. new g_model_grenade_infect[MODEL_MAX_LENGTH] = "models/zombie_escape/v_grenade_infect.mdl"
  17.  
  18. // Sprites
  19. new g_sprite_grenade_trail[SPRITE_MAX_LENGTH] = "sprites/laserbeam.spr"
  20. new g_sprite_grenade_ring[SPRITE_MAX_LENGTH] = "sprites/shockwave.spr"
  21. new g_sprite_grenade_gibs[SPRITE_MAX_LENGTH] = "sprites/zombie_escape/infect_gibs.spr"
  22.  
  23. new Array:g_sound_grenade_infect_explode
  24. new Array:g_sound_grenade_infect_player
  25. new Array:g_sound_grenade_infect_gibs
  26.  
  27. // Explosion radius for custom grenades
  28. const Float:NADE_EXPLOSION_RADIUS = 240.0
  29.  
  30. // HACK: pev_ field used to store custom nade types and their values
  31. const PEV_NADE_TYPE = pev_flTimeStepSound
  32. const NADE_TYPE_INFECTION = 1111
  33.  
  34. new g_trailSpr, g_exploSpr, g_gibsSpr
  35.  
  36. new g_ItemID
  37. new g_InfectionBombCounter, cvar_infection_bomb_round_limit, cvar_infection_reduis
  38.  
  39. new bool:g_bHasInfection[33]
  40.  
  41. public plugin_init()
  42. {
  43.     register_plugin("[ZE] Item: Infection Bomb", ZE_VERSION, AUTHORS)
  44.    
  45.     register_forward(FM_SetModel, "fw_SetModel")
  46.     RegisterHam(Ham_Think, "grenade", "fw_ThinkGrenade")
  47.    
  48.     g_ItemID = ze_register_item("Infection Bomb", 50, 0)
  49.     cvar_infection_bomb_round_limit = register_cvar("ze_infection_bomb_round_limit", "3")
  50.     cvar_infection_reduis = register_cvar("ze_infection_bomb_reduis", "240")
  51. }
  52.  
  53. public plugin_precache()
  54. {
  55.     // Initialize arrays
  56.     g_sound_grenade_infect_explode = ArrayCreate(SOUND_MAX_LENGTH, 1)
  57.     g_sound_grenade_infect_player = ArrayCreate(SOUND_MAX_LENGTH, 1)
  58.     g_sound_grenade_infect_gibs = ArrayCreate(SOUND_MAX_LENGTH, 1)
  59.    
  60.     // Load from external file
  61.     amx_load_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT EXPLODE", g_sound_grenade_infect_explode)
  62.     amx_load_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT PLAYER", g_sound_grenade_infect_player)
  63.    
  64.     // If we couldn't load custom sounds from file, use and save default ones
  65.     new index
  66.     if (ArraySize(g_sound_grenade_infect_explode) == 0)
  67.     {
  68.         for (index = 0; index < sizeof sound_grenade_infect_explode; index++)
  69.             ArrayPushString(g_sound_grenade_infect_explode, sound_grenade_infect_explode[index])
  70.        
  71.         // Save to external file
  72.         amx_save_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT EXPLODE", g_sound_grenade_infect_explode)
  73.     }
  74.     if (ArraySize(g_sound_grenade_infect_player) == 0)
  75.     {
  76.         for (index = 0; index < sizeof sound_grenade_infect_player; index++)
  77.             ArrayPushString(g_sound_grenade_infect_player, sound_grenade_infect_player[index])
  78.        
  79.         // Save to external file
  80.         amx_save_setting_string_arr(ZE_SETTING_FILE, "Sounds", "GRENADE INFECT PLAYER", g_sound_grenade_infect_player)
  81.     }
  82.    
  83.     // Load from external file, save if not found
  84.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Weapon Models", "GRENADE INFECT", g_model_grenade_infect, charsmax(g_model_grenade_infect)))
  85.         amx_save_setting_string(ZE_SETTING_FILE, "Weapon Models", "GRENADE INFECT", g_model_grenade_infect)
  86.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT TRAIL", g_sprite_grenade_trail, charsmax(g_sprite_grenade_trail)))
  87.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT TRAIL", g_sprite_grenade_trail)
  88.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT GIBS", g_sprite_grenade_gibs, charsmax(g_sprite_grenade_gibs)))
  89.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "GRENADE INFECT GIBS", g_sprite_grenade_gibs)
  90.     if (!amx_load_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "RING", g_sprite_grenade_ring, charsmax(g_sprite_grenade_ring)))
  91.         amx_save_setting_string(ZE_SETTING_FILE, "Grenade Sprites", "RING", g_sprite_grenade_ring)
  92.    
  93.     // Precache sounds
  94.     new sound[SOUND_MAX_LENGTH]
  95.     for (index = 0; index < ArraySize(g_sound_grenade_infect_explode); index++)
  96.     {
  97.         ArrayGetString(g_sound_grenade_infect_explode, index, sound, charsmax(sound))
  98.         precache_sound(sound)
  99.     }
  100.     for (index = 0; index < ArraySize(g_sound_grenade_infect_player); index++)
  101.     {
  102.         ArrayGetString(g_sound_grenade_infect_player, index, sound, charsmax(sound))
  103.         precache_sound(sound)
  104.     }
  105.    
  106.     // Precache models
  107.     precache_model(g_model_grenade_infect)
  108.     g_trailSpr = precache_model(g_sprite_grenade_trail)
  109.     g_exploSpr = precache_model(g_sprite_grenade_ring)
  110.     g_gibsSpr = precache_model(g_sprite_grenade_gibs)
  111. }
  112.  
  113. public ze_game_started()
  114. {
  115.     g_InfectionBombCounter = 0
  116. }
  117.  
  118. public ze_select_item_pre(id, itemid)
  119. {
  120.     // This is not our item
  121.     if (itemid != g_ItemID)
  122.         return ZE_ITEM_AVAILABLE;
  123.    
  124.     // Available for Humans only, So don't show it for zombies
  125.     if (!ze_is_user_zombie(id))
  126.         return ZE_ITEM_DONT_SHOW
  127.    
  128.     // Display remaining item count for this round
  129.     static text[32]
  130.     formatex(text, charsmax(text), "[%d/%d]", g_InfectionBombCounter, get_pcvar_num(cvar_infection_bomb_round_limit))
  131.     ze_add_text_to_item(text)
  132.    
  133.     // Reached infection bomb limit for this round
  134.     if (g_InfectionBombCounter >= get_pcvar_num(cvar_infection_bomb_round_limit))
  135.         return ZE_ITEM_UNAVAILABLE;
  136.    
  137.     // Player already owns infection bomb
  138.     if (g_bHasInfection[id])
  139.         return ZE_ITEM_UNAVAILABLE;
  140.    
  141.     return ZE_ITEM_AVAILABLE
  142. }
  143.  
  144. public ze_select_item_post(player, itemid)
  145. {
  146.     if (itemid != g_ItemID)
  147.         return
  148.    
  149.     // Give infection bomb
  150.     give_item(player, "weapon_hegrenade")
  151.     g_InfectionBombCounter++
  152.     g_bHasInfection[player]
  153. }
  154.  
  155. public ze_user_humanized(id)
  156. {
  157.     // Remove custom grenade model
  158.     g_bHasInfection[id] = false
  159. }
  160.  
  161. public ze_user_infected(id, attacker)
  162. {
  163.     // Set custom grenade model
  164.     cs_set_player_view_model(id, CSW_HEGRENADE, g_model_grenade_infect)
  165. }
  166.  
  167. // Forward Set Model
  168. public fw_SetModel(entity, const model[])
  169. {
  170.     // We don't care
  171.     if (strlen(model) < 8)
  172.         return;
  173.    
  174.     // Narrow down our matches a bit
  175.     if (model[7] != 'w' || model[8] != '_')
  176.         return;
  177.    
  178.     // Get damage time of grenade
  179.     static Float:dmgtime
  180.     pev(entity, pev_dmgtime, dmgtime)
  181.    
  182.     // Grenade not yet thrown
  183.     if (dmgtime == 0.0)
  184.         return;
  185.    
  186.     // Grenade's owner isn't zombie?
  187.     if (!ze_is_user_zombie(pev(entity, pev_owner)))
  188.         return;
  189.    
  190.     // HE Grenade
  191.     if (model[9] == 'h' && model[10] == 'e')
  192.     {
  193.         // Give it a glow
  194.         fm_set_rendering(entity, kRenderFxGlowShell, 0, 200, 0, kRenderNormal, 16);
  195.        
  196.         // And a colored trail
  197.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  198.         write_byte(TE_BEAMFOLLOW) // TE id
  199.         write_short(entity) // entity
  200.         write_short(g_trailSpr) // sprite
  201.         write_byte(10) // life
  202.         write_byte(10) // width
  203.         write_byte(0) // r
  204.         write_byte(200) // g
  205.         write_byte(0) // b
  206.         write_byte(200) // brightness
  207.         message_end()
  208.        
  209.         // Set grenade type on the thrown grenade entity
  210.         set_pev(entity, PEV_NADE_TYPE, NADE_TYPE_INFECTION)
  211.     }
  212. }
  213.  
  214. // Ham Grenade Think Forward
  215. public fw_ThinkGrenade(entity)
  216. {
  217.     // Invalid entity
  218.     if (!pev_valid(entity)) return HAM_IGNORED;
  219.    
  220.     // Get damage time of grenade
  221.     static Float:dmgtime
  222.     pev(entity, pev_dmgtime, dmgtime)
  223.    
  224.     // Check if it's time to go off
  225.     if (dmgtime > get_gametime())
  226.         return HAM_IGNORED;
  227.    
  228.     // Check if it's one of our custom nades
  229.     switch (pev(entity, PEV_NADE_TYPE))
  230.     {
  231.         case NADE_TYPE_INFECTION: // Infection Bomb
  232.         {
  233.             infection_explode(entity)
  234.             return HAM_SUPERCEDE;
  235.         }
  236.     }
  237.    
  238.     return HAM_IGNORED;
  239. }
  240.  
  241. // Infection Bomb Explosion
  242. infection_explode(ent)
  243. {
  244.     // Get origin
  245.     static Float:origin[3]
  246.     pev(ent, pev_origin, origin)
  247.    
  248.     // Make the explosion
  249.     create_blast(origin)
  250.    
  251.     // Infection nade explode sound
  252.     static sound[SOUND_MAX_LENGTH]
  253.     ArrayGetString(g_sound_grenade_infect_explode, random_num(0, ArraySize(g_sound_grenade_infect_explode) - 1), sound, charsmax(sound))
  254.     emit_sound(ent, CHAN_WEAPON, sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  255.    
  256.     // Get attacker
  257.     new attacker = pev(ent, pev_owner)
  258.    
  259.     // Infection bomb owner disconnected or not zombie anymore?
  260.     if (!is_user_connected(attacker) || !ze_is_user_zombie(attacker))
  261.     {
  262.         // Get rid of the grenade
  263.         engfunc(EngFunc_RemoveEntity, ent)
  264.         return;
  265.     }
  266.    
  267.     // Collisions
  268.     new victim = -1
  269.    
  270.     while ((victim = engfunc(EngFunc_FindEntityInSphere, victim, origin, cvar_infection_reduis)) != 0)
  271.     {
  272.         // Only effect alive humans
  273.         if (!is_user_alive(victim) || ze_is_user_zombie(victim))
  274.             continue;
  275.        
  276.         if (ze_get_humans_number() == 1)
  277.             continue;
  278.        
  279.         new iArmor = floatround(get_entvar(victim, var_armorvalue))
  280.        
  281.         if (iArmor > 55)
  282.             continue;
  283.        
  284.         // Turn into zombie
  285.         ze_set_user_zombie(victim)
  286.        
  287.         // Victim's sound
  288.         ArrayGetString(g_sound_grenade_infect_player, random_num(0, ArraySize(g_sound_grenade_infect_player) - 1), sound, charsmax(sound))
  289.         emit_sound(victim, CHAN_VOICE, sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  290.     }
  291.    
  292.     // Get rid of the grenade
  293.     engfunc(EngFunc_RemoveEntity, ent)
  294. }
  295.  
  296. // Infection Bomb: Green Blast
  297. create_blast(const Float:origin[3])
  298. {
  299.     // Smallest ring
  300.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  301.     write_byte(TE_BEAMCYLINDER) // TE id
  302.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  303.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  304.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  305.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  306.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  307.     engfunc(EngFunc_WriteCoord, origin[2]+385.0) // z axis
  308.     write_short(g_exploSpr) // sprite
  309.     write_byte(0) // startframe
  310.     write_byte(0) // framerate
  311.     write_byte(4) // life
  312.     write_byte(60) // width
  313.     write_byte(0) // noise
  314.     write_byte(0) // red
  315.     write_byte(200) // green
  316.     write_byte(0) // blue
  317.     write_byte(200) // brightness
  318.     write_byte(0) // speed
  319.     message_end()
  320.    
  321.     // Medium ring
  322.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  323.     write_byte(TE_BEAMCYLINDER) // TE id
  324.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  325.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  326.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  327.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  328.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  329.     engfunc(EngFunc_WriteCoord, origin[2]+470.0) // z axis
  330.     write_short(g_exploSpr) // sprite
  331.     write_byte(0) // startframe
  332.     write_byte(0) // framerate
  333.     write_byte(4) // life
  334.     write_byte(60) // width
  335.     write_byte(0) // noise
  336.     write_byte(0) // red
  337.     write_byte(200) // green
  338.     write_byte(0) // blue
  339.     write_byte(200) // brightness
  340.     write_byte(0) // speed
  341.     message_end()
  342.    
  343.     // Largest ring
  344.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  345.     write_byte(TE_BEAMCYLINDER) // TE id
  346.     engfunc(EngFunc_WriteCoord, origin[0]) // x
  347.     engfunc(EngFunc_WriteCoord, origin[1]) // y
  348.     engfunc(EngFunc_WriteCoord, origin[2]) // z
  349.     engfunc(EngFunc_WriteCoord, origin[0]) // x axis
  350.     engfunc(EngFunc_WriteCoord, origin[1]) // y axis
  351.     engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
  352.     write_short(g_exploSpr) // sprite
  353.     write_byte(0) // startframe
  354.     write_byte(0) // framerate
  355.     write_byte(4) // life
  356.     write_byte(60) // width
  357.     write_byte(0) // noise
  358.     write_byte(0) // red
  359.     write_byte(200) // green
  360.     write_byte(0) // blue
  361.     write_byte(200) // brightness
  362.     write_byte(0) // speed
  363.     message_end()
  364. }
  365.  
  366. // Set entity's rendering type (from fakemeta_util)
  367. stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
  368. {
  369.     static Float:color[3]
  370.     color[0] = float(r)
  371.     color[1] = float(g)
  372.     color[2] = float(b)
  373.    
  374.     set_pev(entity, pev_renderfx, fx)
  375.     set_pev(entity, pev_rendercolor, color)
  376.     set_pev(entity, pev_rendermode, render)
  377.     set_pev(entity, pev_renderamt, float(amount))
  378. }
  379.  
Bomb is not working good. Sometimes it infects and sometimes not, as I said before
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#13

Post by Raheem » 4 years ago

Give conditions so i can trace.
He who fails to plan is planning to fail

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

#14

Post by czirimbolo » 4 years ago

The main code is bugged. When I throw bomb to infect A Human its not working sometimes. Then i need to throw two times. I didnt test your last code with armor, I am talking about main code
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#15

Post by Raheem » 4 years ago

Maybe there is conflict with other nades.
He who fails to plan is planning to fail

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 3 guests