Ion cannon

Useless Stuffs, Spam ... etc
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1880
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 101 times
Age: 21
Contact:

Re: Ion cannon

#11

Post by Raheem » 10 Months Ago

What the problem now? Can anyone explain what the problem?
You don't know? Learn and you will know.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 281
Joined: 11 Months Ago
Location: Des Moines/USA
Has thanked: 6 times
Been thanked: 21 times
Age: 33
Contact:

#12

Post by Mark » 10 Months Ago

This code is correct?

When the fire starts we want the nade to explode once.

  1. public CreateFire(id)
  2. {
  3.     if( !g_Target[ id ] )
  4.     {
  5.         remove_task( id )
  6.         return PLUGIN_CONTINUE
  7.     }
  8.    
  9.     for( new id = 1; id < g_iMaxids; id++ )
  10.     {
  11.         if(ze_is_user_zombie(id))
  12.         {
  13.             ze_set_fire_grenade(id, true)
  14.         }
  15.     }
  16.  
  17.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  18.     write_byte(TE_SPRITE)
  19.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  20.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  21.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
  22.     write_short(ReadyFire)
  23.     write_byte(30)
  24.     write_byte(200)
  25.     message_end()
  26.  
  27.     set_task(1.5,"CreateFire", id)
  28.     return PLUGIN_CONTINUE
  29. }

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1880
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 101 times
Age: 21
Contact:

#13

Post by Raheem » 10 Months Ago

In this case we use boolean variable, a global variable that seen for all your functions. You will need to set it true once the event is done once and then you check if it's true then don't execute code again. And to reset it to false once the event ended.

If you don't understand this check:

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <cstrike>
  4. #include <fun>
  5. #include <fakemeta_util>
  6.  
  7.  
  8. new const PLUGIN[] = "[ZE] Extra Item:Ion Cannon"
  9. new const VERSION[] = "1.0"
  10. new const AUTHOR[] = "A.F./Mark"
  11.  
  12. //#define ION_RADIUS        2000.0
  13. //#define ION_MAXDAMAGE     54200.0
  14. #define ACTION_BLOCK        ( IN_JUMP | IN_DUCK | IN_FORWARD | IN_BACK | IN_LEFT | IN_RIGHT | IN_MOVELEFT | IN_MOVERIGHT | IN_RELOAD | IN_RUN | IN_USE)
  15.  
  16. new const V_MODEL[] = "models/v_c4.mdl"
  17. new const W_MODEL[] = "models/w_battery.mdl"
  18.  
  19. new const SOUND_APPROACH[] = "zombie_plague/ion_canon/ion_approach2.wav"
  20. new const SOUND_BEACON[] = "zombie_plague/ion_canon/ion_beacon_set.wav"
  21. new const SOUND_STOP[] = "vox/_comma.wav"
  22. new const SOUND_BEEP[] = "zombie_plague/ion_canon/ion_beep3.wav"
  23. new const SOUND_ATTACK[] = "zombie_plague/ion_canon/ion_attack.wav"
  24. new const SOUND_READY[] = "zombie_plague/ion_canon/ion_ready.wav"
  25. new const SOUND_PLANT[] = "zombie_plague/ion_canon/ion_beacon_plant2.wav"
  26.  
  27. new g_iCurrentWeapon[33]
  28. new bool:g_bHasIon[33]
  29. new bool:g_bCanBuy
  30. new bool:g_bIsFiring[33]
  31. new bool:g_bKilledByIon[33]
  32. new bool:g_bIsPlanting[33]
  33. new g_iLastWeapon[33]
  34. new g_Target[33]
  35. new i_Pitch[33]
  36. new Float:i_BeaconTime[33]
  37. new Float:ion_mid_origin[33][3]
  38. new Float:beam_origin[33][8][3]
  39. new Float:g_degrees[33][8]
  40. new Float:g_distance[33]
  41. new Float:g_Speed[33]
  42. new IonBeam, BlueFire, Shockwave, ReadyFire, BlueFlare, LaserFlame
  43. new g_iIonID
  44. new gmsgScreenShake
  45. new g_iMaxids
  46. new bool:g_bExploded /* This variable first initialized to false */
  47.  
  48. new cvar_barlen, cvar_maxdmg, cvar_radius, cvar_ionmode, cvar_damage
  49.  
  50. enum
  51. {
  52.     anim_idle,
  53.     anim_draw,
  54.     anim_drop,
  55.     anim_pressbutton
  56. }
  57.  
  58. public plugin_precache()
  59. {
  60.     precache_model(V_MODEL)
  61.     precache_model(W_MODEL)
  62.     precache_sound(SOUND_APPROACH)
  63.     precache_sound(SOUND_BEACON)
  64.     precache_sound(SOUND_BEEP)
  65.     precache_sound(SOUND_ATTACK)
  66.     precache_sound(SOUND_READY)
  67.     precache_sound(SOUND_PLANT)
  68.     precache_sound(SOUND_STOP)
  69.     IonBeam = precache_model("sprites/ion_canon/ionbeam.spr")
  70.     BlueFlare = precache_model("sprites/ion_canon/bflare.spr")
  71.     ReadyFire = precache_model("sprites/ion_canon/fire.spr")
  72.     BlueFire = precache_model("sprites/ion_canon/blueflame.spr")
  73.     LaserFlame = precache_model("sprites/ion_canon/ion_laserflame.spr")
  74.     Shockwave = precache_model("sprites/shockwave.spr")
  75. }
  76.  
  77. public plugin_init()
  78. {
  79.     register_plugin( PLUGIN, VERSION, AUTHOR )
  80.    
  81.     g_iIonID = ze_register_item( "Ion Cannon", 100, 0)
  82.    
  83.     register_clcmd( "drop", "fn_Drop" )
  84.    
  85.     register_event( "CurWeapon", "EV_CurWeapon", "be", "1=1" )
  86.     register_event( "DeathMsg", "EV_DeathMsg", "a" )
  87.     register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" )
  88.    
  89.     register_forward( FM_CmdStart, "fw_CmdStart" )
  90.     register_forward( FM_PlayerPreThink, "fw_idPreThink" )
  91.    
  92.     RegisterHam( Ham_Item_Deploy, "weapon_c4", "fw_KnifeDeploy_Post", 1 )
  93.  
  94.     register_message( get_user_msgid( "DeathMsg" ), "fn_DeathMsg" )
  95.    
  96.     gmsgScreenShake = get_user_msgid( "ScreenShake" )
  97.    
  98.     cvar_barlen = register_cvar( "ze_ion_barlen", "4" )
  99.     cvar_maxdmg = register_cvar( "ze_ion_maxdmg", "54200" )
  100.     cvar_radius = register_cvar( "ze_ion_radius", "2000" )
  101.     cvar_ionmode = register_cvar( "ze_ion_mode", "1" ) // 0 - all zm damage, 1 - radius damage
  102.     cvar_damage = register_cvar( "ze_ion_damage", "1000" ) // only if ze_ion_mode is 0
  103.    
  104.     g_iMaxids = get_maxplayers( )
  105. }
  106.  
  107. public client_connect( id )
  108. {
  109.     g_bHasIon[ id ] = false
  110.     g_bIsPlanting[ id ] = false
  111. }
  112.  
  113. public client_disconnected( id )
  114. {
  115.     g_bHasIon[ id ] = false
  116. }
  117.  
  118. public ze_game_started()
  119. {
  120.     g_bCanBuy = false
  121. }
  122.  
  123. public ze_zombie_release()
  124. {
  125.     g_bCanBuy = true
  126. }
  127.  
  128. public ze_select_item_pre(id, itemid)
  129. {
  130.     if (itemid != g_iIonID)
  131.         return ZE_ITEM_AVAILABLE
  132.  
  133.     if (ze_is_user_zombie(id))
  134.         return ZE_ITEM_DONT_SHOW
  135.  
  136.     if (g_bHasIon[id] || !g_bCanBuy)
  137.         return ZE_ITEM_UNAVAILABLE
  138.  
  139.     return ZE_ITEM_AVAILABLE
  140. }
  141.  
  142. public ze_select_item_post(id, itemid)
  143. {
  144.     if( itemid == g_iIonID )
  145.     {
  146.         if( g_bHasIon[id] )
  147.         {
  148.             client_print( id, print_chat, "[ZE] Already have Ion Cannon" )
  149.             return PLUGIN_HANDLED
  150.         }
  151.         else
  152.         {
  153.             g_bHasIon[id] = true
  154.             give_item( id, "weapon_c4" )
  155.         }
  156.     }
  157.     return PLUGIN_CONTINUE
  158. }
  159.  
  160. public ze_user_infected(iVictim, iInfector)
  161. {
  162.     emit_sound(g_Target[iVictim], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  163.     ProgressBar(iVictim, 0, 0)
  164.     remove_task(iVictim+5000)
  165.     g_bHasIon[ iVictim ] = false
  166.     g_bIsFiring[ iVictim ] = false
  167.     g_bIsPlanting[ iVictim ] = false
  168.     g_Target[ iVictim ] = 0
  169. }
  170.  
  171. public ze_user_humanized(id)
  172. {
  173.     g_bHasIon[id] = false
  174.     emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  175.     ProgressBar(id, 0, 0)
  176.     remove_task(id+5000)
  177.     g_bIsFiring[ id ] = false
  178.     g_bIsPlanting[ id ] = false
  179.     g_Target[ id ] = 0
  180. }
  181.  
  182. public fn_Drop( id )
  183. {
  184.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  185.         return PLUGIN_CONTINUE
  186.    
  187.     if( g_iCurrentWeapon[ id ] == CSW_C4 )
  188.     {
  189.         client_print( id, print_center, "* You cannot drop Ion Cannon *" )
  190.         return PLUGIN_HANDLED
  191.     }
  192.     return PLUGIN_CONTINUE
  193. }
  194.  
  195. public EV_CurWeapon( id )
  196. {
  197.     if( !is_user_alive( id ) )
  198.         return PLUGIN_CONTINUE
  199.        
  200.     g_iCurrentWeapon[ id ] = read_data( 2 )
  201.    
  202.     return PLUGIN_CONTINUE
  203. }
  204.  
  205. public EV_DeathMsg( )
  206. {
  207.     static iVictim
  208.     iVictim = read_data( 2 )
  209.    
  210.     if( !is_user_connected( iVictim ) )
  211.         return
  212.        
  213.     g_bHasIon[ iVictim ] = false
  214.     g_bIsPlanting[ iVictim ] = false
  215. }
  216.  
  217. public EV_RoundStart( )
  218. {
  219.     // Remove any ion cannons
  220.     for( new i = 1; i < g_iMaxids; i++ )
  221.     {
  222.         if( g_Target[ i ] )
  223.             emit_sound(g_Target[i], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  224.        
  225.         if( is_user_alive( i ) )
  226.         {
  227.             ProgressBar(i, 0, 0)
  228.             remove_task(i+5000)
  229.             g_bHasIon[ i ] = false
  230.             g_bIsFiring[ i ] = false
  231.             g_bIsPlanting[ i ] = false
  232.             g_Target[ i ] = 0
  233.         }
  234.     }
  235.    
  236.     static iEnt
  237.     iEnt = -1
  238.    
  239.     while( ( iEnt = find_ent_by_class( iEnt, "info_target_ion" ) ) > 0 )
  240.     {
  241.         engfunc( EngFunc_RemoveEntity, iEnt )
  242.     }
  243. }
  244.  
  245. public fw_CmdStart( id, UC_Handle, Seed )
  246. {
  247.     if( !is_user_alive( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
  248.         return FMRES_IGNORED
  249.        
  250.     static afButtons
  251.     afButtons = get_uc( UC_Handle, UC_Buttons )
  252.    
  253.     if( afButtons & IN_ATTACK )
  254.     {
  255.         afButtons &= ~IN_ATTACK
  256.         set_uc( UC_Handle, UC_Buttons, afButtons )
  257.        
  258.         if( g_bIsPlanting[ id ] )
  259.         {
  260.             //ProgressBar(id, 0, 0)
  261.             return FMRES_IGNORED
  262.         }
  263.        
  264.         if( g_Target[ id ] )
  265.         {
  266.             client_print( id, print_center, "* You already had planted Ion Cannon *" )
  267.             g_bIsPlanting[ id ] = false
  268.             return FMRES_IGNORED
  269.         }
  270.    
  271.         if( is_user_outside( id ) )
  272.         {
  273.             g_Target[ id ] = 0
  274.             i_Pitch[ id ] = 97
  275.             i_BeaconTime[ id ] = 1.12
  276.             g_distance[ id ] = 350.0
  277.             g_Speed[ id ] = 0.0
  278.            
  279.            
  280.             static iEnt
  281.             iEnt = find_ent_by_owner( -1, "weapon_c4", id )
  282.             set_pdata_float( iEnt, 48, 10.0, 4 )
  283.            
  284.             g_bIsFiring[ id ] = true
  285.             g_bIsPlanting[ id ] = true
  286.             emit_sound(id, CHAN_WEAPON, SOUND_BEACON, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  287.            
  288.             g_iCurrentWeapon[ id ] = CSW_C4
  289.            
  290.             if( get_pcvar_num( cvar_barlen ) > 0 )
  291.             {
  292.                 set_task( 3.6, "UpdateAnim" )
  293.                 SendWeaponAnim( id, anim_pressbutton )
  294.                 ProgressBar(id, get_pcvar_num( cvar_barlen ), 0)
  295.                 set_task(get_pcvar_float( cvar_barlen ),"ion_planted", id+5000)
  296.             }
  297.             else
  298.             {
  299.                 set_task(0.2,"ion_planted", id+5000)
  300.                 SendWeaponAnim( id, anim_drop )
  301.             }
  302.         }
  303.         else
  304.         {
  305.             g_bIsPlanting[ id ] = false
  306.             client_print( id, print_center, "* To plant Ion Cannon you must be outside!!!*" )
  307.             return FMRES_IGNORED
  308.         }
  309.     }
  310.     return FMRES_HANDLED
  311. }
  312.  
  313. public fw_PlayerPreThink( id )
  314. {
  315.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  316.         return
  317.    
  318.     if( g_bIsFiring[ id ] )
  319.     {
  320.         g_iLastWeapon[ id ] = get_user_weapon( id )
  321.        
  322.         if( g_iCurrentWeapon[ id ] != CSW_C4 || g_iLastWeapon[ id ] != g_iCurrentWeapon[ id ] || get_user_button( id ) & ACTION_BLOCK )
  323.         {
  324.             emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  325.             ProgressBar(id, 0, 0)
  326.             remove_task(id+5000)
  327.             g_bIsFiring[ id ] = false
  328.             g_bIsPlanting[ id ] = false
  329.         }
  330.     }
  331. }
  332.  
  333. public fw_KnifeDeploy_Post( iEnt )
  334. {
  335.     static id
  336.     id = get_pdata_cbase( iEnt, 41, 4 )
  337.    
  338.     if( g_bHasIon[ id ] )
  339.     {
  340.         set_pev( id, pev_viewmodel2, V_MODEL )
  341.         SendWeaponAnim( id, anim_draw )
  342.     }
  343. }
  344.  
  345. public fn_DeathMsg( id, Dest, iEntity )
  346. {
  347.     static iVictim, iKiller
  348.     iKiller = get_msg_arg_int( 1 )
  349.     iVictim = get_msg_arg_int( 2 )
  350.    
  351.     if( !is_user_connected( iVictim ) || iKiller == iVictim )
  352.         return PLUGIN_CONTINUE
  353.    
  354.     if ( g_bKilledByIon[ iVictim ] )
  355.     {
  356.         set_msg_arg_string ( 4, "ion cannon" )
  357.     }
  358.     return PLUGIN_CONTINUE
  359. }
  360.  
  361. public ion_planted(id)
  362. {  
  363.     id -= 5000
  364.    
  365.     if( !is_user_alive( id ) || ze_is_user_zombie( id ) )
  366.     {
  367.         remove_task( id )
  368.         return PLUGIN_CONTINUE
  369.     }
  370.    
  371.     client_print(0, print_center, "Ion Cannon has been planted!")
  372.     client_cmd(0, "spk %s", SOUND_PLANT)
  373.     g_bIsFiring[id] = false
  374.     g_bIsPlanting[ id ] = false
  375.    
  376.     static Weapon
  377.     Weapon = find_ent_by_owner( -1, "weapon_c4", id )
  378.    
  379.     ExecuteHamB( Ham_Weapon_RetireWeapon, Weapon );
  380.     ExecuteHamB( Ham_RemovePlayerItem, id, Weapon );
  381.     ExecuteHamB( Ham_Item_Kill, Weapon );
  382.  
  383.     set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1 << CSW_C4) );
  384.     cs_set_user_bpammo( id, CSW_C4, 0 );
  385.     g_bHasIon[ id ] = false
  386.  
  387.     g_Target[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
  388.     if(!g_Target[id]) return PLUGIN_HANDLED
  389.  
  390.     // Strings
  391.     set_pev(g_Target[id],pev_classname,"info_target_ion")
  392.     engfunc(EngFunc_SetModel,g_Target[id],W_MODEL)
  393.  
  394.     // Integer
  395.     set_pev(g_Target[id],pev_owner, id)
  396.     set_pev(g_Target[id],pev_movetype, MOVETYPE_TOSS)
  397.     set_pev(g_Target[id],pev_solid, SOLID_TRIGGER)
  398.  
  399.     entity_get_vector(id,EV_VEC_origin, ion_mid_origin[id])
  400.     //wpn_projectile_startpos(id,0,0,50,ion_mid_origin[id])
  401.     //static Float:flOrigin[ 3 ]
  402.     //pev( id, pev_origin, flOrigin )
  403.     //engfunc( EngFunc_SetOrigin, g_Target[ id ], flOrigin )
  404.     set_pev(g_Target[id],pev_origin,ion_mid_origin[id])
  405.  
  406.     ion_beacon(id)
  407.     set_task(5.0,"ion_startup", id)
  408.     return PLUGIN_CONTINUE
  409. }
  410.  
  411. public ion_beacon(id)
  412. {
  413.     if( !g_Target[ id ] )
  414.     {
  415.         remove_task( id )
  416.         return PLUGIN_CONTINUE
  417.     }
  418.  
  419.     i_Pitch[id] += 3
  420.     i_BeaconTime[id] -= 0.03
  421.     if(i_Pitch[id] > 255) i_Pitch[id] = 255
  422.     if(i_BeaconTime[id] < 0.30) i_BeaconTime[id] = 0.30
  423.     emit_sound(g_Target[id], CHAN_ITEM, SOUND_BEEP, VOL_NORM, ATTN_NORM, 0, i_Pitch[id])
  424.     set_task(i_BeaconTime[id],"ion_beacon", id)
  425.     return PLUGIN_CONTINUE
  426. }
  427.  
  428. public ion_startup(id)
  429. {
  430.     client_cmd(0, "spk ^"%s^"", SOUND_APPROACH)
  431.     client_print(0, print_chat,"Ion Cannon is approaching")
  432.     set_task(5.0,"Trace_Ready", id)
  433. }
  434.  
  435. public Trace_Ready(id)
  436. {
  437.     if( !pev_valid( id ) )
  438.     {
  439.         remove_task( id )
  440.         return PLUGIN_CONTINUE
  441.     }
  442.        
  443.     // write origin of each
  444.     new Float:mid_origin[33][3]
  445.     pev(g_Target[id],pev_origin,mid_origin[id]) // Target contain entity id
  446.     // 1st
  447.     beam_origin[id][0][0] = mid_origin[id][0] + 300.0
  448.     beam_origin[id][0][1] = mid_origin[id][1] + 150.0
  449.     beam_origin[id][0][2] = mid_origin[id][2]
  450.     g_degrees[id][0] = 0.0
  451.     // 2nd
  452.     beam_origin[id][1][0] = mid_origin[id][0] + 300.0
  453.     beam_origin[id][1][1] = mid_origin[id][1] - 150.0
  454.     beam_origin[id][1][2] = mid_origin[id][2]
  455.     g_degrees[id][1] = 45.0
  456.     // 3rd
  457.     beam_origin[id][2][0] = mid_origin[id][0] - 300.0
  458.     beam_origin[id][2][1] = mid_origin[id][1] - 150.0
  459.     beam_origin[id][2][2] = mid_origin[id][2]
  460.     g_degrees[id][2] = 90.0
  461.     // 4th
  462.     beam_origin[id][3][0] = mid_origin[id][0] - 300.0
  463.     beam_origin[id][3][1] = mid_origin[id][1] + 150.0
  464.     beam_origin[id][3][2] = mid_origin[id][2]
  465.     g_degrees[id][3] = 135.0
  466.     // 5th
  467.     beam_origin[id][4][0] = mid_origin[id][0] + 150.0
  468.     beam_origin[id][4][1] = mid_origin[id][1] + 300.0
  469.     beam_origin[id][4][2] = mid_origin[id][2]
  470.     g_degrees[id][4] = 180.0
  471.     // 6th
  472.     beam_origin[id][5][0] = mid_origin[id][0] + 150.0
  473.     beam_origin[id][5][1] = mid_origin[id][1] - 300.0
  474.     beam_origin[id][5][2] = mid_origin[id][2]
  475.     g_degrees[id][5] = 225.0
  476.     // 7th
  477.     beam_origin[id][6][0] = mid_origin[id][0] - 150.0
  478.     beam_origin[id][6][1] = mid_origin[id][1] - 300.0
  479.     beam_origin[id][6][2] = mid_origin[id][2]
  480.     g_degrees[id][6] = 270.0
  481.     // 8th
  482.     beam_origin[id][7][0] = mid_origin[id][0] - 150.0
  483.     beam_origin[id][7][1] = mid_origin[id][1] + 300.0
  484.     beam_origin[id][7][2] = mid_origin[id][2]
  485.     g_degrees[id][7] = 315.0
  486.    
  487.     // set the mid to global
  488.     ion_mid_origin[id] = mid_origin[id]
  489.  
  490.     new Float:addtime
  491.     for(new i = 0; i < 8; i++) {
  492.         addtime = addtime + 0.3
  493.         new param[3]
  494.         param[0] = i
  495.         param[1] = id
  496.         set_task(0.0 + addtime, "Trace_Start", _,param, 2)
  497.     }
  498.     Laser_Rotate(id) //To fix the laserdraw
  499.     client_cmd(0, "spk ^"%s^"", SOUND_READY)
  500.    
  501.     for(new Float:i = 0.0; i < 7.5; i += 0.01) //Rotate for 7.5 secs.
  502.         set_task(i+3.0, "Laser_Rotate", id)
  503.  
  504.     set_task(2.9,"AddSpeed", id)
  505.     set_task(11.5,"CreateFire", id)
  506.     set_task(12.5,"ClearLasers", id)
  507.     set_task(16.2,"FireIonCannon", id)
  508.     return PLUGIN_CONTINUE
  509. }
  510.  
  511. public AddSpeed(id)
  512. {
  513.     if( !g_Target[ id ] )
  514.     {
  515.         remove_task( id )
  516.         return PLUGIN_CONTINUE
  517.     }
  518.    
  519.     if(g_Speed[id] > 1.0) g_Speed[id] = 1.0
  520.     g_Speed[id] += 0.1
  521.     set_task(0.6,"AddSpeed", id)
  522.     return PLUGIN_CONTINUE
  523. }
  524.  
  525. public CreateFire(id)
  526. {
  527.     if( !g_Target[ id ] )
  528.     {
  529.         remove_task( id )
  530.         return PLUGIN_CONTINUE
  531.     }
  532.    
  533.     // Here we check if it's exploded before or not?
  534.     if (!g_bExploded)
  535.     {
  536.         for( new id = 1; id < g_iMaxids; id++ )
  537.         {
  538.             if(ze_is_user_zombie(id))
  539.             {
  540.                 ze_set_fire_grenade(id, true)
  541.             }
  542.         }
  543.        
  544.         // After this we turn the variable to true so not to be called next call
  545.         g_bExploded = true
  546.     }
  547.  
  548.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  549.     write_byte(TE_SPRITE)
  550.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  551.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  552.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
  553.     write_short(ReadyFire)
  554.     write_byte(30)
  555.     write_byte(200)
  556.     message_end()
  557.  
  558.     set_task(1.5,"CreateFire", id)
  559.     return PLUGIN_CONTINUE
  560. }
  561.  
  562. public ClearLasers(id)
  563. {
  564.     // Here we reset the variable
  565.     g_bExploded = false
  566.    
  567.     ze_set_fire_grenade(id, false)
  568.     remove_task(1018+id)
  569. }
  570.  
  571. public Laser_Rotate(id)
  572. {
  573.     if( !g_Target[ id ] )
  574.     {
  575.         remove_task( id )
  576.         return
  577.     }
  578.    
  579.     g_distance[id] -= 0.467
  580.     for(new i = 0; i < 8; i++) {
  581.         // Calculate new alpha
  582.         g_degrees[id][i] += g_Speed[id]
  583.         if(g_degrees[id][i] > 360.0)
  584.             g_degrees[id][i] -= 360.0
  585.  
  586.         // calcul the next origin
  587.         new Float:tmp[33][3]
  588.         tmp[id] = ion_mid_origin[id]
  589.  
  590.         tmp[id][0] += floatsin(g_degrees[id][i], degrees) * g_distance[id]
  591.         tmp[id][1] += floatcos(g_degrees[id][i], degrees) * g_distance[id]
  592.         tmp[id][2] += 0.0 // -.-
  593.         beam_origin[id][i] = tmp[id]
  594.     }
  595. }
  596.  
  597. public Trace_Start(param[])
  598. {
  599.     new i = param[0]
  600.     new id = param[1]
  601.  
  602.     if( !g_Target[ id ] )
  603.     {
  604.         remove_task( id )
  605.         return
  606.     }
  607.    
  608.     new Float:get_random_z,Float:SkyOrigin[33][3]
  609.    
  610.     if( is_user_alive( id ) )
  611.     {
  612.         SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  613.         get_random_z = random_float(300.0,SkyOrigin[id][2])
  614.     }
  615.  
  616.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  617.     write_byte(TE_SPRITE)
  618.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  619.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  620.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2] + get_random_z)
  621.     write_short(BlueFire)
  622.     write_byte(10)
  623.     write_byte(100)
  624.     message_end()
  625.    
  626.     TraceAll(param)
  627. }
  628.  
  629. public TraceAll(param[])
  630. {
  631.     new i = param[0]
  632.     new id = param[1]
  633.    
  634.     if( !g_Target[ id ] )
  635.     {
  636.         remove_task( id )
  637.         return
  638.     }
  639.    
  640.     new Float:SkyOrigin[33][3]
  641.     SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  642.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  643.     write_byte(TE_BEAMPOINTS)
  644.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //start point (x)
  645.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //start point (y)
  646.     engfunc(EngFunc_WriteCoord, SkyOrigin[id][2])           //start point (z)
  647.  
  648.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //end point (x)
  649.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //end point (y)
  650.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])      //end point (z)
  651.     write_short(IonBeam)    //model
  652.     write_byte(0)       //startframe
  653.     write_byte(0)       //framerate
  654.     write_byte(1)       //life
  655.     write_byte(50)      //width
  656.     write_byte(0)       //noise
  657.     write_byte(255)     //r
  658.     write_byte(255)     //g
  659.     write_byte(255)     //b
  660.     write_byte(255)     //brightness
  661.     write_byte(0)       //speed
  662.     message_end()
  663.  
  664.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  665.     write_byte(TE_SPRITE)
  666.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  667.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  668.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  669.     write_short(LaserFlame)
  670.     write_byte(5)
  671.     write_byte(200)
  672.     message_end()
  673.  
  674.     /*message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  675.     write_byte(TE_WORLDDECAL)
  676.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  677.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  678.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  679.     write_byte(46)
  680.     message_end()*/
  681.  
  682.     set_task(0.08,"TraceAll", 1018+id, param, 2)
  683. }
  684.  
  685. public FireIonCannon(id)
  686. {
  687.     if( !g_Target[ id ] )
  688.     {
  689.         remove_task( id )
  690.         return
  691.     }
  692.    
  693.     new i = -1
  694.     while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
  695.     {
  696.         if( !is_user_connected( i ) )
  697.             continue
  698.            
  699.         if( pev(i, pev_flags) & (FL_CLIENT | FL_FAKECLIENT))
  700.         {
  701.             message_begin(MSG_ONE_UNRELIABLE, gmsgScreenShake, {0,0,0}, i)
  702.             write_short(255<<14) //ammount
  703.             write_short(10<<14) //lasts this long
  704.             write_short(255<<14) //frequency
  705.             message_end()
  706.         }
  707.         //next player in spehre.
  708.         continue
  709.     }
  710.  
  711.     new Float:skyOrigin[33][3]
  712.     skyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  713.  
  714.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  715.     write_byte(TE_BEAMPOINTS)
  716.     engfunc(EngFunc_WriteCoord, skyOrigin[id][0])   //start point (x)
  717.     engfunc(EngFunc_WriteCoord, skyOrigin[id][1])   //start point (y)
  718.     engfunc(EngFunc_WriteCoord, skyOrigin[id][2])   //start point (z)
  719.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])      //end point (x)
  720.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])      //end point (y)
  721.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])      //end point (z)
  722.     write_short(IonBeam)    //model
  723.     write_byte(0)       //startframe
  724.     write_byte(0)       //framerate
  725.     write_byte(15)      //life
  726.     write_byte(255)     //width
  727.     write_byte(0)       //noise
  728.     write_byte(255)     //r
  729.     write_byte(255)     //g
  730.     write_byte(255)     //b
  731.     write_byte(255)     //brightness
  732.     write_byte(0)       //speed
  733.     message_end()
  734.  
  735.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin, 0)
  736.     write_byte(TE_BEAMCYLINDER)
  737.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // start X
  738.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // start Y
  739.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2]) // start Z
  740.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // something X
  741.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // something Y
  742.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + get_pcvar_float( cvar_radius ) - 1000.0) // something Z
  743.     write_short(Shockwave) // sprite
  744.     write_byte(0) // startframe
  745.     write_byte(0) // framerate
  746.     write_byte(100) // life
  747.     write_byte(150) // width
  748.     write_byte(0) // noise
  749.     write_byte(0) // red
  750.     write_byte(100) // green
  751.     write_byte(250) // blue
  752.     write_byte(150) // brightness
  753.     write_byte(0) // speed
  754.     message_end()
  755.  
  756.     for(new i = 1; i < 6; i++)
  757.     {
  758.         engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  759.         write_byte(TE_SPRITETRAIL)  // line of moving glow sprites with gravity, fadeout, and collisions
  760.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  761.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  762.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])
  763.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  764.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  765.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 200)
  766.         write_short(BlueFlare) // (sprite index)
  767.         write_byte(50) // (count)
  768.         write_byte(random_num(27,30)) // (life in 0.1's)
  769.         write_byte(10) // byte (scale in 0.1's)
  770.         write_byte(random_num(30,70)) // (velocity along vector in 10's)
  771.         write_byte(40) // (randomness of velocity in 10's)
  772.         message_end()
  773.     }
  774.    
  775.     switch( get_pcvar_num( cvar_ionmode ) )
  776.     {
  777.         case 0:
  778.         {
  779.             for( new i = 1; i < g_iMaxids; i++ )
  780.             {
  781.                 if( is_user_alive( i ) && ze_is_user_zombie( i ) )
  782.                 {
  783.                     static Float:flHealth
  784.                     flHealth = entity_get_float( i, EV_FL_health )
  785.                
  786.                     static Float:flDamage
  787.                     flDamage = get_pcvar_float( cvar_damage )
  788.                
  789.                     if( flHealth - flDamage >= 1 )
  790.                     {
  791.                         ExecuteHamB( Ham_TakeDamage, i, g_Target[ id ], id, flDamage, DMG_BLAST )
  792.                     }
  793.                     else
  794.                     {
  795.                         g_bKilledByIon[ i ] = true
  796.                         ExecuteHamB( Ham_Killed, i, id, 2 )
  797.                         g_bKilledByIon[ i ] = false
  798.                     }
  799.                 }
  800.             }
  801.         }
  802.         case 1:
  803.         {
  804.             static victim
  805.             victim = -1
  806.            
  807.             while ( ( victim = engfunc( EngFunc_FindEntityInSphere, victim, ion_mid_origin[id], get_pcvar_float( cvar_radius ) ) ) != 0 )
  808.             {
  809.                 if( !is_user_connected( victim ) )
  810.                 {
  811.                     if( pev_valid( victim ) )
  812.                     {
  813.                         static szClassname[ 32 ]
  814.                         pev( victim, pev_classname, szClassname, 31 )
  815.                        
  816.                         if( equal( szClassname, "func_breakable" ) )
  817.                         {
  818.                             force_use( id, victim )
  819.                         }
  820.                     }
  821.                     continue
  822.                 }
  823.                
  824.                 if ( !is_user_alive( victim ) )
  825.                     continue
  826.                
  827.                 if( !ze_is_user_zombie( victim ) )
  828.                     continue
  829.            
  830.                 static Float:flOrigin[ 3 ]
  831.                 pev( victim, pev_origin, flOrigin )
  832.                
  833.                 static Float:flDistance, Float:flDamage
  834.                 flDistance = get_distance_f( ion_mid_origin[ id ], flOrigin )
  835.                
  836.                 flDamage = floatradius( get_pcvar_float( cvar_maxdmg ), get_pcvar_float( cvar_radius ), flDistance )
  837.                
  838.                 if( flDamage )
  839.                 {
  840.                     static Float:flHealth
  841.                     flHealth = entity_get_float( victim, EV_FL_health )
  842.                
  843.                     if( flHealth - flDamage >= 1 )
  844.                     {
  845.                         ExecuteHamB( Ham_TakeDamage, victim, g_Target[ id ], id, flDamage, DMG_BLAST )
  846.                     }
  847.                     else
  848.                     {
  849.                         g_bKilledByIon[ victim ] = true
  850.                         ExecuteHamB( Ham_Killed, victim, id, 2 )
  851.                         g_bKilledByIon[ victim ] = false
  852.                     }
  853.                 }
  854.             }
  855.         }
  856.     }
  857.    
  858.     client_cmd(0, "spk ^"%s^"", SOUND_ATTACK)
  859.     ResetAll(id)
  860. }
  861.  
  862. ResetAll(id)
  863. {  
  864.     if( !g_Target[ id ] )
  865.     {
  866.         remove_task( id )
  867.         return
  868.     }
  869.    
  870.     set_pev(g_Target[id], pev_flags, FL_KILLME)
  871.     g_Target[id] = 0
  872. }
  873.  
  874. /******************** Stocks ********************/
  875.  
  876. // Get entity above sky.
  877. stock Float:tlx_distance_to_sky(id)
  878. {  
  879.     new Float:TraceEnd[3]
  880.     pev(id, pev_origin, TraceEnd)
  881.        
  882.     new Float:f_dest[3]
  883.     f_dest[0] = TraceEnd[0]
  884.     f_dest[1] = TraceEnd[1]
  885.     f_dest[2] = TraceEnd[2] + 8192.0
  886.        
  887.     new res, Float:SkyOrigin[3]
  888.     engfunc(EngFunc_TraceLine, TraceEnd, f_dest, IGNORE_MONSTERS + IGNORE_GLASS, id, res)
  889.     get_tr2(res, TR_vecEndPos, SkyOrigin)
  890.    
  891.     return SkyOrigin
  892. }
  893.  
  894. //return distance above us to sky
  895. stock Float:is_user_outside(id)
  896. {
  897.     new Float:origin[3], Float:dist
  898.  
  899.     pev(id, pev_origin, origin)
  900.     dist = origin[2]
  901.  
  902.     while(engfunc(EngFunc_PointContents, origin) == CONTENTS_EMPTY)
  903.         origin[2] += 5.0
  904.     if(engfunc(EngFunc_PointContents, origin) == CONTENTS_SKY)
  905.         return (origin[2] - dist)
  906.  
  907.     return 0.0
  908. }
  909.  
  910. stock ProgressBar(id, seconds, position)
  911. {
  912.     message_begin(MSG_ONE, get_user_msgid("BarTime"), {0, 0, 0}, id)
  913.     write_byte(seconds)
  914.     write_byte(position)
  915.     message_end()
  916. }
  917.  
  918. SendWeaponAnim( id, Sequence )
  919. {
  920.     set_pev( id, pev_weaponanim, Sequence )
  921.    
  922.     message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id )
  923.     write_byte( Sequence )
  924.     write_byte( pev( id, pev_body ) )
  925.     message_end( )
  926. }
  927.  
  928. public UpdateAnim( id )
  929. {
  930.     if( !is_user_alive( id ) || ze_is_user_zombie( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
  931.         return
  932.            
  933.     SendWeaponAnim( id, anim_drop )
  934. }
  935.  
  936. stock Float:floatradius(Float:flMaxAmount, Float:flRadius, Float:flDistance)
  937. {
  938.     return floatsub(flMaxAmount, floatmul(floatdiv(flMaxAmount, flRadius), flDistance))
  939. }

I'm not sure of the place where g_bExploded = false should be as i don't know how this works, so try find the suitable place when the fire ends to reset it to false.
You don't know? Learn and you will know.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 281
Joined: 11 Months Ago
Location: Des Moines/USA
Has thanked: 6 times
Been thanked: 21 times
Age: 33
Contact:

#14

Post by Mark » 10 Months Ago

Ok 1 more problem with this when the zombie is not in the radius of the ion cannon the fire nade still sets him on fire.

New Code Here

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <cstrike>
  4. #include <fun>
  5. #include <fakemeta_util>
  6.  
  7.  
  8. new const PLUGIN[] = "[ZE] Extra Item:Ion Cannon"
  9. new const VERSION[] = "1.0"
  10. new const AUTHOR[] = "A.F./Mark"
  11.  
  12. //#define ION_RADIUS        2000.0
  13. //#define ION_MAXDAMAGE     54200.0
  14. #define ACTION_BLOCK        ( IN_JUMP | IN_DUCK | IN_FORWARD | IN_BACK | IN_LEFT | IN_RIGHT | IN_MOVELEFT | IN_MOVERIGHT | IN_RELOAD | IN_RUN | IN_USE)
  15.  
  16. new const V_MODEL[] = "models/v_c4.mdl"
  17. new const W_MODEL[] = "models/w_battery.mdl"
  18.  
  19. new const SOUND_APPROACH[] = "zombie_plague/ion_canon/ion_approach2.wav"
  20. new const SOUND_BEACON[] = "zombie_plague/ion_canon/ion_beacon_set.wav"
  21. new const SOUND_STOP[] = "vox/_comma.wav"
  22. new const SOUND_BEEP[] = "zombie_plague/ion_canon/ion_beep3.wav"
  23. new const SOUND_ATTACK[] = "zombie_plague/ion_canon/ion_attack.wav"
  24. new const SOUND_READY[] = "zombie_plague/ion_canon/ion_ready.wav"
  25. new const SOUND_PLANT[] = "zombie_plague/ion_canon/ion_beacon_plant2.wav"
  26.  
  27. new g_iCurrentWeapon[33]
  28. new bool:g_bHasIon[33]
  29. new bool:g_bCanBuy
  30. new bool:g_bIsFiring[33]
  31. new bool:g_bKilledByIon[33]
  32. new bool:g_bIsPlanting[33]
  33. new g_iLastWeapon[33]
  34. new g_Target[33]
  35. new i_Pitch[33]
  36. new Float:i_BeaconTime[33]
  37. new Float:ion_mid_origin[33][3]
  38. new Float:beam_origin[33][8][3]
  39. new Float:g_degrees[33][8]
  40. new Float:g_distance[33]
  41. new Float:g_Speed[33]
  42. new IonBeam, BlueFire, Shockwave, ReadyFire, BlueFlare, LaserFlame
  43. new g_iIonID
  44. new gmsgScreenShake
  45. new g_iMaxids
  46. new bool:g_bExploded /* This variable first initialized to false */
  47.  
  48. new cvar_barlen, cvar_maxdmg, cvar_radius, cvar_ionmode, cvar_damage
  49.  
  50. enum
  51. {
  52.     anim_idle,
  53.     anim_draw,
  54.     anim_drop,
  55.     anim_pressbutton
  56. }
  57.  
  58. public plugin_precache()
  59. {
  60.     precache_model(V_MODEL)
  61.     precache_model(W_MODEL)
  62.     precache_sound(SOUND_APPROACH)
  63.     precache_sound(SOUND_BEACON)
  64.     precache_sound(SOUND_BEEP)
  65.     precache_sound(SOUND_ATTACK)
  66.     precache_sound(SOUND_READY)
  67.     precache_sound(SOUND_PLANT)
  68.     precache_sound(SOUND_STOP)
  69.     IonBeam = precache_model("sprites/ion_canon/ionbeam.spr")
  70.     BlueFlare = precache_model("sprites/ion_canon/bflare.spr")
  71.     ReadyFire = precache_model("sprites/ion_canon/fire.spr")
  72.     BlueFire = precache_model("sprites/ion_canon/blueflame.spr")
  73.     LaserFlame = precache_model("sprites/ion_canon/ion_laserflame.spr")
  74.     Shockwave = precache_model("sprites/shockwave.spr")
  75. }
  76.  
  77. public plugin_init()
  78. {
  79.     register_plugin( PLUGIN, VERSION, AUTHOR )
  80.    
  81.     g_iIonID = ze_register_item( "Ion Cannon", 100, 0)
  82.    
  83.     register_clcmd( "drop", "fn_Drop" )
  84.    
  85.     register_event( "CurWeapon", "EV_CurWeapon", "be", "1=1" )
  86.     register_event( "DeathMsg", "EV_DeathMsg", "a" )
  87.     register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" )
  88.    
  89.     register_forward( FM_CmdStart, "fw_CmdStart" )
  90.     register_forward( FM_PlayerPreThink, "fw_idPreThink" )
  91.    
  92.     RegisterHam( Ham_Item_Deploy, "weapon_c4", "fw_KnifeDeploy_Post", 1 )
  93.  
  94.     register_message( get_user_msgid( "DeathMsg" ), "fn_DeathMsg" )
  95.    
  96.     gmsgScreenShake = get_user_msgid( "ScreenShake" )
  97.    
  98.     cvar_barlen = register_cvar( "ze_ion_barlen", "4" )
  99.     cvar_maxdmg = register_cvar( "ze_ion_maxdmg", "54200" )
  100.     cvar_radius = register_cvar( "ze_ion_radius", "2000" )
  101.     cvar_ionmode = register_cvar( "ze_ion_mode", "1" ) // 0 - all zm damage, 1 - radius damage
  102.     cvar_damage = register_cvar( "ze_ion_damage", "1000" ) // only if ze_ion_mode is 0
  103.    
  104.     g_iMaxids = get_maxplayers( )
  105. }
  106.  
  107. public client_connect( id )
  108. {
  109.     g_bHasIon[ id ] = false
  110.     g_bIsPlanting[ id ] = false
  111. }
  112.  
  113. public client_disconnected( id )
  114. {
  115.     g_bHasIon[ id ] = false
  116. }
  117.  
  118. public ze_game_started()
  119. {
  120.     g_bCanBuy = false
  121. }
  122.  
  123. public ze_zombie_release()
  124. {
  125.     g_bCanBuy = true
  126. }
  127.  
  128. public ze_select_item_pre(id, itemid)
  129. {
  130.     if (itemid != g_iIonID)
  131.         return ZE_ITEM_AVAILABLE
  132.  
  133.     if (ze_is_user_zombie(id))
  134.         return ZE_ITEM_DONT_SHOW
  135.  
  136.     if (g_bHasIon[id] || !g_bCanBuy)
  137.         return ZE_ITEM_UNAVAILABLE
  138.  
  139.     return ZE_ITEM_AVAILABLE
  140. }
  141.  
  142. public ze_select_item_post(id, itemid)
  143. {
  144.     if( itemid == g_iIonID )
  145.     {
  146.         if( g_bHasIon[id] )
  147.         {
  148.             client_print( id, print_chat, "[ZE] Already have Ion Cannon" )
  149.             return PLUGIN_HANDLED
  150.         }
  151.         else
  152.         {
  153.             g_bHasIon[id] = true
  154.             give_item( id, "weapon_c4" )
  155.         }
  156.     }
  157.     return PLUGIN_CONTINUE
  158. }
  159.  
  160. public ze_user_infected(iVictim, iInfector)
  161. {
  162.     emit_sound(g_Target[iVictim], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  163.     ProgressBar(iVictim, 0, 0)
  164.     remove_task(iVictim+5000)
  165.     g_bHasIon[ iVictim ] = false
  166.     g_bIsFiring[ iVictim ] = false
  167.     g_bIsPlanting[ iVictim ] = false
  168.     g_Target[ iVictim ] = 0
  169. }
  170.  
  171. public ze_user_humanized(id)
  172. {
  173.     g_bHasIon[id] = false
  174.     emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  175.     ProgressBar(id, 0, 0)
  176.     remove_task(id+5000)
  177.     g_bIsFiring[ id ] = false
  178.     g_bIsPlanting[ id ] = false
  179.     g_Target[ id ] = 0
  180. }
  181.  
  182. public fn_Drop( id )
  183. {
  184.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  185.         return PLUGIN_CONTINUE
  186.    
  187.     if( g_iCurrentWeapon[ id ] == CSW_C4 )
  188.     {
  189.         client_print( id, print_center, "* You cannot drop Ion Cannon *" )
  190.         return PLUGIN_HANDLED
  191.     }
  192.     return PLUGIN_CONTINUE
  193. }
  194.  
  195. public EV_CurWeapon( id )
  196. {
  197.     if( !is_user_alive( id ) )
  198.         return PLUGIN_CONTINUE
  199.        
  200.     g_iCurrentWeapon[ id ] = read_data( 2 )
  201.    
  202.     return PLUGIN_CONTINUE
  203. }
  204.  
  205. public EV_DeathMsg( )
  206. {
  207.     static iVictim
  208.     iVictim = read_data( 2 )
  209.    
  210.     if( !is_user_connected( iVictim ) )
  211.         return
  212.        
  213.     g_bHasIon[ iVictim ] = false
  214.     g_bIsPlanting[ iVictim ] = false
  215. }
  216.  
  217. public EV_RoundStart( )
  218. {
  219.     // Remove any ion cannons
  220.     for( new i = 1; i < g_iMaxids; i++ )
  221.     {
  222.         if( g_Target[ i ] )
  223.             emit_sound(g_Target[i], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  224.        
  225.         if( is_user_alive( i ) )
  226.         {
  227.             ProgressBar(i, 0, 0)
  228.             remove_task(i+5000)
  229.             g_bHasIon[ i ] = false
  230.             g_bIsFiring[ i ] = false
  231.             g_bIsPlanting[ i ] = false
  232.             g_Target[ i ] = 0
  233.         }
  234.     }
  235.    
  236.     static iEnt
  237.     iEnt = -1
  238.    
  239.     while( ( iEnt = find_ent_by_class( iEnt, "info_target_ion" ) ) > 0 )
  240.     {
  241.         engfunc( EngFunc_RemoveEntity, iEnt )
  242.     }
  243. }
  244.  
  245. public fw_CmdStart( id, UC_Handle, Seed )
  246. {
  247.     if( !is_user_alive( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
  248.         return FMRES_IGNORED
  249.        
  250.     static afButtons
  251.     afButtons = get_uc( UC_Handle, UC_Buttons )
  252.    
  253.     if( afButtons & IN_ATTACK )
  254.     {
  255.         afButtons &= ~IN_ATTACK
  256.         set_uc( UC_Handle, UC_Buttons, afButtons )
  257.        
  258.         if( g_bIsPlanting[ id ] )
  259.         {
  260.             //ProgressBar(id, 0, 0)
  261.             return FMRES_IGNORED
  262.         }
  263.        
  264.         if( g_Target[ id ] )
  265.         {
  266.             client_print( id, print_center, "* You already had planted Ion Cannon *" )
  267.             g_bIsPlanting[ id ] = false
  268.             return FMRES_IGNORED
  269.         }
  270.    
  271.         if( is_user_outside( id ) )
  272.         {
  273.             g_Target[ id ] = 0
  274.             i_Pitch[ id ] = 97
  275.             i_BeaconTime[ id ] = 1.12
  276.             g_distance[ id ] = 350.0
  277.             g_Speed[ id ] = 0.0
  278.            
  279.            
  280.             static iEnt
  281.             iEnt = find_ent_by_owner( -1, "weapon_c4", id )
  282.             set_pdata_float( iEnt, 48, 10.0, 4 )
  283.            
  284.             g_bIsFiring[ id ] = true
  285.             g_bIsPlanting[ id ] = true
  286.             emit_sound(id, CHAN_WEAPON, SOUND_BEACON, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  287.            
  288.             g_iCurrentWeapon[ id ] = CSW_C4
  289.            
  290.             if( get_pcvar_num( cvar_barlen ) > 0 )
  291.             {
  292.                 set_task( 3.6, "UpdateAnim" )
  293.                 SendWeaponAnim( id, anim_pressbutton )
  294.                 ProgressBar(id, get_pcvar_num( cvar_barlen ), 0)
  295.                 set_task(get_pcvar_float( cvar_barlen ),"ion_planted", id+5000)
  296.             }
  297.             else
  298.             {
  299.                 set_task(0.2,"ion_planted", id+5000)
  300.                 SendWeaponAnim( id, anim_drop )
  301.             }
  302.         }
  303.         else
  304.         {
  305.             g_bIsPlanting[ id ] = false
  306.             client_print( id, print_center, "* To plant Ion Cannon you must be outside!!!*" )
  307.             return FMRES_IGNORED
  308.         }
  309.     }
  310.     return FMRES_HANDLED
  311. }
  312.  
  313. public fw_PlayerPreThink( id )
  314. {
  315.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  316.         return
  317.    
  318.     if( g_bIsFiring[ id ] )
  319.     {
  320.         g_iLastWeapon[ id ] = get_user_weapon( id )
  321.        
  322.         if( g_iCurrentWeapon[ id ] != CSW_C4 || g_iLastWeapon[ id ] != g_iCurrentWeapon[ id ] || get_user_button( id ) & ACTION_BLOCK )
  323.         {
  324.             emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  325.             ProgressBar(id, 0, 0)
  326.             remove_task(id+5000)
  327.             g_bIsFiring[ id ] = false
  328.             g_bIsPlanting[ id ] = false
  329.         }
  330.     }
  331. }
  332.  
  333. public fw_KnifeDeploy_Post( iEnt )
  334. {
  335.     static id
  336.     id = get_pdata_cbase( iEnt, 41, 4 )
  337.    
  338.     if( g_bHasIon[ id ] )
  339.     {
  340.         set_pev( id, pev_viewmodel2, V_MODEL )
  341.         SendWeaponAnim( id, anim_draw )
  342.     }
  343. }
  344.  
  345. public fn_DeathMsg( id, Dest, iEntity )
  346. {
  347.     static iVictim, iKiller
  348.     iKiller = get_msg_arg_int( 1 )
  349.     iVictim = get_msg_arg_int( 2 )
  350.    
  351.     if( !is_user_connected( iVictim ) || iKiller == iVictim )
  352.         return PLUGIN_CONTINUE
  353.    
  354.     if ( g_bKilledByIon[ iVictim ] )
  355.     {
  356.         set_msg_arg_string ( 4, "ion cannon" )
  357.     }
  358.     return PLUGIN_CONTINUE
  359. }
  360.  
  361. public ion_planted(id)
  362. {  
  363.     id -= 5000
  364.    
  365.     if( !is_user_alive( id ) || ze_is_user_zombie( id ) )
  366.     {
  367.         remove_task( id )
  368.         return PLUGIN_CONTINUE
  369.     }
  370.    
  371.     client_print(0, print_center, "Ion Cannon has been planted!")
  372.     client_cmd(0, "spk %s", SOUND_PLANT)
  373.     g_bIsFiring[id] = false
  374.     g_bIsPlanting[ id ] = false
  375.    
  376.     static Weapon
  377.     Weapon = find_ent_by_owner( -1, "weapon_c4", id )
  378.    
  379.     ExecuteHamB( Ham_Weapon_RetireWeapon, Weapon );
  380.     ExecuteHamB( Ham_RemovePlayerItem, id, Weapon );
  381.     ExecuteHamB( Ham_Item_Kill, Weapon );
  382.  
  383.     set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1 << CSW_C4) );
  384.     cs_set_user_bpammo( id, CSW_C4, 0 );
  385.     g_bHasIon[ id ] = false
  386.  
  387.     g_Target[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
  388.     if(!g_Target[id]) return PLUGIN_HANDLED
  389.  
  390.     // Strings
  391.     set_pev(g_Target[id],pev_classname,"info_target_ion")
  392.     engfunc(EngFunc_SetModel,g_Target[id],W_MODEL)
  393.  
  394.     // Integer
  395.     set_pev(g_Target[id],pev_owner, id)
  396.     set_pev(g_Target[id],pev_movetype, MOVETYPE_TOSS)
  397.     set_pev(g_Target[id],pev_solid, SOLID_TRIGGER)
  398.  
  399.     entity_get_vector(id,EV_VEC_origin, ion_mid_origin[id])
  400.     //wpn_projectile_startpos(id,0,0,50,ion_mid_origin[id])
  401.     //static Float:flOrigin[ 3 ]
  402.     //pev( id, pev_origin, flOrigin )
  403.     //engfunc( EngFunc_SetOrigin, g_Target[ id ], flOrigin )
  404.     set_pev(g_Target[id],pev_origin,ion_mid_origin[id])
  405.  
  406.     ion_beacon(id)
  407.     set_task(5.0,"ion_startup", id)
  408.     return PLUGIN_CONTINUE
  409. }
  410.  
  411. public ion_beacon(id)
  412. {
  413.     if( !g_Target[ id ] )
  414.     {
  415.         remove_task( id )
  416.         return PLUGIN_CONTINUE
  417.     }
  418.  
  419.     i_Pitch[id] += 3
  420.     i_BeaconTime[id] -= 0.03
  421.     if(i_Pitch[id] > 255) i_Pitch[id] = 255
  422.     if(i_BeaconTime[id] < 0.30) i_BeaconTime[id] = 0.30
  423.     emit_sound(g_Target[id], CHAN_ITEM, SOUND_BEEP, VOL_NORM, ATTN_NORM, 0, i_Pitch[id])
  424.     set_task(i_BeaconTime[id],"ion_beacon", id)
  425.     return PLUGIN_CONTINUE
  426. }
  427.  
  428. public ion_startup(id)
  429. {
  430.     client_cmd(0, "spk ^"%s^"", SOUND_APPROACH)
  431.     client_print(0, print_chat,"Ion Cannon is approaching")
  432.     set_task(5.0,"Trace_Ready", id)
  433. }
  434.  
  435. public Trace_Ready(id)
  436. {
  437.     if( !pev_valid( id ) )
  438.     {
  439.         remove_task( id )
  440.         return PLUGIN_CONTINUE
  441.     }
  442.        
  443.     // write origin of each
  444.     new Float:mid_origin[33][3]
  445.     pev(g_Target[id],pev_origin,mid_origin[id]) // Target contain entity id
  446.     // 1st
  447.     beam_origin[id][0][0] = mid_origin[id][0] + 300.0
  448.     beam_origin[id][0][1] = mid_origin[id][1] + 150.0
  449.     beam_origin[id][0][2] = mid_origin[id][2]
  450.     g_degrees[id][0] = 0.0
  451.     // 2nd
  452.     beam_origin[id][1][0] = mid_origin[id][0] + 300.0
  453.     beam_origin[id][1][1] = mid_origin[id][1] - 150.0
  454.     beam_origin[id][1][2] = mid_origin[id][2]
  455.     g_degrees[id][1] = 45.0
  456.     // 3rd
  457.     beam_origin[id][2][0] = mid_origin[id][0] - 300.0
  458.     beam_origin[id][2][1] = mid_origin[id][1] - 150.0
  459.     beam_origin[id][2][2] = mid_origin[id][2]
  460.     g_degrees[id][2] = 90.0
  461.     // 4th
  462.     beam_origin[id][3][0] = mid_origin[id][0] - 300.0
  463.     beam_origin[id][3][1] = mid_origin[id][1] + 150.0
  464.     beam_origin[id][3][2] = mid_origin[id][2]
  465.     g_degrees[id][3] = 135.0
  466.     // 5th
  467.     beam_origin[id][4][0] = mid_origin[id][0] + 150.0
  468.     beam_origin[id][4][1] = mid_origin[id][1] + 300.0
  469.     beam_origin[id][4][2] = mid_origin[id][2]
  470.     g_degrees[id][4] = 180.0
  471.     // 6th
  472.     beam_origin[id][5][0] = mid_origin[id][0] + 150.0
  473.     beam_origin[id][5][1] = mid_origin[id][1] - 300.0
  474.     beam_origin[id][5][2] = mid_origin[id][2]
  475.     g_degrees[id][5] = 225.0
  476.     // 7th
  477.     beam_origin[id][6][0] = mid_origin[id][0] - 150.0
  478.     beam_origin[id][6][1] = mid_origin[id][1] - 300.0
  479.     beam_origin[id][6][2] = mid_origin[id][2]
  480.     g_degrees[id][6] = 270.0
  481.     // 8th
  482.     beam_origin[id][7][0] = mid_origin[id][0] - 150.0
  483.     beam_origin[id][7][1] = mid_origin[id][1] + 300.0
  484.     beam_origin[id][7][2] = mid_origin[id][2]
  485.     g_degrees[id][7] = 315.0
  486.    
  487.     // set the mid to global
  488.     ion_mid_origin[id] = mid_origin[id]
  489.  
  490.     new Float:addtime
  491.     for(new i = 0; i < 8; i++) {
  492.         addtime = addtime + 0.3
  493.         new param[3]
  494.         param[0] = i
  495.         param[1] = id
  496.         set_task(0.0 + addtime, "Trace_Start", _,param, 2)
  497.     }
  498.     Laser_Rotate(id) //To fix the laserdraw
  499.     client_cmd(0, "spk ^"%s^"", SOUND_READY)
  500.    
  501.     for(new Float:i = 0.0; i < 7.5; i += 0.01) //Rotate for 7.5 secs.
  502.         set_task(i+3.0, "Laser_Rotate", id)
  503.  
  504.     set_task(2.9,"AddSpeed", id)
  505.     set_task(11.5,"CreateFire", id)
  506.     set_task(12.5,"ClearLasers", id)
  507.     set_task(18.2,"FireIonCannon", id)
  508.     return PLUGIN_CONTINUE
  509. }
  510.  
  511. public AddSpeed(id)
  512. {
  513.     if( !g_Target[ id ] )
  514.     {
  515.         remove_task( id )
  516.         return PLUGIN_CONTINUE
  517.     }
  518.    
  519.     if(g_Speed[id] > 1.0) g_Speed[id] = 1.0
  520.     g_Speed[id] += 0.1
  521.     set_task(0.6,"AddSpeed", id)
  522.     return PLUGIN_CONTINUE
  523. }
  524.  
  525. public CreateFire(id)
  526. {
  527.     if( !g_Target[ id ] )
  528.     {
  529.         g_bExploded = false
  530.         remove_task( id )
  531.         return PLUGIN_CONTINUE
  532.     }
  533.    
  534.     // Here we check if it's exploded before or not?
  535.     if (!g_bExploded)
  536.     {
  537.         for( new id = 1; id < g_iMaxids; id++ )
  538.         {
  539.             if(ze_is_user_zombie(id))
  540.             {
  541.                 ze_set_fire_grenade(id, true)
  542.             }
  543.         }
  544.        
  545.         // After this we turn the variable to true so not to be called next call
  546.         g_bExploded = true
  547.     }
  548.  
  549.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  550.     write_byte(TE_SPRITE)
  551.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  552.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  553.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
  554.     write_short(ReadyFire)
  555.     write_byte(30)
  556.     write_byte(200)
  557.     message_end()
  558.  
  559.     set_task(1.5,"CreateFire", id)
  560.     return PLUGIN_CONTINUE
  561. }
  562.  
  563. public ClearLasers(id)
  564. {
  565.     // Here we reset the variable
  566.     g_bExploded = false
  567.    
  568.     ze_set_fire_grenade(id, false)
  569.     remove_task(1018+id)
  570. }
  571.  
  572. public Laser_Rotate(id)
  573. {
  574.     if( !g_Target[ id ] )
  575.     {
  576.         remove_task( id )
  577.         return
  578.     }
  579.    
  580.     g_distance[id] -= 0.467
  581.     for(new i = 0; i < 8; i++) {
  582.         // Calculate new alpha
  583.         g_degrees[id][i] += g_Speed[id]
  584.         if(g_degrees[id][i] > 360.0)
  585.             g_degrees[id][i] -= 360.0
  586.  
  587.         // calcul the next origin
  588.         new Float:tmp[33][3]
  589.         tmp[id] = ion_mid_origin[id]
  590.  
  591.         tmp[id][0] += floatsin(g_degrees[id][i], degrees) * g_distance[id]
  592.         tmp[id][1] += floatcos(g_degrees[id][i], degrees) * g_distance[id]
  593.         tmp[id][2] += 0.0 // -.-
  594.         beam_origin[id][i] = tmp[id]
  595.     }
  596. }
  597.  
  598. public Trace_Start(param[])
  599. {
  600.     new i = param[0]
  601.     new id = param[1]
  602.  
  603.     if( !g_Target[ id ] )
  604.     {
  605.         remove_task( id )
  606.         return
  607.     }
  608.    
  609.     new Float:get_random_z,Float:SkyOrigin[33][3]
  610.    
  611.     if( is_user_alive( id ) )
  612.     {
  613.         SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  614.         get_random_z = random_float(300.0,SkyOrigin[id][2])
  615.     }
  616.  
  617.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  618.     write_byte(TE_SPRITE)
  619.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  620.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  621.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2] + get_random_z)
  622.     write_short(BlueFire)
  623.     write_byte(10)
  624.     write_byte(100)
  625.     message_end()
  626.    
  627.     TraceAll(param)
  628. }
  629.  
  630. public TraceAll(param[])
  631. {
  632.     new i = param[0]
  633.     new id = param[1]
  634.    
  635.     if( !g_Target[ id ] )
  636.     {
  637.         remove_task( id )
  638.         return
  639.     }
  640.    
  641.     new Float:SkyOrigin[33][3]
  642.     SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  643.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  644.     write_byte(TE_BEAMPOINTS)
  645.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //start point (x)
  646.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //start point (y)
  647.     engfunc(EngFunc_WriteCoord, SkyOrigin[id][2])           //start point (z)
  648.  
  649.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //end point (x)
  650.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //end point (y)
  651.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])      //end point (z)
  652.     write_short(IonBeam)    //model
  653.     write_byte(0)       //startframe
  654.     write_byte(0)       //framerate
  655.     write_byte(1)       //life
  656.     write_byte(50)      //width
  657.     write_byte(0)       //noise
  658.     write_byte(255)     //r
  659.     write_byte(255)     //g
  660.     write_byte(255)     //b
  661.     write_byte(255)     //brightness
  662.     write_byte(0)       //speed
  663.     message_end()
  664.  
  665.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  666.     write_byte(TE_SPRITE)
  667.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  668.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  669.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  670.     write_short(LaserFlame)
  671.     write_byte(5)
  672.     write_byte(200)
  673.     message_end()
  674.  
  675.     /*message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  676.     write_byte(TE_WORLDDECAL)
  677.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  678.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  679.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  680.     write_byte(46)
  681.     message_end()*/
  682.  
  683.     set_task(0.08,"TraceAll", 1018+id, param, 2)
  684. }
  685.  
  686. public FireIonCannon(id)
  687. {
  688.     if( !g_Target[ id ] )
  689.     {
  690.         remove_task( id )
  691.         return
  692.     }
  693.    
  694.     new i = -1
  695.     while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
  696.     {
  697.         if( !is_user_connected( i ))
  698.             continue
  699.            
  700.         if( pev(i, pev_flags) & (FL_CLIENT | FL_FAKECLIENT))
  701.         {
  702.             message_begin(MSG_ONE_UNRELIABLE, gmsgScreenShake, {0,0,0}, i)
  703.             write_short(255<<14) //ammount
  704.             write_short(10<<14) //lasts this long
  705.             write_short(255<<14) //frequency
  706.             message_end()
  707.         }
  708.         //next player in spehre.
  709.         continue
  710.     }
  711.  
  712.     new Float:skyOrigin[33][3]
  713.     skyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  714.  
  715.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  716.     write_byte(TE_BEAMPOINTS)
  717.     engfunc(EngFunc_WriteCoord, skyOrigin[id][0])   //start point (x)
  718.     engfunc(EngFunc_WriteCoord, skyOrigin[id][1])   //start point (y)
  719.     engfunc(EngFunc_WriteCoord, skyOrigin[id][2])   //start point (z)
  720.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])      //end point (x)
  721.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])      //end point (y)
  722.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])      //end point (z)
  723.     write_short(IonBeam)    //model
  724.     write_byte(0)       //startframe
  725.     write_byte(0)       //framerate
  726.     write_byte(15)      //life
  727.     write_byte(255)     //width
  728.     write_byte(0)       //noise
  729.     write_byte(255)     //r
  730.     write_byte(255)     //g
  731.     write_byte(255)     //b
  732.     write_byte(255)     //brightness
  733.     write_byte(0)       //speed
  734.     message_end()
  735.  
  736.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin, 0)
  737.     write_byte(TE_BEAMCYLINDER)
  738.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // start X
  739.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // start Y
  740.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2]) // start Z
  741.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // something X
  742.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // something Y
  743.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + get_pcvar_float( cvar_radius ) - 1000.0) // something Z
  744.     write_short(Shockwave) // sprite
  745.     write_byte(0) // startframe
  746.     write_byte(0) // framerate
  747.     write_byte(100) // life
  748.     write_byte(150) // width
  749.     write_byte(0) // noise
  750.     write_byte(0) // red
  751.     write_byte(100) // green
  752.     write_byte(250) // blue
  753.     write_byte(150) // brightness
  754.     write_byte(0) // speed
  755.     message_end()
  756.  
  757.     for(new i = 1; i < 6; i++)
  758.     {
  759.         engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  760.         write_byte(TE_SPRITETRAIL)  // line of moving glow sprites with gravity, fadeout, and collisions
  761.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  762.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  763.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])
  764.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  765.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  766.         engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 200)
  767.         write_short(BlueFlare) // (sprite index)
  768.         write_byte(50) // (count)
  769.         write_byte(random_num(27,30)) // (life in 0.1's)
  770.         write_byte(10) // byte (scale in 0.1's)
  771.         write_byte(random_num(30,70)) // (velocity along vector in 10's)
  772.         write_byte(40) // (randomness of velocity in 10's)
  773.         message_end()
  774.     }
  775.    
  776.     switch( get_pcvar_num( cvar_ionmode ) )
  777.     {
  778.         case 0:
  779.         {
  780.             for( new i = 1; i < g_iMaxids; i++ )
  781.             {
  782.                 if( is_user_alive( i ) && ze_is_user_zombie( i ) )
  783.                 {
  784.                     static Float:flHealth
  785.                     flHealth = entity_get_float( i, EV_FL_health )
  786.                
  787.                     static Float:flDamage
  788.                     flDamage = get_pcvar_float( cvar_damage )
  789.                
  790.                     if( flHealth - flDamage >= 1 )
  791.                     {
  792.                         ExecuteHamB( Ham_TakeDamage, i, g_Target[ id ], id, flDamage, DMG_BLAST )
  793.                     }
  794.                     else
  795.                     {
  796.                         g_bKilledByIon[ i ] = true
  797.                         ExecuteHamB( Ham_Killed, i, id, 2 )
  798.                         g_bKilledByIon[ i ] = false
  799.                     }
  800.                 }
  801.             }
  802.         }
  803.         case 1:
  804.         {
  805.             static victim
  806.             victim = -1
  807.            
  808.             while ( ( victim = engfunc( EngFunc_FindEntityInSphere, victim, ion_mid_origin[id], get_pcvar_float( cvar_radius ) ) ) != 0 )
  809.             {
  810.                 if( !is_user_connected( victim ) )
  811.                 {
  812.                     if( pev_valid( victim ) )
  813.                     {
  814.                         static szClassname[ 32 ]
  815.                         pev( victim, pev_classname, szClassname, 31 )
  816.                        
  817.                         if( equal( szClassname, "func_breakable" ) )
  818.                         {
  819.                             force_use( id, victim )
  820.                         }
  821.                     }
  822.                     continue
  823.                 }
  824.                
  825.                 if ( !is_user_alive( victim ) )
  826.                     continue
  827.                
  828.                 if( !ze_is_user_zombie( victim ) )
  829.                     continue
  830.            
  831.                 static Float:flOrigin[ 3 ]
  832.                 pev( victim, pev_origin, flOrigin )
  833.                
  834.                 static Float:flDistance, Float:flDamage
  835.                 flDistance = get_distance_f( ion_mid_origin[ id ], flOrigin )
  836.                
  837.                 flDamage = floatradius( get_pcvar_float( cvar_maxdmg ), get_pcvar_float( cvar_radius ), flDistance )
  838.                
  839.                 if( flDamage )
  840.                 {
  841.                     static Float:flHealth
  842.                     flHealth = entity_get_float( victim, EV_FL_health )
  843.                
  844.                     if( flHealth - flDamage >= 1 )
  845.                     {
  846.                         ExecuteHamB( Ham_TakeDamage, victim, g_Target[ id ], id, flDamage, DMG_BLAST )
  847.                     }
  848.                     else
  849.                     {
  850.                         g_bKilledByIon[ victim ] = true
  851.                         ExecuteHamB( Ham_Killed, victim, id, 2 )
  852.                         g_bKilledByIon[ victim ] = false
  853.                     }
  854.                 }
  855.             }
  856.         }
  857.     }
  858.    
  859.     client_cmd(0, "spk ^"%s^"", SOUND_ATTACK)
  860.     ResetAll(id)
  861. }
  862.  
  863. ResetAll(id)
  864. {  
  865.     if( !g_Target[ id ] )
  866.     {
  867.         remove_task( id )
  868.         return
  869.     }
  870.    
  871.     set_pev(g_Target[id], pev_flags, FL_KILLME)
  872.     g_Target[id] = 0
  873. }
  874.  
  875. /******************** Stocks ********************/
  876.  
  877. // Get entity above sky.
  878. stock Float:tlx_distance_to_sky(id)
  879. {  
  880.     new Float:TraceEnd[3]
  881.     pev(id, pev_origin, TraceEnd)
  882.        
  883.     new Float:f_dest[3]
  884.     f_dest[0] = TraceEnd[0]
  885.     f_dest[1] = TraceEnd[1]
  886.     f_dest[2] = TraceEnd[2] + 8192.0
  887.        
  888.     new res, Float:SkyOrigin[3]
  889.     engfunc(EngFunc_TraceLine, TraceEnd, f_dest, IGNORE_MONSTERS + IGNORE_GLASS, id, res)
  890.     get_tr2(res, TR_vecEndPos, SkyOrigin)
  891.    
  892.     return SkyOrigin
  893. }
  894.  
  895. //return distance above us to sky
  896. stock Float:is_user_outside(id)
  897. {
  898.     new Float:origin[3], Float:dist
  899.  
  900.     pev(id, pev_origin, origin)
  901.     dist = origin[2]
  902.  
  903.     while(engfunc(EngFunc_PointContents, origin) == CONTENTS_EMPTY)
  904.         origin[2] += 5.0
  905.     if(engfunc(EngFunc_PointContents, origin) == CONTENTS_SKY)
  906.         return (origin[2] - dist)
  907.  
  908.     return 0.0
  909. }
  910.  
  911. stock ProgressBar(id, seconds, position)
  912. {
  913.     message_begin(MSG_ONE, get_user_msgid("BarTime"), {0, 0, 0}, id)
  914.     write_byte(seconds)
  915.     write_byte(position)
  916.     message_end()
  917. }
  918.  
  919. SendWeaponAnim( id, Sequence )
  920. {
  921.     set_pev( id, pev_weaponanim, Sequence )
  922.    
  923.     message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id )
  924.     write_byte( Sequence )
  925.     write_byte( pev( id, pev_body ) )
  926.     message_end( )
  927. }
  928.  
  929. public UpdateAnim( id )
  930. {
  931.     if( !is_user_alive( id ) || ze_is_user_zombie( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
  932.         return
  933.            
  934.     SendWeaponAnim( id, anim_drop )
  935. }
  936.  
  937. stock Float:floatradius(Float:flMaxAmount, Float:flRadius, Float:flDistance)
  938. {
  939.     return floatsub(flMaxAmount, floatmul(floatdiv(flMaxAmount, flRadius), flDistance))
  940. }

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 576
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 47 times
Age: 19
Contact:

#15

Post by Jack GamePlay » 10 Months Ago

Try:

Code: Select all

#include <zombie_escape>
#include <engine>
#include <cstrike>
#include <fun>
#include <fakemeta_util>
 
 
new const PLUGIN[] = "[ZE] Extra Item:Ion Cannon"
new const VERSION[] = "1.0"
new const AUTHOR[] = "A.F./Mark"
 
//#define ION_RADIUS        2000.0
//#define ION_MAXDAMAGE     54200.0
#define ACTION_BLOCK        ( IN_JUMP | IN_DUCK | IN_FORWARD | IN_BACK | IN_LEFT | IN_RIGHT | IN_MOVELEFT | IN_MOVERIGHT | IN_RELOAD | IN_RUN | IN_USE)
 
new const V_MODEL[] = "models/v_c4.mdl"
new const W_MODEL[] = "models/w_battery.mdl"
 
new const SOUND_APPROACH[] = "zombie_plague/ion_canon/ion_approach2.wav"
new const SOUND_BEACON[] = "zombie_plague/ion_canon/ion_beacon_set.wav"
new const SOUND_STOP[] = "vox/_comma.wav"
new const SOUND_BEEP[] = "zombie_plague/ion_canon/ion_beep3.wav"
new const SOUND_ATTACK[] = "zombie_plague/ion_canon/ion_attack.wav"
new const SOUND_READY[] = "zombie_plague/ion_canon/ion_ready.wav"
new const SOUND_PLANT[] = "zombie_plague/ion_canon/ion_beacon_plant2.wav"
 
new g_iCurrentWeapon[33]
new bool:g_bHasIon[33]
new bool:g_bCanBuy
new bool:g_bIsFiring[33]
new bool:g_bKilledByIon[33]
new bool:g_bIsPlanting[33]
new g_iLastWeapon[33]
new g_Target[33]
new i_Pitch[33]
new Float:i_BeaconTime[33]
new Float:ion_mid_origin[33][3]
new Float:beam_origin[33][8][3]
new Float:g_degrees[33][8]
new Float:g_distance[33]
new Float:g_Speed[33]
new IonBeam, BlueFire, Shockwave, ReadyFire, BlueFlare, LaserFlame
new g_iIonID
new gmsgScreenShake
new g_iMaxids
new bool:g_bExploded /* This variable first initialized to false */
 
new cvar_barlen, cvar_maxdmg, cvar_radius, cvar_ionmode, cvar_damage
 
enum
{
    anim_idle,
    anim_draw,
    anim_drop,
    anim_pressbutton
}
 
public plugin_precache()
{
    precache_model(V_MODEL)
    precache_model(W_MODEL)
    precache_sound(SOUND_APPROACH)
    precache_sound(SOUND_BEACON)
    precache_sound(SOUND_BEEP)
    precache_sound(SOUND_ATTACK)
    precache_sound(SOUND_READY)
    precache_sound(SOUND_PLANT)
    precache_sound(SOUND_STOP)
    IonBeam = precache_model("sprites/ion_canon/ionbeam.spr")
    BlueFlare = precache_model("sprites/ion_canon/bflare.spr")
    ReadyFire = precache_model("sprites/ion_canon/fire.spr")
    BlueFire = precache_model("sprites/ion_canon/blueflame.spr")
    LaserFlame = precache_model("sprites/ion_canon/ion_laserflame.spr")
    Shockwave = precache_model("sprites/shockwave.spr")
}
 
public plugin_init()
{
    register_plugin( PLUGIN, VERSION, AUTHOR )
   
    g_iIonID = ze_register_item( "Ion Cannon", 100, 0)
   
    register_clcmd( "drop", "fn_Drop" )
   
    register_event( "CurWeapon", "EV_CurWeapon", "be", "1=1" )
    register_event( "DeathMsg", "EV_DeathMsg", "a" )
    register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" )
   
    register_forward( FM_CmdStart, "fw_CmdStart" )
    register_forward( FM_PlayerPreThink, "fw_idPreThink" )
   
    RegisterHam( Ham_Item_Deploy, "weapon_c4", "fw_KnifeDeploy_Post", 1 )
 
    register_message( get_user_msgid( "DeathMsg" ), "fn_DeathMsg" )
   
    gmsgScreenShake = get_user_msgid( "ScreenShake" )
   
    cvar_barlen = register_cvar( "ze_ion_barlen", "4" )
    cvar_maxdmg = register_cvar( "ze_ion_maxdmg", "54200" )
    cvar_radius = register_cvar( "ze_ion_radius", "2000" )
    cvar_ionmode = register_cvar( "ze_ion_mode", "1" ) // 0 - all zm damage, 1 - radius damage
    cvar_damage = register_cvar( "ze_ion_damage", "1000" ) // only if ze_ion_mode is 0
   
    g_iMaxids = get_maxplayers( )
}
 
public client_connect( id )
{
    g_bHasIon[ id ] = false
    g_bIsPlanting[ id ] = false
}
 
public client_disconnected( id )
{
    g_bHasIon[ id ] = false
}
 
public ze_game_started()
{
    g_bCanBuy = false
}
 
public ze_zombie_release()
{
    g_bCanBuy = true
}
 
public ze_select_item_pre(id, itemid)
{
    if (itemid != g_iIonID)
        return ZE_ITEM_AVAILABLE
 
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
 
    if (g_bHasIon[id] || !g_bCanBuy)
        return ZE_ITEM_UNAVAILABLE
 
    return ZE_ITEM_AVAILABLE
}
 
public ze_select_item_post(id, itemid)
{
    if( itemid == g_iIonID )
    {
        if( g_bHasIon[id] )
        {
            client_print( id, print_chat, "[ZE] Already have Ion Cannon" )
            return PLUGIN_HANDLED
        }
        else
        {
            g_bHasIon[id] = true
            give_item( id, "weapon_c4" )
        }
    }
    return PLUGIN_CONTINUE
}
 
public ze_user_infected(iVictim, iInfector)
{
    emit_sound(g_Target[iVictim], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    ProgressBar(iVictim, 0, 0)
    remove_task(iVictim+5000)
    g_bHasIon[ iVictim ] = false
    g_bIsFiring[ iVictim ] = false
    g_bIsPlanting[ iVictim ] = false
    g_Target[ iVictim ] = 0
}
 
public ze_user_humanized(id)
{
    g_bHasIon[id] = false
    emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    ProgressBar(id, 0, 0)
    remove_task(id+5000)
    g_bIsFiring[ id ] = false
    g_bIsPlanting[ id ] = false
    g_Target[ id ] = 0
}
 
public fn_Drop( id )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] )
        return PLUGIN_CONTINUE
   
    if( g_iCurrentWeapon[ id ] == CSW_C4 )
    {
        client_print( id, print_center, "* You cannot drop Ion Cannon *" )
        return PLUGIN_HANDLED
    }
    return PLUGIN_CONTINUE
}
 
public EV_CurWeapon( id )
{
    if( !is_user_alive( id ) )
        return PLUGIN_CONTINUE
       
    g_iCurrentWeapon[ id ] = read_data( 2 )
   
    return PLUGIN_CONTINUE
}
 
public EV_DeathMsg( )
{
    static iVictim
    iVictim = read_data( 2 )
   
    if( !is_user_connected( iVictim ) )
        return
       
    g_bHasIon[ iVictim ] = false
    g_bIsPlanting[ iVictim ] = false
}
 
public EV_RoundStart( )
{
    // Remove any ion cannons
    for( new i = 1; i < g_iMaxids; i++ )
    {
        if( g_Target[ i ] )
            emit_sound(g_Target[i], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
       
        if( is_user_alive( i ) )
        {
            ProgressBar(i, 0, 0)
            remove_task(i+5000)
            g_bHasIon[ i ] = false
            g_bIsFiring[ i ] = false
            g_bIsPlanting[ i ] = false
            g_Target[ i ] = 0
        }
    }
   
    static iEnt
    iEnt = -1
   
    while( ( iEnt = find_ent_by_class( iEnt, "info_target_ion" ) ) > 0 )
    {
        engfunc( EngFunc_RemoveEntity, iEnt )
    }
}
 
public fw_CmdStart( id, UC_Handle, Seed )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
        return FMRES_IGNORED
       
    static afButtons
    afButtons = get_uc( UC_Handle, UC_Buttons )
   
    if( afButtons & IN_ATTACK )
    {
        afButtons &= ~IN_ATTACK
        set_uc( UC_Handle, UC_Buttons, afButtons )
       
        if( g_bIsPlanting[ id ] )
        {
            //ProgressBar(id, 0, 0)
            return FMRES_IGNORED
        }
       
        if( g_Target[ id ] )
        {
            client_print( id, print_center, "* You already had planted Ion Cannon *" )
            g_bIsPlanting[ id ] = false
            return FMRES_IGNORED
        }
   
        if( is_user_outside( id ) )
        {
            g_Target[ id ] = 0
            i_Pitch[ id ] = 97
            i_BeaconTime[ id ] = 1.12
            g_distance[ id ] = 350.0
            g_Speed[ id ] = 0.0
           
           
            static iEnt
            iEnt = find_ent_by_owner( -1, "weapon_c4", id )
            set_pdata_float( iEnt, 48, 10.0, 4 )
           
            g_bIsFiring[ id ] = true
            g_bIsPlanting[ id ] = true
            emit_sound(id, CHAN_WEAPON, SOUND_BEACON, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
           
            g_iCurrentWeapon[ id ] = CSW_C4
           
            if( get_pcvar_num( cvar_barlen ) > 0 )
            {
                set_task( 3.6, "UpdateAnim" )
                SendWeaponAnim( id, anim_pressbutton )
                ProgressBar(id, get_pcvar_num( cvar_barlen ), 0)
                set_task(get_pcvar_float( cvar_barlen ),"ion_planted", id+5000)
            }
            else
            {
                set_task(0.2,"ion_planted", id+5000)
                SendWeaponAnim( id, anim_drop )
            }
        }
        else
        {
            g_bIsPlanting[ id ] = false
            client_print( id, print_center, "* To plant Ion Cannon you must be outside!!!*" )
            return FMRES_IGNORED
        }
    }
    return FMRES_HANDLED
}
 
public fw_PlayerPreThink( id )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] )
        return
   
    if( g_bIsFiring[ id ] )
    {
        g_iLastWeapon[ id ] = get_user_weapon( id )
       
        if( g_iCurrentWeapon[ id ] != CSW_C4 || g_iLastWeapon[ id ] != g_iCurrentWeapon[ id ] || get_user_button( id ) & ACTION_BLOCK )
        {
            emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
            ProgressBar(id, 0, 0)
            remove_task(id+5000)
            g_bIsFiring[ id ] = false
            g_bIsPlanting[ id ] = false
        }
    }
}
 
public fw_KnifeDeploy_Post( iEnt )
{
    static id
    id = get_pdata_cbase( iEnt, 41, 4 )
   
    if( g_bHasIon[ id ] )
    {
        set_pev( id, pev_viewmodel2, V_MODEL )
        SendWeaponAnim( id, anim_draw )
    }
}
 
public fn_DeathMsg( id, Dest, iEntity )
{
    static iVictim, iKiller
    iKiller = get_msg_arg_int( 1 )
    iVictim = get_msg_arg_int( 2 )
   
    if( !is_user_connected( iVictim ) || iKiller == iVictim )
        return PLUGIN_CONTINUE
   
    if ( g_bKilledByIon[ iVictim ] )
    {
        set_msg_arg_string ( 4, "ion cannon" )
    }
    return PLUGIN_CONTINUE
}
 
public ion_planted(id)
{  
    id -= 5000
   
    if( !is_user_alive( id ) || ze_is_user_zombie( id ) )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
   
    client_print(0, print_center, "Ion Cannon has been planted!")
    client_cmd(0, "spk %s", SOUND_PLANT)
    g_bIsFiring[id] = false
    g_bIsPlanting[ id ] = false
   
    static Weapon
    Weapon = find_ent_by_owner( -1, "weapon_c4", id )
   
    ExecuteHamB( Ham_Weapon_RetireWeapon, Weapon );
    ExecuteHamB( Ham_RemovePlayerItem, id, Weapon );
    ExecuteHamB( Ham_Item_Kill, Weapon );
 
    set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1 << CSW_C4) );
    cs_set_user_bpammo( id, CSW_C4, 0 );
    g_bHasIon[ id ] = false
 
    g_Target[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
    if(!g_Target[id]) return PLUGIN_HANDLED
 
    // Strings
    set_pev(g_Target[id],pev_classname,"info_target_ion")
    engfunc(EngFunc_SetModel,g_Target[id],W_MODEL)
 
    // Integer
    set_pev(g_Target[id],pev_owner, id)
    set_pev(g_Target[id],pev_movetype, MOVETYPE_TOSS)
    set_pev(g_Target[id],pev_solid, SOLID_TRIGGER)
 
    entity_get_vector(id,EV_VEC_origin, ion_mid_origin[id])
    //wpn_projectile_startpos(id,0,0,50,ion_mid_origin[id])
    //static Float:flOrigin[ 3 ]
    //pev( id, pev_origin, flOrigin )
    //engfunc( EngFunc_SetOrigin, g_Target[ id ], flOrigin )
    set_pev(g_Target[id],pev_origin,ion_mid_origin[id])
 
    ion_beacon(id)
    set_task(5.0,"ion_startup", id)
    return PLUGIN_CONTINUE
}
 
public ion_beacon(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
 
    i_Pitch[id] += 3
    i_BeaconTime[id] -= 0.03
    if(i_Pitch[id] > 255) i_Pitch[id] = 255
    if(i_BeaconTime[id] < 0.30) i_BeaconTime[id] = 0.30
    emit_sound(g_Target[id], CHAN_ITEM, SOUND_BEEP, VOL_NORM, ATTN_NORM, 0, i_Pitch[id])
    set_task(i_BeaconTime[id],"ion_beacon", id)
    return PLUGIN_CONTINUE
}
 
public ion_startup(id)
{
    client_cmd(0, "spk ^"%s^"", SOUND_APPROACH)
    client_print(0, print_chat,"Ion Cannon is approaching")
    set_task(5.0,"Trace_Ready", id)
}
 
public Trace_Ready(id)
{
    if( !pev_valid( id ) )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
       
    // write origin of each
    new Float:mid_origin[33][3]
    pev(g_Target[id],pev_origin,mid_origin[id]) // Target contain entity id
    // 1st
    beam_origin[id][0][0] = mid_origin[id][0] + 300.0
    beam_origin[id][0][1] = mid_origin[id][1] + 150.0
    beam_origin[id][0][2] = mid_origin[id][2]
    g_degrees[id][0] = 0.0
    // 2nd
    beam_origin[id][1][0] = mid_origin[id][0] + 300.0
    beam_origin[id][1][1] = mid_origin[id][1] - 150.0
    beam_origin[id][1][2] = mid_origin[id][2]
    g_degrees[id][1] = 45.0
    // 3rd
    beam_origin[id][2][0] = mid_origin[id][0] - 300.0
    beam_origin[id][2][1] = mid_origin[id][1] - 150.0
    beam_origin[id][2][2] = mid_origin[id][2]
    g_degrees[id][2] = 90.0
    // 4th
    beam_origin[id][3][0] = mid_origin[id][0] - 300.0
    beam_origin[id][3][1] = mid_origin[id][1] + 150.0
    beam_origin[id][3][2] = mid_origin[id][2]
    g_degrees[id][3] = 135.0
    // 5th
    beam_origin[id][4][0] = mid_origin[id][0] + 150.0
    beam_origin[id][4][1] = mid_origin[id][1] + 300.0
    beam_origin[id][4][2] = mid_origin[id][2]
    g_degrees[id][4] = 180.0
    // 6th
    beam_origin[id][5][0] = mid_origin[id][0] + 150.0
    beam_origin[id][5][1] = mid_origin[id][1] - 300.0
    beam_origin[id][5][2] = mid_origin[id][2]
    g_degrees[id][5] = 225.0
    // 7th
    beam_origin[id][6][0] = mid_origin[id][0] - 150.0
    beam_origin[id][6][1] = mid_origin[id][1] - 300.0
    beam_origin[id][6][2] = mid_origin[id][2]
    g_degrees[id][6] = 270.0
    // 8th
    beam_origin[id][7][0] = mid_origin[id][0] - 150.0
    beam_origin[id][7][1] = mid_origin[id][1] + 300.0
    beam_origin[id][7][2] = mid_origin[id][2]
    g_degrees[id][7] = 315.0
   
    // set the mid to global
    ion_mid_origin[id] = mid_origin[id]
 
    new Float:addtime
    for(new i = 0; i < 8; i++) {
        addtime = addtime + 0.3
        new param[3]
        param[0] = i
        param[1] = id
        set_task(0.0 + addtime, "Trace_Start", _,param, 2)
    }
    Laser_Rotate(id) //To fix the laserdraw
    client_cmd(0, "spk ^"%s^"", SOUND_READY)
   
    for(new Float:i = 0.0; i < 7.5; i += 0.01) //Rotate for 7.5 secs.
        set_task(i+3.0, "Laser_Rotate", id)
 
    set_task(2.9,"AddSpeed", id)
    set_task(11.5,"CreateFire", id)
    set_task(12.5,"ClearLasers", id)
    set_task(18.2,"FireIonCannon", id)
    return PLUGIN_CONTINUE
}
 
public AddSpeed(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
   
    if(g_Speed[id] > 1.0) g_Speed[id] = 1.0
    g_Speed[id] += 0.1
    set_task(0.6,"AddSpeed", id)
    return PLUGIN_CONTINUE
}
 
public CreateFire(id)
{
    if( !g_Target[ id ] )
    {
        g_bExploded = false
        remove_task( id )
        return PLUGIN_CONTINUE
    }
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
    write_short(ReadyFire)
    write_byte(30)
    write_byte(200)
    message_end()
 
    set_task(1.5,"CreateFire", id)
    return PLUGIN_CONTINUE
}
 
public ClearLasers(id)
{
    // Here we reset the variable
    g_bExploded = false
   
    ze_set_fire_grenade(id, false)
    remove_task(1018+id)
}
 
public Laser_Rotate(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    g_distance[id] -= 0.467
    for(new i = 0; i < 8; i++) {
        // Calculate new alpha
        g_degrees[id][i] += g_Speed[id]
        if(g_degrees[id][i] > 360.0)
            g_degrees[id][i] -= 360.0
 
        // calcul the next origin
        new Float:tmp[33][3]
        tmp[id] = ion_mid_origin[id]
 
        tmp[id][0] += floatsin(g_degrees[id][i], degrees) * g_distance[id]
        tmp[id][1] += floatcos(g_degrees[id][i], degrees) * g_distance[id]
        tmp[id][2] += 0.0 // -.-
        beam_origin[id][i] = tmp[id]
    }
}
 
public Trace_Start(param[])
{
    new i = param[0]
    new id = param[1]
 
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new Float:get_random_z,Float:SkyOrigin[33][3]
   
    if( is_user_alive( id ) )
    {
        SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
        get_random_z = random_float(300.0,SkyOrigin[id][2])
    }
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2] + get_random_z)
    write_short(BlueFire)
    write_byte(10)
    write_byte(100)
    message_end()
   
    TraceAll(param)
}
 
public TraceAll(param[])
{
    new i = param[0]
    new id = param[1]
   
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new Float:SkyOrigin[33][3]
    SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_BEAMPOINTS)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //start point (x)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //start point (y)
    engfunc(EngFunc_WriteCoord, SkyOrigin[id][2])           //start point (z)
 
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //end point (x)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //end point (y)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])      //end point (z)
    write_short(IonBeam)    //model
    write_byte(0)       //startframe
    write_byte(0)       //framerate
    write_byte(1)       //life
    write_byte(50)      //width
    write_byte(0)       //noise
    write_byte(255)     //r
    write_byte(255)     //g
    write_byte(255)     //b
    write_byte(255)     //brightness
    write_byte(0)       //speed
    message_end()
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
    write_short(LaserFlame)
    write_byte(5)
    write_byte(200)
    message_end()
 
    /*message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(TE_WORLDDECAL)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
    write_byte(46)
    message_end()*/
 
    set_task(0.08,"TraceAll", 1018+id, param, 2)
}
 
public FireIonCannon(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new i = -1
    while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
    {
        if( !is_user_connected( i ))
            continue
           
        if( pev(i, pev_flags) & (FL_CLIENT | FL_FAKECLIENT))
        {
            message_begin(MSG_ONE_UNRELIABLE, gmsgScreenShake, {0,0,0}, i)
            write_short(255<<14) //ammount
            write_short(10<<14) //lasts this long
            write_short(255<<14) //frequency
            message_end()
   
			if (ze_is_user_zombie(i))
				ze_set_fire_grenade(i, true)

			// After this we turn the variable to true so not to be called next call
			g_bExploded = true
        }
        //next player in spehre.
        continue
    }
 
    new Float:skyOrigin[33][3]
    skyOrigin[id] = tlx_distance_to_sky(g_Target[id])
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
    write_byte(TE_BEAMPOINTS)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][0])   //start point (x)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][1])   //start point (y)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][2])   //start point (z)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])      //end point (x)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])      //end point (y)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])      //end point (z)
    write_short(IonBeam)    //model
    write_byte(0)       //startframe
    write_byte(0)       //framerate
    write_byte(15)      //life
    write_byte(255)     //width
    write_byte(0)       //noise
    write_byte(255)     //r
    write_byte(255)     //g
    write_byte(255)     //b
    write_byte(255)     //brightness
    write_byte(0)       //speed
    message_end()
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin, 0)
    write_byte(TE_BEAMCYLINDER)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // start X
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // start Y
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2]) // start Z
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // something X
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // something Y
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + get_pcvar_float( cvar_radius ) - 1000.0) // something Z
    write_short(Shockwave) // sprite
    write_byte(0) // startframe
    write_byte(0) // framerate
    write_byte(100) // life
    write_byte(150) // width
    write_byte(0) // noise
    write_byte(0) // red
    write_byte(100) // green
    write_byte(250) // blue
    write_byte(150) // brightness
    write_byte(0) // speed
    message_end()
 
    for(new i = 1; i < 6; i++)
    {
        engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
        write_byte(TE_SPRITETRAIL)  // line of moving glow sprites with gravity, fadeout, and collisions
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 200)
        write_short(BlueFlare) // (sprite index)
        write_byte(50) // (count)
        write_byte(random_num(27,30)) // (life in 0.1's)
        write_byte(10) // byte (scale in 0.1's)
        write_byte(random_num(30,70)) // (velocity along vector in 10's)
        write_byte(40) // (randomness of velocity in 10's)
        message_end()
    }
   
    switch( get_pcvar_num( cvar_ionmode ) )
    {
        case 0:
        {
            for( new i = 1; i < g_iMaxids; i++ )
            {
                if( is_user_alive( i ) && ze_is_user_zombie( i ) )
                {
                    static Float:flHealth
                    flHealth = entity_get_float( i, EV_FL_health )
               
                    static Float:flDamage
                    flDamage = get_pcvar_float( cvar_damage )
               
                    if( flHealth - flDamage >= 1 )
                    {
                        ExecuteHamB( Ham_TakeDamage, i, g_Target[ id ], id, flDamage, DMG_BLAST )
                    }
                    else
                    {
                        g_bKilledByIon[ i ] = true
                        ExecuteHamB( Ham_Killed, i, id, 2 )
                        g_bKilledByIon[ i ] = false
                    }
                }
            }
        }
        case 1:
        {
            static victim
            victim = -1
           
            while ( ( victim = engfunc( EngFunc_FindEntityInSphere, victim, ion_mid_origin[id], get_pcvar_float( cvar_radius ) ) ) != 0 )
            {
                if( !is_user_connected( victim ) )
                {
                    if( pev_valid( victim ) )
                    {
                        static szClassname[ 32 ]
                        pev( victim, pev_classname, szClassname, 31 )
                       
                        if( equal( szClassname, "func_breakable" ) )
                        {
                            force_use( id, victim )
                        }
                    }
                    continue
                }
               
                if ( !is_user_alive( victim ) )
                    continue
               
                if( !ze_is_user_zombie( victim ) )
                    continue
           
                static Float:flOrigin[ 3 ]
                pev( victim, pev_origin, flOrigin )
               
                static Float:flDistance, Float:flDamage
                flDistance = get_distance_f( ion_mid_origin[ id ], flOrigin )
               
                flDamage = floatradius( get_pcvar_float( cvar_maxdmg ), get_pcvar_float( cvar_radius ), flDistance )
               
                if( flDamage )
                {
                    static Float:flHealth
                    flHealth = entity_get_float( victim, EV_FL_health )
               
                    if( flHealth - flDamage >= 1 )
                    {
                        ExecuteHamB( Ham_TakeDamage, victim, g_Target[ id ], id, flDamage, DMG_BLAST )
                    }
                    else
                    {
                        g_bKilledByIon[ victim ] = true
                        ExecuteHamB( Ham_Killed, victim, id, 2 )
                        g_bKilledByIon[ victim ] = false
                    }
                }
            }
        }
    }
   
    client_cmd(0, "spk ^"%s^"", SOUND_ATTACK)
    ResetAll(id)
}
 
ResetAll(id)
{  
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    set_pev(g_Target[id], pev_flags, FL_KILLME)
    g_Target[id] = 0
}
 
/******************** Stocks ********************/
 
// Get entity above sky.
stock Float:tlx_distance_to_sky(id)
{  
    new Float:TraceEnd[3]
    pev(id, pev_origin, TraceEnd)
       
    new Float:f_dest[3]
    f_dest[0] = TraceEnd[0]
    f_dest[1] = TraceEnd[1]
    f_dest[2] = TraceEnd[2] + 8192.0
       
    new res, Float:SkyOrigin[3]
    engfunc(EngFunc_TraceLine, TraceEnd, f_dest, IGNORE_MONSTERS + IGNORE_GLASS, id, res)
    get_tr2(res, TR_vecEndPos, SkyOrigin)
   
    return SkyOrigin
}
 
//return distance above us to sky
stock Float:is_user_outside(id)
{
    new Float:origin[3], Float:dist
 
    pev(id, pev_origin, origin)
    dist = origin[2]
 
    while(engfunc(EngFunc_PointContents, origin) == CONTENTS_EMPTY)
        origin[2] += 5.0
    if(engfunc(EngFunc_PointContents, origin) == CONTENTS_SKY)
        return (origin[2] - dist)
 
    return 0.0
}
 
stock ProgressBar(id, seconds, position)
{
    message_begin(MSG_ONE, get_user_msgid("BarTime"), {0, 0, 0}, id)
    write_byte(seconds)
    write_byte(position)
    message_end()
}
 
SendWeaponAnim( id, Sequence )
{
    set_pev( id, pev_weaponanim, Sequence )
   
    message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id )
    write_byte( Sequence )
    write_byte( pev( id, pev_body ) )
    message_end( )
}
 
public UpdateAnim( id )
{
    if( !is_user_alive( id ) || ze_is_user_zombie( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
        return
           
    SendWeaponAnim( id, anim_drop )
}
 
stock Float:floatradius(Float:flMaxAmount, Float:flRadius, Float:flDistance)
{
    return floatsub(flMaxAmount, floatmul(floatdiv(flMaxAmount, flRadius), flDistance))
}
Not interested in CS/Pawn anymore.
Accepting web projects.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 281
Joined: 11 Months Ago
Location: Des Moines/USA
Has thanked: 6 times
Been thanked: 21 times
Age: 33
Contact:

#16

Post by Mark » 9 Months Ago

Jack GamePlay wrote:
10 Months Ago
Try:

Code: Select all

#include <zombie_escape>
#include <engine>
#include <cstrike>
#include <fun>
#include <fakemeta_util>
 
 
new const PLUGIN[] = "[ZE] Extra Item:Ion Cannon"
new const VERSION[] = "1.0"
new const AUTHOR[] = "A.F./Mark"
 
//#define ION_RADIUS        2000.0
//#define ION_MAXDAMAGE     54200.0
#define ACTION_BLOCK        ( IN_JUMP | IN_DUCK | IN_FORWARD | IN_BACK | IN_LEFT | IN_RIGHT | IN_MOVELEFT | IN_MOVERIGHT | IN_RELOAD | IN_RUN | IN_USE)
 
new const V_MODEL[] = "models/v_c4.mdl"
new const W_MODEL[] = "models/w_battery.mdl"
 
new const SOUND_APPROACH[] = "zombie_plague/ion_canon/ion_approach2.wav"
new const SOUND_BEACON[] = "zombie_plague/ion_canon/ion_beacon_set.wav"
new const SOUND_STOP[] = "vox/_comma.wav"
new const SOUND_BEEP[] = "zombie_plague/ion_canon/ion_beep3.wav"
new const SOUND_ATTACK[] = "zombie_plague/ion_canon/ion_attack.wav"
new const SOUND_READY[] = "zombie_plague/ion_canon/ion_ready.wav"
new const SOUND_PLANT[] = "zombie_plague/ion_canon/ion_beacon_plant2.wav"
 
new g_iCurrentWeapon[33]
new bool:g_bHasIon[33]
new bool:g_bCanBuy
new bool:g_bIsFiring[33]
new bool:g_bKilledByIon[33]
new bool:g_bIsPlanting[33]
new g_iLastWeapon[33]
new g_Target[33]
new i_Pitch[33]
new Float:i_BeaconTime[33]
new Float:ion_mid_origin[33][3]
new Float:beam_origin[33][8][3]
new Float:g_degrees[33][8]
new Float:g_distance[33]
new Float:g_Speed[33]
new IonBeam, BlueFire, Shockwave, ReadyFire, BlueFlare, LaserFlame
new g_iIonID
new gmsgScreenShake
new g_iMaxids
new bool:g_bExploded /* This variable first initialized to false */
 
new cvar_barlen, cvar_maxdmg, cvar_radius, cvar_ionmode, cvar_damage
 
enum
{
    anim_idle,
    anim_draw,
    anim_drop,
    anim_pressbutton
}
 
public plugin_precache()
{
    precache_model(V_MODEL)
    precache_model(W_MODEL)
    precache_sound(SOUND_APPROACH)
    precache_sound(SOUND_BEACON)
    precache_sound(SOUND_BEEP)
    precache_sound(SOUND_ATTACK)
    precache_sound(SOUND_READY)
    precache_sound(SOUND_PLANT)
    precache_sound(SOUND_STOP)
    IonBeam = precache_model("sprites/ion_canon/ionbeam.spr")
    BlueFlare = precache_model("sprites/ion_canon/bflare.spr")
    ReadyFire = precache_model("sprites/ion_canon/fire.spr")
    BlueFire = precache_model("sprites/ion_canon/blueflame.spr")
    LaserFlame = precache_model("sprites/ion_canon/ion_laserflame.spr")
    Shockwave = precache_model("sprites/shockwave.spr")
}
 
public plugin_init()
{
    register_plugin( PLUGIN, VERSION, AUTHOR )
   
    g_iIonID = ze_register_item( "Ion Cannon", 100, 0)
   
    register_clcmd( "drop", "fn_Drop" )
   
    register_event( "CurWeapon", "EV_CurWeapon", "be", "1=1" )
    register_event( "DeathMsg", "EV_DeathMsg", "a" )
    register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" )
   
    register_forward( FM_CmdStart, "fw_CmdStart" )
    register_forward( FM_PlayerPreThink, "fw_idPreThink" )
   
    RegisterHam( Ham_Item_Deploy, "weapon_c4", "fw_KnifeDeploy_Post", 1 )
 
    register_message( get_user_msgid( "DeathMsg" ), "fn_DeathMsg" )
   
    gmsgScreenShake = get_user_msgid( "ScreenShake" )
   
    cvar_barlen = register_cvar( "ze_ion_barlen", "4" )
    cvar_maxdmg = register_cvar( "ze_ion_maxdmg", "54200" )
    cvar_radius = register_cvar( "ze_ion_radius", "2000" )
    cvar_ionmode = register_cvar( "ze_ion_mode", "1" ) // 0 - all zm damage, 1 - radius damage
    cvar_damage = register_cvar( "ze_ion_damage", "1000" ) // only if ze_ion_mode is 0
   
    g_iMaxids = get_maxplayers( )
}
 
public client_connect( id )
{
    g_bHasIon[ id ] = false
    g_bIsPlanting[ id ] = false
}
 
public client_disconnected( id )
{
    g_bHasIon[ id ] = false
}
 
public ze_game_started()
{
    g_bCanBuy = false
}
 
public ze_zombie_release()
{
    g_bCanBuy = true
}
 
public ze_select_item_pre(id, itemid)
{
    if (itemid != g_iIonID)
        return ZE_ITEM_AVAILABLE
 
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
 
    if (g_bHasIon[id] || !g_bCanBuy)
        return ZE_ITEM_UNAVAILABLE
 
    return ZE_ITEM_AVAILABLE
}
 
public ze_select_item_post(id, itemid)
{
    if( itemid == g_iIonID )
    {
        if( g_bHasIon[id] )
        {
            client_print( id, print_chat, "[ZE] Already have Ion Cannon" )
            return PLUGIN_HANDLED
        }
        else
        {
            g_bHasIon[id] = true
            give_item( id, "weapon_c4" )
        }
    }
    return PLUGIN_CONTINUE
}
 
public ze_user_infected(iVictim, iInfector)
{
    emit_sound(g_Target[iVictim], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    ProgressBar(iVictim, 0, 0)
    remove_task(iVictim+5000)
    g_bHasIon[ iVictim ] = false
    g_bIsFiring[ iVictim ] = false
    g_bIsPlanting[ iVictim ] = false
    g_Target[ iVictim ] = 0
}
 
public ze_user_humanized(id)
{
    g_bHasIon[id] = false
    emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    ProgressBar(id, 0, 0)
    remove_task(id+5000)
    g_bIsFiring[ id ] = false
    g_bIsPlanting[ id ] = false
    g_Target[ id ] = 0
}
 
public fn_Drop( id )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] )
        return PLUGIN_CONTINUE
   
    if( g_iCurrentWeapon[ id ] == CSW_C4 )
    {
        client_print( id, print_center, "* You cannot drop Ion Cannon *" )
        return PLUGIN_HANDLED
    }
    return PLUGIN_CONTINUE
}
 
public EV_CurWeapon( id )
{
    if( !is_user_alive( id ) )
        return PLUGIN_CONTINUE
       
    g_iCurrentWeapon[ id ] = read_data( 2 )
   
    return PLUGIN_CONTINUE
}
 
public EV_DeathMsg( )
{
    static iVictim
    iVictim = read_data( 2 )
   
    if( !is_user_connected( iVictim ) )
        return
       
    g_bHasIon[ iVictim ] = false
    g_bIsPlanting[ iVictim ] = false
}
 
public EV_RoundStart( )
{
    // Remove any ion cannons
    for( new i = 1; i < g_iMaxids; i++ )
    {
        if( g_Target[ i ] )
            emit_sound(g_Target[i], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
       
        if( is_user_alive( i ) )
        {
            ProgressBar(i, 0, 0)
            remove_task(i+5000)
            g_bHasIon[ i ] = false
            g_bIsFiring[ i ] = false
            g_bIsPlanting[ i ] = false
            g_Target[ i ] = 0
        }
    }
   
    static iEnt
    iEnt = -1
   
    while( ( iEnt = find_ent_by_class( iEnt, "info_target_ion" ) ) > 0 )
    {
        engfunc( EngFunc_RemoveEntity, iEnt )
    }
}
 
public fw_CmdStart( id, UC_Handle, Seed )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
        return FMRES_IGNORED
       
    static afButtons
    afButtons = get_uc( UC_Handle, UC_Buttons )
   
    if( afButtons & IN_ATTACK )
    {
        afButtons &= ~IN_ATTACK
        set_uc( UC_Handle, UC_Buttons, afButtons )
       
        if( g_bIsPlanting[ id ] )
        {
            //ProgressBar(id, 0, 0)
            return FMRES_IGNORED
        }
       
        if( g_Target[ id ] )
        {
            client_print( id, print_center, "* You already had planted Ion Cannon *" )
            g_bIsPlanting[ id ] = false
            return FMRES_IGNORED
        }
   
        if( is_user_outside( id ) )
        {
            g_Target[ id ] = 0
            i_Pitch[ id ] = 97
            i_BeaconTime[ id ] = 1.12
            g_distance[ id ] = 350.0
            g_Speed[ id ] = 0.0
           
           
            static iEnt
            iEnt = find_ent_by_owner( -1, "weapon_c4", id )
            set_pdata_float( iEnt, 48, 10.0, 4 )
           
            g_bIsFiring[ id ] = true
            g_bIsPlanting[ id ] = true
            emit_sound(id, CHAN_WEAPON, SOUND_BEACON, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
           
            g_iCurrentWeapon[ id ] = CSW_C4
           
            if( get_pcvar_num( cvar_barlen ) > 0 )
            {
                set_task( 3.6, "UpdateAnim" )
                SendWeaponAnim( id, anim_pressbutton )
                ProgressBar(id, get_pcvar_num( cvar_barlen ), 0)
                set_task(get_pcvar_float( cvar_barlen ),"ion_planted", id+5000)
            }
            else
            {
                set_task(0.2,"ion_planted", id+5000)
                SendWeaponAnim( id, anim_drop )
            }
        }
        else
        {
            g_bIsPlanting[ id ] = false
            client_print( id, print_center, "* To plant Ion Cannon you must be outside!!!*" )
            return FMRES_IGNORED
        }
    }
    return FMRES_HANDLED
}
 
public fw_PlayerPreThink( id )
{
    if( !is_user_alive( id ) || !g_bHasIon[ id ] )
        return
   
    if( g_bIsFiring[ id ] )
    {
        g_iLastWeapon[ id ] = get_user_weapon( id )
       
        if( g_iCurrentWeapon[ id ] != CSW_C4 || g_iLastWeapon[ id ] != g_iCurrentWeapon[ id ] || get_user_button( id ) & ACTION_BLOCK )
        {
            emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
            ProgressBar(id, 0, 0)
            remove_task(id+5000)
            g_bIsFiring[ id ] = false
            g_bIsPlanting[ id ] = false
        }
    }
}
 
public fw_KnifeDeploy_Post( iEnt )
{
    static id
    id = get_pdata_cbase( iEnt, 41, 4 )
   
    if( g_bHasIon[ id ] )
    {
        set_pev( id, pev_viewmodel2, V_MODEL )
        SendWeaponAnim( id, anim_draw )
    }
}
 
public fn_DeathMsg( id, Dest, iEntity )
{
    static iVictim, iKiller
    iKiller = get_msg_arg_int( 1 )
    iVictim = get_msg_arg_int( 2 )
   
    if( !is_user_connected( iVictim ) || iKiller == iVictim )
        return PLUGIN_CONTINUE
   
    if ( g_bKilledByIon[ iVictim ] )
    {
        set_msg_arg_string ( 4, "ion cannon" )
    }
    return PLUGIN_CONTINUE
}
 
public ion_planted(id)
{  
    id -= 5000
   
    if( !is_user_alive( id ) || ze_is_user_zombie( id ) )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
   
    client_print(0, print_center, "Ion Cannon has been planted!")
    client_cmd(0, "spk %s", SOUND_PLANT)
    g_bIsFiring[id] = false
    g_bIsPlanting[ id ] = false
   
    static Weapon
    Weapon = find_ent_by_owner( -1, "weapon_c4", id )
   
    ExecuteHamB( Ham_Weapon_RetireWeapon, Weapon );
    ExecuteHamB( Ham_RemovePlayerItem, id, Weapon );
    ExecuteHamB( Ham_Item_Kill, Weapon );
 
    set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1 << CSW_C4) );
    cs_set_user_bpammo( id, CSW_C4, 0 );
    g_bHasIon[ id ] = false
 
    g_Target[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
    if(!g_Target[id]) return PLUGIN_HANDLED
 
    // Strings
    set_pev(g_Target[id],pev_classname,"info_target_ion")
    engfunc(EngFunc_SetModel,g_Target[id],W_MODEL)
 
    // Integer
    set_pev(g_Target[id],pev_owner, id)
    set_pev(g_Target[id],pev_movetype, MOVETYPE_TOSS)
    set_pev(g_Target[id],pev_solid, SOLID_TRIGGER)
 
    entity_get_vector(id,EV_VEC_origin, ion_mid_origin[id])
    //wpn_projectile_startpos(id,0,0,50,ion_mid_origin[id])
    //static Float:flOrigin[ 3 ]
    //pev( id, pev_origin, flOrigin )
    //engfunc( EngFunc_SetOrigin, g_Target[ id ], flOrigin )
    set_pev(g_Target[id],pev_origin,ion_mid_origin[id])
 
    ion_beacon(id)
    set_task(5.0,"ion_startup", id)
    return PLUGIN_CONTINUE
}
 
public ion_beacon(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
 
    i_Pitch[id] += 3
    i_BeaconTime[id] -= 0.03
    if(i_Pitch[id] > 255) i_Pitch[id] = 255
    if(i_BeaconTime[id] < 0.30) i_BeaconTime[id] = 0.30
    emit_sound(g_Target[id], CHAN_ITEM, SOUND_BEEP, VOL_NORM, ATTN_NORM, 0, i_Pitch[id])
    set_task(i_BeaconTime[id],"ion_beacon", id)
    return PLUGIN_CONTINUE
}
 
public ion_startup(id)
{
    client_cmd(0, "spk ^"%s^"", SOUND_APPROACH)
    client_print(0, print_chat,"Ion Cannon is approaching")
    set_task(5.0,"Trace_Ready", id)
}
 
public Trace_Ready(id)
{
    if( !pev_valid( id ) )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
       
    // write origin of each
    new Float:mid_origin[33][3]
    pev(g_Target[id],pev_origin,mid_origin[id]) // Target contain entity id
    // 1st
    beam_origin[id][0][0] = mid_origin[id][0] + 300.0
    beam_origin[id][0][1] = mid_origin[id][1] + 150.0
    beam_origin[id][0][2] = mid_origin[id][2]
    g_degrees[id][0] = 0.0
    // 2nd
    beam_origin[id][1][0] = mid_origin[id][0] + 300.0
    beam_origin[id][1][1] = mid_origin[id][1] - 150.0
    beam_origin[id][1][2] = mid_origin[id][2]
    g_degrees[id][1] = 45.0
    // 3rd
    beam_origin[id][2][0] = mid_origin[id][0] - 300.0
    beam_origin[id][2][1] = mid_origin[id][1] - 150.0
    beam_origin[id][2][2] = mid_origin[id][2]
    g_degrees[id][2] = 90.0
    // 4th
    beam_origin[id][3][0] = mid_origin[id][0] - 300.0
    beam_origin[id][3][1] = mid_origin[id][1] + 150.0
    beam_origin[id][3][2] = mid_origin[id][2]
    g_degrees[id][3] = 135.0
    // 5th
    beam_origin[id][4][0] = mid_origin[id][0] + 150.0
    beam_origin[id][4][1] = mid_origin[id][1] + 300.0
    beam_origin[id][4][2] = mid_origin[id][2]
    g_degrees[id][4] = 180.0
    // 6th
    beam_origin[id][5][0] = mid_origin[id][0] + 150.0
    beam_origin[id][5][1] = mid_origin[id][1] - 300.0
    beam_origin[id][5][2] = mid_origin[id][2]
    g_degrees[id][5] = 225.0
    // 7th
    beam_origin[id][6][0] = mid_origin[id][0] - 150.0
    beam_origin[id][6][1] = mid_origin[id][1] - 300.0
    beam_origin[id][6][2] = mid_origin[id][2]
    g_degrees[id][6] = 270.0
    // 8th
    beam_origin[id][7][0] = mid_origin[id][0] - 150.0
    beam_origin[id][7][1] = mid_origin[id][1] + 300.0
    beam_origin[id][7][2] = mid_origin[id][2]
    g_degrees[id][7] = 315.0
   
    // set the mid to global
    ion_mid_origin[id] = mid_origin[id]
 
    new Float:addtime
    for(new i = 0; i < 8; i++) {
        addtime = addtime + 0.3
        new param[3]
        param[0] = i
        param[1] = id
        set_task(0.0 + addtime, "Trace_Start", _,param, 2)
    }
    Laser_Rotate(id) //To fix the laserdraw
    client_cmd(0, "spk ^"%s^"", SOUND_READY)
   
    for(new Float:i = 0.0; i < 7.5; i += 0.01) //Rotate for 7.5 secs.
        set_task(i+3.0, "Laser_Rotate", id)
 
    set_task(2.9,"AddSpeed", id)
    set_task(11.5,"CreateFire", id)
    set_task(12.5,"ClearLasers", id)
    set_task(18.2,"FireIonCannon", id)
    return PLUGIN_CONTINUE
}
 
public AddSpeed(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return PLUGIN_CONTINUE
    }
   
    if(g_Speed[id] > 1.0) g_Speed[id] = 1.0
    g_Speed[id] += 0.1
    set_task(0.6,"AddSpeed", id)
    return PLUGIN_CONTINUE
}
 
public CreateFire(id)
{
    if( !g_Target[ id ] )
    {
        g_bExploded = false
        remove_task( id )
        return PLUGIN_CONTINUE
    }
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
    write_short(ReadyFire)
    write_byte(30)
    write_byte(200)
    message_end()
 
    set_task(1.5,"CreateFire", id)
    return PLUGIN_CONTINUE
}
 
public ClearLasers(id)
{
    // Here we reset the variable
    g_bExploded = false
   
    ze_set_fire_grenade(id, false)
    remove_task(1018+id)
}
 
public Laser_Rotate(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    g_distance[id] -= 0.467
    for(new i = 0; i < 8; i++) {
        // Calculate new alpha
        g_degrees[id][i] += g_Speed[id]
        if(g_degrees[id][i] > 360.0)
            g_degrees[id][i] -= 360.0
 
        // calcul the next origin
        new Float:tmp[33][3]
        tmp[id] = ion_mid_origin[id]
 
        tmp[id][0] += floatsin(g_degrees[id][i], degrees) * g_distance[id]
        tmp[id][1] += floatcos(g_degrees[id][i], degrees) * g_distance[id]
        tmp[id][2] += 0.0 // -.-
        beam_origin[id][i] = tmp[id]
    }
}
 
public Trace_Start(param[])
{
    new i = param[0]
    new id = param[1]
 
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new Float:get_random_z,Float:SkyOrigin[33][3]
   
    if( is_user_alive( id ) )
    {
        SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
        get_random_z = random_float(300.0,SkyOrigin[id][2])
    }
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2] + get_random_z)
    write_short(BlueFire)
    write_byte(10)
    write_byte(100)
    message_end()
   
    TraceAll(param)
}
 
public TraceAll(param[])
{
    new i = param[0]
    new id = param[1]
   
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new Float:SkyOrigin[33][3]
    SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_BEAMPOINTS)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //start point (x)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //start point (y)
    engfunc(EngFunc_WriteCoord, SkyOrigin[id][2])           //start point (z)
 
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //end point (x)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //end point (y)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])      //end point (z)
    write_short(IonBeam)    //model
    write_byte(0)       //startframe
    write_byte(0)       //framerate
    write_byte(1)       //life
    write_byte(50)      //width
    write_byte(0)       //noise
    write_byte(255)     //r
    write_byte(255)     //g
    write_byte(255)     //b
    write_byte(255)     //brightness
    write_byte(0)       //speed
    message_end()
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
    write_byte(TE_SPRITE)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
    write_short(LaserFlame)
    write_byte(5)
    write_byte(200)
    message_end()
 
    /*message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(TE_WORLDDECAL)
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
    engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
    write_byte(46)
    message_end()*/
 
    set_task(0.08,"TraceAll", 1018+id, param, 2)
}
 
public FireIonCannon(id)
{
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    new i = -1
    while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
    {
        if( !is_user_connected( i ))
            continue
           
        if( pev(i, pev_flags) & (FL_CLIENT | FL_FAKECLIENT))
        {
            message_begin(MSG_ONE_UNRELIABLE, gmsgScreenShake, {0,0,0}, i)
            write_short(255<<14) //ammount
            write_short(10<<14) //lasts this long
            write_short(255<<14) //frequency
            message_end()
   
			if (ze_is_user_zombie(i))
				ze_set_fire_grenade(i, true)

			// After this we turn the variable to true so not to be called next call
			g_bExploded = true
        }
        //next player in spehre.
        continue
    }
 
    new Float:skyOrigin[33][3]
    skyOrigin[id] = tlx_distance_to_sky(g_Target[id])
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
    write_byte(TE_BEAMPOINTS)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][0])   //start point (x)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][1])   //start point (y)
    engfunc(EngFunc_WriteCoord, skyOrigin[id][2])   //start point (z)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])      //end point (x)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])      //end point (y)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])      //end point (z)
    write_short(IonBeam)    //model
    write_byte(0)       //startframe
    write_byte(0)       //framerate
    write_byte(15)      //life
    write_byte(255)     //width
    write_byte(0)       //noise
    write_byte(255)     //r
    write_byte(255)     //g
    write_byte(255)     //b
    write_byte(255)     //brightness
    write_byte(0)       //speed
    message_end()
 
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin, 0)
    write_byte(TE_BEAMCYLINDER)
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // start X
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // start Y
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2]) // start Z
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0]) // something X
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1]) // something Y
    engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + get_pcvar_float( cvar_radius ) - 1000.0) // something Z
    write_short(Shockwave) // sprite
    write_byte(0) // startframe
    write_byte(0) // framerate
    write_byte(100) // life
    write_byte(150) // width
    write_byte(0) // noise
    write_byte(0) // red
    write_byte(100) // green
    write_byte(250) // blue
    write_byte(150) // brightness
    write_byte(0) // speed
    message_end()
 
    for(new i = 1; i < 6; i++)
    {
        engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
        write_byte(TE_SPRITETRAIL)  // line of moving glow sprites with gravity, fadeout, and collisions
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
        engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 200)
        write_short(BlueFlare) // (sprite index)
        write_byte(50) // (count)
        write_byte(random_num(27,30)) // (life in 0.1's)
        write_byte(10) // byte (scale in 0.1's)
        write_byte(random_num(30,70)) // (velocity along vector in 10's)
        write_byte(40) // (randomness of velocity in 10's)
        message_end()
    }
   
    switch( get_pcvar_num( cvar_ionmode ) )
    {
        case 0:
        {
            for( new i = 1; i < g_iMaxids; i++ )
            {
                if( is_user_alive( i ) && ze_is_user_zombie( i ) )
                {
                    static Float:flHealth
                    flHealth = entity_get_float( i, EV_FL_health )
               
                    static Float:flDamage
                    flDamage = get_pcvar_float( cvar_damage )
               
                    if( flHealth - flDamage >= 1 )
                    {
                        ExecuteHamB( Ham_TakeDamage, i, g_Target[ id ], id, flDamage, DMG_BLAST )
                    }
                    else
                    {
                        g_bKilledByIon[ i ] = true
                        ExecuteHamB( Ham_Killed, i, id, 2 )
                        g_bKilledByIon[ i ] = false
                    }
                }
            }
        }
        case 1:
        {
            static victim
            victim = -1
           
            while ( ( victim = engfunc( EngFunc_FindEntityInSphere, victim, ion_mid_origin[id], get_pcvar_float( cvar_radius ) ) ) != 0 )
            {
                if( !is_user_connected( victim ) )
                {
                    if( pev_valid( victim ) )
                    {
                        static szClassname[ 32 ]
                        pev( victim, pev_classname, szClassname, 31 )
                       
                        if( equal( szClassname, "func_breakable" ) )
                        {
                            force_use( id, victim )
                        }
                    }
                    continue
                }
               
                if ( !is_user_alive( victim ) )
                    continue
               
                if( !ze_is_user_zombie( victim ) )
                    continue
           
                static Float:flOrigin[ 3 ]
                pev( victim, pev_origin, flOrigin )
               
                static Float:flDistance, Float:flDamage
                flDistance = get_distance_f( ion_mid_origin[ id ], flOrigin )
               
                flDamage = floatradius( get_pcvar_float( cvar_maxdmg ), get_pcvar_float( cvar_radius ), flDistance )
               
                if( flDamage )
                {
                    static Float:flHealth
                    flHealth = entity_get_float( victim, EV_FL_health )
               
                    if( flHealth - flDamage >= 1 )
                    {
                        ExecuteHamB( Ham_TakeDamage, victim, g_Target[ id ], id, flDamage, DMG_BLAST )
                    }
                    else
                    {
                        g_bKilledByIon[ victim ] = true
                        ExecuteHamB( Ham_Killed, victim, id, 2 )
                        g_bKilledByIon[ victim ] = false
                    }
                }
            }
        }
    }
   
    client_cmd(0, "spk ^"%s^"", SOUND_ATTACK)
    ResetAll(id)
}
 
ResetAll(id)
{  
    if( !g_Target[ id ] )
    {
        remove_task( id )
        return
    }
   
    set_pev(g_Target[id], pev_flags, FL_KILLME)
    g_Target[id] = 0
}
 
/******************** Stocks ********************/
 
// Get entity above sky.
stock Float:tlx_distance_to_sky(id)
{  
    new Float:TraceEnd[3]
    pev(id, pev_origin, TraceEnd)
       
    new Float:f_dest[3]
    f_dest[0] = TraceEnd[0]
    f_dest[1] = TraceEnd[1]
    f_dest[2] = TraceEnd[2] + 8192.0
       
    new res, Float:SkyOrigin[3]
    engfunc(EngFunc_TraceLine, TraceEnd, f_dest, IGNORE_MONSTERS + IGNORE_GLASS, id, res)
    get_tr2(res, TR_vecEndPos, SkyOrigin)
   
    return SkyOrigin
}
 
//return distance above us to sky
stock Float:is_user_outside(id)
{
    new Float:origin[3], Float:dist
 
    pev(id, pev_origin, origin)
    dist = origin[2]
 
    while(engfunc(EngFunc_PointContents, origin) == CONTENTS_EMPTY)
        origin[2] += 5.0
    if(engfunc(EngFunc_PointContents, origin) == CONTENTS_SKY)
        return (origin[2] - dist)
 
    return 0.0
}
 
stock ProgressBar(id, seconds, position)
{
    message_begin(MSG_ONE, get_user_msgid("BarTime"), {0, 0, 0}, id)
    write_byte(seconds)
    write_byte(position)
    message_end()
}
 
SendWeaponAnim( id, Sequence )
{
    set_pev( id, pev_weaponanim, Sequence )
   
    message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id )
    write_byte( Sequence )
    write_byte( pev( id, pev_body ) )
    message_end( )
}
 
public UpdateAnim( id )
{
    if( !is_user_alive( id ) || ze_is_user_zombie( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
        return
           
    SendWeaponAnim( id, anim_drop )
}
 
stock Float:floatradius(Float:flMaxAmount, Float:flRadius, Float:flDistance)
{
    return floatsub(flMaxAmount, floatmul(floatdiv(flMaxAmount, flRadius), flDistance))
}
Umm no

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1880
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 101 times
Age: 21
Contact:

#17

Post by Raheem » 9 Months Ago

Player should be in the sphere with specific radius to be fired, in your code you set all zombies fire regardless where they are and then all players fired.

We search for all entities in a sphere with the radius we define from CVAR then if this entity is player we will fire him:

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <cstrike>
  4. #include <fun>
  5. #include <fakemeta_util>
  6.  
  7.  
  8. new const PLUGIN[] = "[ZE] Extra Item:Ion Cannon"
  9. new const VERSION[] = "1.0"
  10. new const AUTHOR[] = "A.F./Mark"
  11.  
  12. //#define ION_RADIUS        2000.0
  13. //#define ION_MAXDAMAGE     54200.0
  14. #define ACTION_BLOCK        ( IN_JUMP | IN_DUCK | IN_FORWARD | IN_BACK | IN_LEFT | IN_RIGHT | IN_MOVELEFT | IN_MOVERIGHT | IN_RELOAD | IN_RUN | IN_USE)
  15.  
  16. new const V_MODEL[] = "models/v_c4.mdl"
  17. new const W_MODEL[] = "models/w_battery.mdl"
  18.  
  19. new const SOUND_APPROACH[] = "zombie_plague/ion_canon/ion_approach2.wav"
  20. new const SOUND_BEACON[] = "zombie_plague/ion_canon/ion_beacon_set.wav"
  21. new const SOUND_STOP[] = "vox/_comma.wav"
  22. new const SOUND_BEEP[] = "zombie_plague/ion_canon/ion_beep3.wav"
  23. new const SOUND_ATTACK[] = "zombie_plague/ion_canon/ion_attack.wav"
  24. new const SOUND_READY[] = "zombie_plague/ion_canon/ion_ready.wav"
  25. new const SOUND_PLANT[] = "zombie_plague/ion_canon/ion_beacon_plant2.wav"
  26.  
  27. new g_iCurrentWeapon[33]
  28. new bool:g_bHasIon[33]
  29. new bool:g_bCanBuy
  30. new bool:g_bIsFiring[33]
  31. new bool:g_bKilledByIon[33]
  32. new bool:g_bIsPlanting[33]
  33. new g_iLastWeapon[33]
  34. new g_Target[33]
  35. new i_Pitch[33]
  36. new Float:i_BeaconTime[33]
  37. new Float:ion_mid_origin[33][3]
  38. new Float:beam_origin[33][8][3]
  39. new Float:g_degrees[33][8]
  40. new Float:g_distance[33]
  41. new Float:g_Speed[33]
  42. new IonBeam, BlueFire, Shockwave, ReadyFire, BlueFlare, LaserFlame
  43. new g_iIonID
  44. new gmsgScreenShake
  45. new g_iMaxids
  46. new bool:g_bExploded /* This variable first initialized to false */
  47.  
  48. new cvar_barlen, cvar_maxdmg, cvar_radius, cvar_ionmode, cvar_damage
  49.  
  50. enum
  51. {
  52.     anim_idle,
  53.     anim_draw,
  54.     anim_drop,
  55.     anim_pressbutton
  56. }
  57.  
  58. public plugin_precache()
  59. {
  60.     precache_model(V_MODEL)
  61.     precache_model(W_MODEL)
  62.     precache_sound(SOUND_APPROACH)
  63.     precache_sound(SOUND_BEACON)
  64.     precache_sound(SOUND_BEEP)
  65.     precache_sound(SOUND_ATTACK)
  66.     precache_sound(SOUND_READY)
  67.     precache_sound(SOUND_PLANT)
  68.     precache_sound(SOUND_STOP)
  69.     IonBeam = precache_model("sprites/ion_canon/ionbeam.spr")
  70.     BlueFlare = precache_model("sprites/ion_canon/bflare.spr")
  71.     ReadyFire = precache_model("sprites/ion_canon/fire.spr")
  72.     BlueFire = precache_model("sprites/ion_canon/blueflame.spr")
  73.     LaserFlame = precache_model("sprites/ion_canon/ion_laserflame.spr")
  74.     Shockwave = precache_model("sprites/shockwave.spr")
  75. }
  76.  
  77. public plugin_init()
  78. {
  79.     register_plugin( PLUGIN, VERSION, AUTHOR )
  80.    
  81.     g_iIonID = ze_register_item( "Ion Cannon", 100, 0)
  82.    
  83.     register_clcmd( "drop", "fn_Drop" )
  84.    
  85.     register_event( "CurWeapon", "EV_CurWeapon", "be", "1=1" )
  86.     register_event( "DeathMsg", "EV_DeathMsg", "a" )
  87.     register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" )
  88.    
  89.     register_forward( FM_CmdStart, "fw_CmdStart" )
  90.     register_forward( FM_PlayerPreThink, "fw_idPreThink" )
  91.    
  92.     RegisterHam( Ham_Item_Deploy, "weapon_c4", "fw_KnifeDeploy_Post", 1 )
  93.  
  94.     register_message( get_user_msgid( "DeathMsg" ), "fn_DeathMsg" )
  95.    
  96.     gmsgScreenShake = get_user_msgid( "ScreenShake" )
  97.    
  98.     cvar_barlen = register_cvar( "ze_ion_barlen", "4" )
  99.     cvar_maxdmg = register_cvar( "ze_ion_maxdmg", "54200" )
  100.     cvar_radius = register_cvar( "ze_ion_radius", "2000" )
  101.     cvar_ionmode = register_cvar( "ze_ion_mode", "1" ) // 0 - all zm damage, 1 - radius damage
  102.     cvar_damage = register_cvar( "ze_ion_damage", "1000" ) // only if ze_ion_mode is 0
  103.    
  104.     g_iMaxids = get_maxplayers( )
  105. }
  106.  
  107. public client_connect( id )
  108. {
  109.     g_bHasIon[ id ] = false
  110.     g_bIsPlanting[ id ] = false
  111. }
  112.  
  113. public client_disconnected( id )
  114. {
  115.     g_bHasIon[ id ] = false
  116. }
  117.  
  118. public ze_game_started()
  119. {
  120.     g_bCanBuy = false
  121. }
  122.  
  123. public ze_zombie_release()
  124. {
  125.     g_bCanBuy = true
  126. }
  127.  
  128. public ze_select_item_pre(id, itemid)
  129. {
  130.     if (itemid != g_iIonID)
  131.         return ZE_ITEM_AVAILABLE
  132.  
  133.     if (ze_is_user_zombie(id))
  134.         return ZE_ITEM_DONT_SHOW
  135.  
  136.     if (g_bHasIon[id] || !g_bCanBuy)
  137.         return ZE_ITEM_UNAVAILABLE
  138.  
  139.     return ZE_ITEM_AVAILABLE
  140. }
  141.  
  142. public ze_select_item_post(id, itemid)
  143. {
  144.     if( itemid == g_iIonID )
  145.     {
  146.         if( g_bHasIon[id] )
  147.         {
  148.             client_print( id, print_chat, "[ZE] Already have Ion Cannon" )
  149.             return PLUGIN_HANDLED
  150.         }
  151.         else
  152.         {
  153.             g_bHasIon[id] = true
  154.             give_item( id, "weapon_c4" )
  155.         }
  156.     }
  157.     return PLUGIN_CONTINUE
  158. }
  159.  
  160. public ze_user_infected(iVictim, iInfector)
  161. {
  162.     emit_sound(g_Target[iVictim], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  163.     ProgressBar(iVictim, 0, 0)
  164.     remove_task(iVictim+5000)
  165.     g_bHasIon[ iVictim ] = false
  166.     g_bIsFiring[ iVictim ] = false
  167.     g_bIsPlanting[ iVictim ] = false
  168.     g_Target[ iVictim ] = 0
  169. }
  170.  
  171. public ze_user_humanized(id)
  172. {
  173.     g_bHasIon[id] = false
  174.     emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  175.     ProgressBar(id, 0, 0)
  176.     remove_task(id+5000)
  177.     g_bIsFiring[ id ] = false
  178.     g_bIsPlanting[ id ] = false
  179.     g_Target[ id ] = 0
  180. }
  181.  
  182. public fn_Drop( id )
  183. {
  184.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  185.         return PLUGIN_CONTINUE
  186.    
  187.     if( g_iCurrentWeapon[ id ] == CSW_C4 )
  188.     {
  189.         client_print( id, print_center, "* You cannot drop Ion Cannon *" )
  190.         return PLUGIN_HANDLED
  191.     }
  192.     return PLUGIN_CONTINUE
  193. }
  194.  
  195. public EV_CurWeapon( id )
  196. {
  197.     if( !is_user_alive( id ) )
  198.         return PLUGIN_CONTINUE
  199.        
  200.     g_iCurrentWeapon[ id ] = read_data( 2 )
  201.    
  202.     return PLUGIN_CONTINUE
  203. }
  204.  
  205. public EV_DeathMsg( )
  206. {
  207.     static iVictim
  208.     iVictim = read_data( 2 )
  209.    
  210.     if( !is_user_connected( iVictim ) )
  211.         return
  212.        
  213.     g_bHasIon[ iVictim ] = false
  214.     g_bIsPlanting[ iVictim ] = false
  215. }
  216.  
  217. public EV_RoundStart( )
  218. {
  219.     // Remove any ion cannons
  220.     for( new i = 1; i < g_iMaxids; i++ )
  221.     {
  222.         if( g_Target[ i ] )
  223.             emit_sound(g_Target[i], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  224.        
  225.         if( is_user_alive( i ) )
  226.         {
  227.             ProgressBar(i, 0, 0)
  228.             remove_task(i+5000)
  229.             g_bHasIon[ i ] = false
  230.             g_bIsFiring[ i ] = false
  231.             g_bIsPlanting[ i ] = false
  232.             g_Target[ i ] = 0
  233.         }
  234.     }
  235.    
  236.     static iEnt
  237.     iEnt = -1
  238.    
  239.     while( ( iEnt = find_ent_by_class( iEnt, "info_target_ion" ) ) > 0 )
  240.     {
  241.         engfunc( EngFunc_RemoveEntity, iEnt )
  242.     }
  243. }
  244.  
  245. public fw_CmdStart( id, UC_Handle, Seed )
  246. {
  247.     if( !is_user_alive( id ) || !g_bHasIon[ id ] || g_iCurrentWeapon[ id ] != CSW_C4 )
  248.         return FMRES_IGNORED
  249.        
  250.     static afButtons
  251.     afButtons = get_uc( UC_Handle, UC_Buttons )
  252.    
  253.     if( afButtons & IN_ATTACK )
  254.     {
  255.         afButtons &= ~IN_ATTACK
  256.         set_uc( UC_Handle, UC_Buttons, afButtons )
  257.        
  258.         if( g_bIsPlanting[ id ] )
  259.         {
  260.             //ProgressBar(id, 0, 0)
  261.             return FMRES_IGNORED
  262.         }
  263.        
  264.         if( g_Target[ id ] )
  265.         {
  266.             client_print( id, print_center, "* You already had planted Ion Cannon *" )
  267.             g_bIsPlanting[ id ] = false
  268.             return FMRES_IGNORED
  269.         }
  270.    
  271.         if( is_user_outside( id ) )
  272.         {
  273.             g_Target[ id ] = 0
  274.             i_Pitch[ id ] = 97
  275.             i_BeaconTime[ id ] = 1.12
  276.             g_distance[ id ] = 350.0
  277.             g_Speed[ id ] = 0.0
  278.            
  279.            
  280.             static iEnt
  281.             iEnt = find_ent_by_owner( -1, "weapon_c4", id )
  282.             set_pdata_float( iEnt, 48, 10.0, 4 )
  283.            
  284.             g_bIsFiring[ id ] = true
  285.             g_bIsPlanting[ id ] = true
  286.             emit_sound(id, CHAN_WEAPON, SOUND_BEACON, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  287.            
  288.             g_iCurrentWeapon[ id ] = CSW_C4
  289.            
  290.             if( get_pcvar_num( cvar_barlen ) > 0 )
  291.             {
  292.                 set_task( 3.6, "UpdateAnim" )
  293.                 SendWeaponAnim( id, anim_pressbutton )
  294.                 ProgressBar(id, get_pcvar_num( cvar_barlen ), 0)
  295.                 set_task(get_pcvar_float( cvar_barlen ),"ion_planted", id+5000)
  296.             }
  297.             else
  298.             {
  299.                 set_task(0.2,"ion_planted", id+5000)
  300.                 SendWeaponAnim( id, anim_drop )
  301.             }
  302.         }
  303.         else
  304.         {
  305.             g_bIsPlanting[ id ] = false
  306.             client_print( id, print_center, "* To plant Ion Cannon you must be outside!!!*" )
  307.             return FMRES_IGNORED
  308.         }
  309.     }
  310.     return FMRES_HANDLED
  311. }
  312.  
  313. public fw_PlayerPreThink( id )
  314. {
  315.     if( !is_user_alive( id ) || !g_bHasIon[ id ] )
  316.         return
  317.    
  318.     if( g_bIsFiring[ id ] )
  319.     {
  320.         g_iLastWeapon[ id ] = get_user_weapon( id )
  321.        
  322.         if( g_iCurrentWeapon[ id ] != CSW_C4 || g_iLastWeapon[ id ] != g_iCurrentWeapon[ id ] || get_user_button( id ) & ACTION_BLOCK )
  323.         {
  324.             emit_sound(g_Target[id], CHAN_WEAPON, SOUND_STOP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  325.             ProgressBar(id, 0, 0)
  326.             remove_task(id+5000)
  327.             g_bIsFiring[ id ] = false
  328.             g_bIsPlanting[ id ] = false
  329.         }
  330.     }
  331. }
  332.  
  333. public fw_KnifeDeploy_Post( iEnt )
  334. {
  335.     static id
  336.     id = get_pdata_cbase( iEnt, 41, 4 )
  337.    
  338.     if( g_bHasIon[ id ] )
  339.     {
  340.         set_pev( id, pev_viewmodel2, V_MODEL )
  341.         SendWeaponAnim( id, anim_draw )
  342.     }
  343. }
  344.  
  345. public fn_DeathMsg( id, Dest, iEntity )
  346. {
  347.     static iVictim, iKiller
  348.     iKiller = get_msg_arg_int( 1 )
  349.     iVictim = get_msg_arg_int( 2 )
  350.    
  351.     if( !is_user_connected( iVictim ) || iKiller == iVictim )
  352.         return PLUGIN_CONTINUE
  353.    
  354.     if ( g_bKilledByIon[ iVictim ] )
  355.     {
  356.         set_msg_arg_string ( 4, "ion cannon" )
  357.     }
  358.     return PLUGIN_CONTINUE
  359. }
  360.  
  361. public ion_planted(id)
  362. {  
  363.     id -= 5000
  364.    
  365.     if( !is_user_alive( id ) || ze_is_user_zombie( id ) )
  366.     {
  367.         remove_task( id )
  368.         return PLUGIN_CONTINUE
  369.     }
  370.    
  371.     client_print(0, print_center, "Ion Cannon has been planted!")
  372.     client_cmd(0, "spk %s", SOUND_PLANT)
  373.     g_bIsFiring[id] = false
  374.     g_bIsPlanting[ id ] = false
  375.    
  376.     static Weapon
  377.     Weapon = find_ent_by_owner( -1, "weapon_c4", id )
  378.    
  379.     ExecuteHamB( Ham_Weapon_RetireWeapon, Weapon );
  380.     ExecuteHamB( Ham_RemovePlayerItem, id, Weapon );
  381.     ExecuteHamB( Ham_Item_Kill, Weapon );
  382.  
  383.     set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1 << CSW_C4) );
  384.     cs_set_user_bpammo( id, CSW_C4, 0 );
  385.     g_bHasIon[ id ] = false
  386.  
  387.     g_Target[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
  388.     if(!g_Target[id]) return PLUGIN_HANDLED
  389.  
  390.     // Strings
  391.     set_pev(g_Target[id],pev_classname,"info_target_ion")
  392.     engfunc(EngFunc_SetModel,g_Target[id],W_MODEL)
  393.  
  394.     // Integer
  395.     set_pev(g_Target[id],pev_owner, id)
  396.     set_pev(g_Target[id],pev_movetype, MOVETYPE_TOSS)
  397.     set_pev(g_Target[id],pev_solid, SOLID_TRIGGER)
  398.  
  399.     entity_get_vector(id,EV_VEC_origin, ion_mid_origin[id])
  400.     //wpn_projectile_startpos(id,0,0,50,ion_mid_origin[id])
  401.     //static Float:flOrigin[ 3 ]
  402.     //pev( id, pev_origin, flOrigin )
  403.     //engfunc( EngFunc_SetOrigin, g_Target[ id ], flOrigin )
  404.     set_pev(g_Target[id],pev_origin,ion_mid_origin[id])
  405.  
  406.     ion_beacon(id)
  407.     set_task(5.0,"ion_startup", id)
  408.     return PLUGIN_CONTINUE
  409. }
  410.  
  411. public ion_beacon(id)
  412. {
  413.     if( !g_Target[ id ] )
  414.     {
  415.         remove_task( id )
  416.         return PLUGIN_CONTINUE
  417.     }
  418.  
  419.     i_Pitch[id] += 3
  420.     i_BeaconTime[id] -= 0.03
  421.     if(i_Pitch[id] > 255) i_Pitch[id] = 255
  422.     if(i_BeaconTime[id] < 0.30) i_BeaconTime[id] = 0.30
  423.     emit_sound(g_Target[id], CHAN_ITEM, SOUND_BEEP, VOL_NORM, ATTN_NORM, 0, i_Pitch[id])
  424.     set_task(i_BeaconTime[id],"ion_beacon", id)
  425.     return PLUGIN_CONTINUE
  426. }
  427.  
  428. public ion_startup(id)
  429. {
  430.     client_cmd(0, "spk ^"%s^"", SOUND_APPROACH)
  431.     client_print(0, print_chat,"Ion Cannon is approaching")
  432.     set_task(5.0,"Trace_Ready", id)
  433. }
  434.  
  435. public Trace_Ready(id)
  436. {
  437.     if( !pev_valid( id ) )
  438.     {
  439.         remove_task( id )
  440.         return PLUGIN_CONTINUE
  441.     }
  442.        
  443.     // write origin of each
  444.     new Float:mid_origin[33][3]
  445.     pev(g_Target[id],pev_origin,mid_origin[id]) // Target contain entity id
  446.     // 1st
  447.     beam_origin[id][0][0] = mid_origin[id][0] + 300.0
  448.     beam_origin[id][0][1] = mid_origin[id][1] + 150.0
  449.     beam_origin[id][0][2] = mid_origin[id][2]
  450.     g_degrees[id][0] = 0.0
  451.     // 2nd
  452.     beam_origin[id][1][0] = mid_origin[id][0] + 300.0
  453.     beam_origin[id][1][1] = mid_origin[id][1] - 150.0
  454.     beam_origin[id][1][2] = mid_origin[id][2]
  455.     g_degrees[id][1] = 45.0
  456.     // 3rd
  457.     beam_origin[id][2][0] = mid_origin[id][0] - 300.0
  458.     beam_origin[id][2][1] = mid_origin[id][1] - 150.0
  459.     beam_origin[id][2][2] = mid_origin[id][2]
  460.     g_degrees[id][2] = 90.0
  461.     // 4th
  462.     beam_origin[id][3][0] = mid_origin[id][0] - 300.0
  463.     beam_origin[id][3][1] = mid_origin[id][1] + 150.0
  464.     beam_origin[id][3][2] = mid_origin[id][2]
  465.     g_degrees[id][3] = 135.0
  466.     // 5th
  467.     beam_origin[id][4][0] = mid_origin[id][0] + 150.0
  468.     beam_origin[id][4][1] = mid_origin[id][1] + 300.0
  469.     beam_origin[id][4][2] = mid_origin[id][2]
  470.     g_degrees[id][4] = 180.0
  471.     // 6th
  472.     beam_origin[id][5][0] = mid_origin[id][0] + 150.0
  473.     beam_origin[id][5][1] = mid_origin[id][1] - 300.0
  474.     beam_origin[id][5][2] = mid_origin[id][2]
  475.     g_degrees[id][5] = 225.0
  476.     // 7th
  477.     beam_origin[id][6][0] = mid_origin[id][0] - 150.0
  478.     beam_origin[id][6][1] = mid_origin[id][1] - 300.0
  479.     beam_origin[id][6][2] = mid_origin[id][2]
  480.     g_degrees[id][6] = 270.0
  481.     // 8th
  482.     beam_origin[id][7][0] = mid_origin[id][0] - 150.0
  483.     beam_origin[id][7][1] = mid_origin[id][1] + 300.0
  484.     beam_origin[id][7][2] = mid_origin[id][2]
  485.     g_degrees[id][7] = 315.0
  486.    
  487.     // set the mid to global
  488.     ion_mid_origin[id] = mid_origin[id]
  489.  
  490.     new Float:addtime
  491.     for(new i = 0; i < 8; i++) {
  492.         addtime = addtime + 0.3
  493.         new param[3]
  494.         param[0] = i
  495.         param[1] = id
  496.         set_task(0.0 + addtime, "Trace_Start", _,param, 2)
  497.     }
  498.     Laser_Rotate(id) //To fix the laserdraw
  499.     client_cmd(0, "spk ^"%s^"", SOUND_READY)
  500.    
  501.     for(new Float:i = 0.0; i < 7.5; i += 0.01) //Rotate for 7.5 secs.
  502.         set_task(i+3.0, "Laser_Rotate", id)
  503.  
  504.     set_task(2.9,"AddSpeed", id)
  505.     set_task(11.5,"CreateFire", id)
  506.     set_task(12.5,"ClearLasers", id)
  507.     set_task(18.2,"FireIonCannon", id)
  508.     return PLUGIN_CONTINUE
  509. }
  510.  
  511. public AddSpeed(id)
  512. {
  513.     if( !g_Target[ id ] )
  514.     {
  515.         remove_task( id )
  516.         return PLUGIN_CONTINUE
  517.     }
  518.    
  519.     if(g_Speed[id] > 1.0) g_Speed[id] = 1.0
  520.     g_Speed[id] += 0.1
  521.     set_task(0.6,"AddSpeed", id)
  522.     return PLUGIN_CONTINUE
  523. }
  524.  
  525. public CreateFire(id)
  526. {
  527.     if( !g_Target[ id ] )
  528.     {
  529.         g_bExploded = false
  530.         remove_task( id )
  531.         return PLUGIN_CONTINUE
  532.     }
  533.    
  534.     new i = -1
  535.    
  536.     while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
  537.     {
  538.         if( !is_user_connected( i ))
  539.             continue
  540.            
  541.         // Here we check if it's exploded before or not?
  542.         if (!g_bExploded)
  543.         {
  544.             //for( new id = 1; id < g_iMaxids; id++ )
  545.             //{
  546.                 if(ze_is_user_zombie(i))
  547.                 {
  548.                     ze_set_fire_grenade(i, true)
  549.                 }
  550.             //}
  551.            
  552.             // After this we turn the variable to true so not to be called next call
  553.             g_bExploded = true
  554.         }
  555.         //next player in spehre.
  556.         continue
  557.     }
  558.  
  559.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  560.     write_byte(TE_SPRITE)
  561.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])
  562.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])
  563.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2] + 100)
  564.     write_short(ReadyFire)
  565.     write_byte(30)
  566.     write_byte(200)
  567.     message_end()
  568.  
  569.     set_task(1.5,"CreateFire", id)
  570.     return PLUGIN_CONTINUE
  571. }
  572.  
  573. public ClearLasers(id)
  574. {
  575.     // Here we reset the variable
  576.     g_bExploded = false
  577.    
  578.     ze_set_fire_grenade(id, false)
  579.     remove_task(1018+id)
  580. }
  581.  
  582. public Laser_Rotate(id)
  583. {
  584.     if( !g_Target[ id ] )
  585.     {
  586.         remove_task( id )
  587.         return
  588.     }
  589.    
  590.     g_distance[id] -= 0.467
  591.     for(new i = 0; i < 8; i++) {
  592.         // Calculate new alpha
  593.         g_degrees[id][i] += g_Speed[id]
  594.         if(g_degrees[id][i] > 360.0)
  595.             g_degrees[id][i] -= 360.0
  596.  
  597.         // calcul the next origin
  598.         new Float:tmp[33][3]
  599.         tmp[id] = ion_mid_origin[id]
  600.  
  601.         tmp[id][0] += floatsin(g_degrees[id][i], degrees) * g_distance[id]
  602.         tmp[id][1] += floatcos(g_degrees[id][i], degrees) * g_distance[id]
  603.         tmp[id][2] += 0.0 // -.-
  604.         beam_origin[id][i] = tmp[id]
  605.     }
  606. }
  607.  
  608. public Trace_Start(param[])
  609. {
  610.     new i = param[0]
  611.     new id = param[1]
  612.  
  613.     if( !g_Target[ id ] )
  614.     {
  615.         remove_task( id )
  616.         return
  617.     }
  618.    
  619.     new Float:get_random_z,Float:SkyOrigin[33][3]
  620.    
  621.     if( is_user_alive( id ) )
  622.     {
  623.         SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  624.         get_random_z = random_float(300.0,SkyOrigin[id][2])
  625.     }
  626.  
  627.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  628.     write_byte(TE_SPRITE)
  629.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  630.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  631.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2] + get_random_z)
  632.     write_short(BlueFire)
  633.     write_byte(10)
  634.     write_byte(100)
  635.     message_end()
  636.    
  637.     TraceAll(param)
  638. }
  639.  
  640. public TraceAll(param[])
  641. {
  642.     new i = param[0]
  643.     new id = param[1]
  644.    
  645.     if( !g_Target[ id ] )
  646.     {
  647.         remove_task( id )
  648.         return
  649.     }
  650.    
  651.     new Float:SkyOrigin[33][3]
  652.     SkyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  653.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  654.     write_byte(TE_BEAMPOINTS)
  655.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //start point (x)
  656.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //start point (y)
  657.     engfunc(EngFunc_WriteCoord, SkyOrigin[id][2])           //start point (z)
  658.  
  659.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])      //end point (x)
  660.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])      //end point (y)
  661.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])      //end point (z)
  662.     write_short(IonBeam)    //model
  663.     write_byte(0)       //startframe
  664.     write_byte(0)       //framerate
  665.     write_byte(1)       //life
  666.     write_byte(50)      //width
  667.     write_byte(0)       //noise
  668.     write_byte(255)     //r
  669.     write_byte(255)     //g
  670.     write_byte(255)     //b
  671.     write_byte(255)     //brightness
  672.     write_byte(0)       //speed
  673.     message_end()
  674.  
  675.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, beam_origin[id][i], 0)
  676.     write_byte(TE_SPRITE)
  677.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  678.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  679.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  680.     write_short(LaserFlame)
  681.     write_byte(5)
  682.     write_byte(200)
  683.     message_end()
  684.  
  685.     /*message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  686.     write_byte(TE_WORLDDECAL)
  687.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][0])
  688.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][1])
  689.     engfunc(EngFunc_WriteCoord, beam_origin[id][i][2])
  690.     write_byte(46)
  691.     message_end()*/
  692.  
  693.     set_task(0.08,"TraceAll", 1018+id, param, 2)
  694. }
  695.  
  696. public FireIonCannon(id)
  697. {
  698.     if( !g_Target[ id ] )
  699.     {
  700.         remove_task( id )
  701.         return
  702.     }
  703.    
  704.     new i = -1
  705.     while((i = engfunc(EngFunc_FindEntityInSphere, i, ion_mid_origin[id], get_pcvar_float( cvar_radius ) )) != 0)
  706.     {
  707.         if( !is_user_connected( i ))
  708.             continue
  709.            
  710.         if( pev(i, pev_flags) & (FL_CLIENT | FL_FAKECLIENT))
  711.         {
  712.             message_begin(MSG_ONE_UNRELIABLE, gmsgScreenShake, {0,0,0}, i)
  713.             write_short(255<<14) //ammount
  714.             write_short(10<<14) //lasts this long
  715.             write_short(255<<14) //frequency
  716.             message_end()
  717.         }
  718.         //next player in spehre.
  719.         continue
  720.     }
  721.  
  722.     new Float:skyOrigin[33][3]
  723.     skyOrigin[id] = tlx_distance_to_sky(g_Target[id])
  724.  
  725.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, ion_mid_origin[id], 0)
  726.     write_byte(TE_BEAMPOINTS)
  727.     engfunc(EngFunc_WriteCoord, skyOrigin[id][0])   //start point (x)
  728.     engfunc(EngFunc_WriteCoord, skyOrigin[id][1])   //start point (y)
  729.     engfunc(EngFunc_WriteCoord, skyOrigin[id][2])   //start point (z)
  730.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][0])      //end point (x)
  731.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][1])      //end point (y)
  732.     engfunc(EngFunc_WriteCoord, ion_mid_origin[id][2])      //end point (z)
  733.     write_short(IonBeam