SHARE
TWEET

Untitled

a guest Aug 20th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <fakemeta>
  4. #include <fun>
  5. #include <hamsandwich>
  6.  
  7. #define FFADE_IN        0x0000
  8. #define ICON_HASNADE        1
  9. #define TASKID 6431
  10. #define message_begin_fl(%1,%2,%3,%4) engfunc(EngFunc_MessageBegin, %1, %2, %3, %4)
  11. #define write_coord_fl(%1) engfunc(EngFunc_WriteCoord, %1)
  12. #define m_pPlayer       41
  13. #define OFFSET_WEAPON_CSWID 43
  14. #define MAX_WEAPONS     32
  15. #define AMMO_FLASHBANG      11
  16. #define AMMO_HEGRENADE      12
  17. #define AMMO_SMOKEGRENADE   13
  18. #define DMG_GRENADE     (1<<24)
  19. #define STATUS_HIDE     0
  20. #define STATUS_SHOW     1
  21. #define STATUS_FLASH        2
  22. #define shock_RADIUS        240.0
  23. #define NT_FLASHBANG        (1<<0) // 1; CSW:25
  24. #define NT_HEGRENADE        (1<<1) // 2; CSW:4
  25. #define NT_SMOKEGRENADE     (1<<2) // 4; CSW:9
  26.  
  27. enum
  28. {
  29.     Float:x = 400.0,    // x
  30.     Float:y = 999.0,    // y
  31.     Float:z = 400.0     // z
  32. }
  33.  
  34. new sh_nadetypes, sh_by_radius, sh_hitself, sh_los, sh_maxdamage, sh_mindamage,sh_slow, sh_give;
  35. new maxPlayers, gmsgStatusIcon, mp_friendlyfire,bool:roundRestarting;
  36. new shockKilled[33],hasshockNade[33], nadesBought[33];
  37. new MsgScreenShake, gmsgScreenFade, smokeSpr, sprSpr3;
  38. new g_slowdown[33] = 0, g_gametime[33] = 0
  39.  
  40. public plugin_init()
  41. {
  42.     register_plugin( "Shock Grenade", "1.2", "Dedihost n/ Nikolow" );
  43.  
  44.     sh_nadetypes = register_cvar("sh_nadetypes","2"); //Smoke - 4 || Flash - 1 | HE - 2
  45.     sh_slow = register_cvar("sh_slow","1"); //da ima li zabavqne ?!
  46.  
  47.     sh_by_radius = register_cvar("sh_by_radius","20.0"); //radius kato float
  48.     sh_hitself = register_cvar("sh_hitself","0"); //da te hitva li ako ti q metnesh
  49.     sh_los = register_cvar("sh_los","1"); //da go zaseche li ako e na kraq na radiusa
  50.     sh_maxdamage = register_cvar("sh_maxdamage","0.0"); //da pravi li dmg kato float
  51.     sh_mindamage = register_cvar("sh_mindamage","0.0"); //minimalen dmg kato float
  52.     sh_give = register_cvar("give_bomb","1"); //Give bomb to the player or no
  53.  
  54.     mp_friendlyfire = get_cvar_pointer("mp_friendlyfire");
  55.    
  56.     MsgScreenShake = get_user_msgid("ScreenShake");
  57.    
  58.     maxPlayers = get_maxplayers();
  59.     gmsgStatusIcon = get_user_msgid("StatusIcon");
  60.     gmsgScreenFade = get_user_msgid("ScreenFade");
  61.    
  62.     register_forward(FM_SetModel,"fw_setmodel",1);
  63.     register_message(get_user_msgid("DeathMsg"),"msg_deathmsg");
  64.    
  65.     register_event("TextMsg", "event_round_restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in");
  66.     register_event("HLTV", "event_new_round", "a", "1=0", "2=0");
  67.     register_concmd("shockbombbaby", "Give_item");
  68.  
  69.     RegisterHam(Ham_Spawn,"player","ham_player_spawn",1);
  70.     RegisterHam(Ham_Think,"grenade","ham_grenade_think",0);
  71.     RegisterHam(Ham_Use, "player_weaponstrip", "ham_player_weaponstrip_use", 1);
  72. }
  73.  
  74. enum _:Sprites
  75. {
  76.     SPRITE_CYLINDER,
  77.     SPRITE_SHOCK,
  78.     SPRITE_BEAM2,
  79.     SPRITE_FLAKE
  80. }
  81. new g_iSprites[ Sprites ];
  82. new const g_szSndShock[] = "Nikolow/shock_explode.wav";
  83. new const SPRITE_SPRITE3[]  = "sprites/Nikolow/shock_smoke.spr";
  84. new const SPRITE_SMOKE[]    = "sprites/steam1.spr";
  85.  
  86. public plugin_precache()
  87. {
  88.     precache_sound( g_szSndShock );
  89.     sprSpr3 = precache_model(SPRITE_SPRITE3);
  90.     smokeSpr = precache_model(SPRITE_SMOKE);
  91.     g_iSprites[ SPRITE_CYLINDER ] = precache_model( "sprites/white.spr" );
  92.     g_iSprites[ SPRITE_SHOCK ] = precache_model( "sprites/Nikolow/shock_explode.spr" );
  93.     g_iSprites[ SPRITE_BEAM2 ] = precache_model( "sprites/Nikolow/shock_trail.spr" );
  94.     g_iSprites[ SPRITE_FLAKE ] = precache_model( "sprites/Nikolow/shock_flare.spr" );
  95. }
  96.  
  97. public client_putinserver(id)
  98. {
  99.     shockKilled[id] = 0;
  100.     hasshockNade[id] = 0;
  101. }
  102.  
  103. public Give_item( id )
  104. {
  105.     if( is_user_alive( id ) && get_pcvar_num( sh_give ) == 1 )
  106.     {
  107.    
  108.         give_item( id, "weapon_smokegrenade" )
  109.         hasshockNade[id] = true;
  110.     }
  111. }
  112.  
  113.  
  114. public client_disconnect(id) remove_task(id+TASKID)
  115.  
  116. public fw_setmodel(ent,model[])
  117. {
  118.     new owner = pev(ent,pev_owner);
  119.     if(!is_user_connected(owner)) return FMRES_IGNORED;
  120.    
  121.     new Float:dmgtime;
  122.     pev(ent,pev_dmgtime,dmgtime);
  123.     if(dmgtime == 0.0) return FMRES_IGNORED;
  124.    
  125.     new type, csw;
  126.     if(model[7] == 'w' && model[8] == '_')
  127.     {
  128.         switch(model[9])
  129.         {
  130.             case 'h': { type = NT_HEGRENADE; csw = CSW_HEGRENADE; }
  131.             case 'f': { type = NT_FLASHBANG; csw = CSW_FLASHBANG; }
  132.             case 's': { type = NT_SMOKEGRENADE; csw = CSW_SMOKEGRENADE; }
  133.         }
  134.     }
  135.     if(!type) return FMRES_IGNORED;
  136.    
  137.     new team = _:cs_get_user_team(owner);
  138.  
  139.     if(hasshockNade[owner] == csw || (get_pcvar_num(sh_nadetypes) & type))
  140.     {
  141.         if(hasshockNade[owner] == csw)
  142.         {
  143.             hasshockNade[owner] = 0;
  144.         }
  145.  
  146.         set_pev(ent,pev_team,team);
  147.         set_pev(ent,pev_bInDuck,1);
  148.        
  149.         // glowshell
  150.         set_pev(ent,pev_rendermode,kRenderNormal);
  151.         set_pev(ent,pev_renderfx,kRenderFxGlowShell);
  152.         set_pev(ent,pev_rendercolor,{255.0, 200.0, 0.0});
  153.         set_pev(ent,pev_renderamt,16.0);
  154.  
  155.         UTIL_BeamFollow( ent, g_iSprites[ SPRITE_BEAM2 ], 20, 10, 255, 200, 0, 255 );
  156.     }
  157.  
  158.     return FMRES_IGNORED;
  159. }
  160.  
  161. public msg_deathmsg(msg_id,msg_dest,msg_entity)
  162. {
  163.     new victim = get_msg_arg_int(2);
  164.     if(!is_user_connected(victim) || !shockKilled[victim]) return PLUGIN_CONTINUE;
  165.  
  166.     static weapon[8];
  167.     get_msg_arg_string(4,weapon,7);
  168.     if(equal(weapon,"grenade")) set_msg_arg_string(4,"shockgrenade");
  169.  
  170.     return PLUGIN_CONTINUE;
  171. }
  172.  
  173. public event_round_restart() roundRestarting = true;
  174.  
  175. public event_new_round()
  176. {
  177.     if(roundRestarting)
  178.     {
  179.         roundRestarting = false;
  180.        
  181.         for(new i=1;i<=maxPlayers;i++)
  182.         {
  183.             hasshockNade[i] = 0;
  184.             g_slowdown[i] = 0
  185.             g_gametime[i] = 0
  186.         }
  187.     }
  188. }
  189.  
  190. public ham_player_spawn(id)
  191. {
  192.     nadesBought[id] = 0;
  193.    
  194.     return HAM_IGNORED;
  195. }
  196.  
  197. public ham_grenade_think(ent)
  198. {
  199.     if(!pev_valid(ent) || !pev(ent,pev_bInDuck)) return HAM_IGNORED;
  200.    
  201.     new Float:dmgtime;
  202.     pev(ent,pev_dmgtime,dmgtime);
  203.     if(dmgtime > get_gametime()) return HAM_IGNORED;
  204.    
  205.     shocknade_explode(ent);
  206.  
  207.     return HAM_SUPERCEDE;
  208. }
  209.  
  210. public ham_player_weaponstrip_use(ent, idcaller, idactivator, use_type, Float:value)
  211. {
  212.     if(idcaller >= 1 && idcaller <= maxPlayers)
  213.     {
  214.         hasshockNade[idcaller] = 0;
  215.     }
  216.  
  217.     return HAM_IGNORED;
  218. }
  219.  
  220. public Shake(id)
  221. {
  222.     new Dura = UTIL_FixedUnsigned16(9.0, 1 << 12) //4.0
  223.     new Freq = UTIL_FixedUnsigned16(5.0 , 1 << 8) //0.7
  224.     new Ampl = UTIL_FixedUnsigned16(5.0, 1 << 12) //20.0
  225.    
  226.     message_begin(MSG_ONE , MsgScreenShake , {0,0,0} ,id)
  227.     write_short( Ampl ) // --| Shake amount.
  228.     write_short( Dura ) // --| Shake lasts this long.
  229.     write_short( Freq ) // --| Shake noise frequency.
  230.     message_end ()
  231. }
  232.  
  233. UTIL_FixedUnsigned16 ( const Float:Value, const Scale ) return clamp( floatround( Value * Scale ), 0, 0xFFFF );
  234.  
  235. public shocknade_explode(ent)
  236. {
  237.     if(!pev_valid(ent))
  238.         return FMRES_IGNORED;
  239.    
  240.     new nadeTeam = pev(ent,pev_team), owner = pev(ent,pev_owner), Float:nadeOrigin[3];
  241.     pev(ent,pev_origin,nadeOrigin);
  242.    
  243.     ///////////////////////////////////////////////////////////////
  244.     //////////////////////
  245.     ///////////////
  246.     // effects
  247.    
  248.    
  249.     // make the smoke
  250.     message_begin_fl(MSG_PVS,SVC_TEMPENTITY,nadeOrigin,0);
  251.     write_byte(TE_SMOKE);
  252.     write_coord_fl(nadeOrigin[0]); // x
  253.     write_coord_fl(nadeOrigin[1]); // y
  254.     write_coord_fl(nadeOrigin[2]); // z
  255.     write_short(smokeSpr); // sprite
  256.     write_byte(random_num(30,40)); // scale
  257.     write_byte(5); // framerate
  258.     message_end();
  259.    
  260.     if(!pev_valid(ent))
  261.         return FMRES_IGNORED;
  262.        
  263.     new Float:vOrigin[ 3 ];
  264.     pev( ent, pev_origin, vOrigin );
  265.        
  266.     UTIL_Explosion( ent, g_iSprites[ SPRITE_SHOCK ], 40, 15, 4 ); //30
  267.        
  268.     UTIL_DLight( ent, 100, 255, 200, 0, 255, 95, 20 ); //50
  269.     UTIL_BeamCylinder( ent, g_iSprites[ SPRITE_CYLINDER ], 0, 3, 10, 255, 255, 200, 0, 255, 0 );
  270.     UTIL_SpriteTrail( ent, g_iSprites[ SPRITE_FLAKE ], 30, 3, 2, 30, 0 );
  271.  
  272.     emit_sound(ent,CHAN_ITEM,g_szSndShock,VOL_NORM,ATTN_NORM,0,PITCH_HIGH);
  273.  
  274.     //remove_entity( ent );
  275.    
  276.     engfunc(EngFunc_MessageBegin, MSG_BROADCAST,SVC_TEMPENTITY, vOrigin, 0)
  277.     write_byte(TE_EXPLOSION)
  278.     engfunc(EngFunc_WriteCoord, vOrigin[0]) // x axis
  279.     engfunc(EngFunc_WriteCoord, vOrigin[1]) // y axis
  280.     engfunc(EngFunc_WriteCoord, vOrigin[2]+75) // z axis
  281.     write_short(sprSpr3)
  282.     write_byte(22)
  283.     write_byte(28)
  284.     write_byte(TE_EXPLFLAG_NOSOUND)
  285.     message_end()
  286.    
  287.    
  288.     ///////////////////////////////////////////////////////////////
  289.     //////////////////////
  290.     ///////////////
  291.    
  292.     // explosion
  293.     //emit_sound(ent,CHAN_ITEM,SOUND_EXPLODE,VOL_NORM,ATTN_NORM,0,PITCH_HIGH);
  294.  
  295.     // cache our cvars
  296.     new ff = get_pcvar_num(mp_friendlyfire), Float:by_radius = get_pcvar_float(sh_by_radius),
  297.     hitself = get_pcvar_num(sh_hitself), los = get_pcvar_num(sh_los), Float:maxdamage = get_pcvar_float(sh_maxdamage),
  298.     Float:mindamage = get_pcvar_float(sh_mindamage)
  299.  
  300.     new ta, Float:targetOrigin[3], Float:distance, tr = create_tr2(), Float:fraction, Float:damage;
  301.     for(new target=1;target<=maxPlayers;target++)
  302.     {
  303.         if(!is_user_alive(target) || pev(target,pev_takedamage) == DAMAGE_NO || (pev(target,pev_flags) & FL_GODMODE) ||(target == owner && !hitself))
  304.             continue;
  305.        
  306.         ta = (_:cs_get_user_team(target) == nadeTeam);
  307.         if(ta && !ff && target != owner) continue;
  308.        
  309.         if(!pev_valid(ent))
  310.             return FMRES_IGNORED;
  311.        
  312.         pev(target,pev_origin,targetOrigin);
  313.         distance = vector_distance(nadeOrigin,targetOrigin);
  314.        
  315.         if(distance > shock_RADIUS) continue;
  316.  
  317.         // check line of sight
  318.         if(los)
  319.         {
  320.             nadeOrigin[2] += 2.0;
  321.             engfunc(EngFunc_TraceLine,nadeOrigin,targetOrigin,DONT_IGNORE_MONSTERS,ent,tr);
  322.             nadeOrigin[2] -= 2.0;
  323.  
  324.             get_tr2(tr,TR_flFraction,fraction);
  325.             if(fraction != 1.0 && get_tr2(tr,TR_pHit) != target) continue;
  326.         }
  327.  
  328.         // damaged
  329.         if(maxdamage > 0.0)
  330.         {
  331.             damage = radius_calc(distance,shock_RADIUS,maxdamage,mindamage);
  332.             if(ta) damage /= 2.0; // half damage for friendlyfire
  333.  
  334.             if(damage > 0.0)
  335.             {
  336.                 shockKilled[target] = 1;
  337.                 ExecuteHamB(Ham_TakeDamage,target,ent,owner,damage,DMG_GRENADE);
  338.                 if(!is_user_alive(target)) continue; // dead now
  339.                 shockKilled[target] = 0;
  340.             }
  341.         }
  342.        
  343.         message_begin(MSG_ONE,gmsgScreenFade,_,target);
  344.         write_short(floatround(4096.0 * 5)); // duration
  345.         write_short(floatround(3072.0 * 4)); // hold time (4096.0 * 0.75)
  346.         write_short(FFADE_IN); // flags
  347.         write_byte(255); // red
  348.         write_byte(200); // green
  349.         write_byte(0); // blue
  350.         write_byte(100); // alpha
  351.         message_end();
  352.        
  353.         show_icon(target, STATUS_SHOW);
  354.  
  355.         // shock
  356.         if(radius_calc(distance,shock_RADIUS,100.0,0.0) >= by_radius)
  357.         {
  358.             //tuk moq kod za preobrushtaneto
  359.             if(!pev_valid(ent))
  360.                 return FMRES_IGNORED;
  361.                
  362.             set_pev(target, pev_punchangle, Float:{x, y, z})
  363.             if(get_pcvar_num(sh_slow) == 1)
  364.             {
  365.                 g_slowdown[target] = 1;
  366.                 set_user_maxspeed(target, 200.0)
  367.                 set_task(0.7,"remove_slow",target+TASKID,_,_,"b")
  368.             }
  369.             set_task(0.1, "Shake", target)
  370.         }
  371.     }
  372.    
  373.     if(!pev_valid(ent))
  374.         return FMRES_IGNORED;
  375.  
  376.     free_tr2(tr);
  377.     set_pev(ent,pev_flags,pev(ent,pev_flags)|FL_KILLME);
  378.    
  379.     return FMRES_SUPERCEDE;
  380. }
  381.  
  382. public remove_slow(TASK)
  383. {
  384.     new id = TASK - TASKID
  385.     g_gametime[id]++
  386.     set_user_maxspeed(id, 100.0)
  387.    
  388.     if(g_gametime[id] >= 10.0)
  389.     {
  390.         set_user_maxspeed(id, 250.0)
  391.         g_slowdown[id] = 0
  392.         g_gametime[id] = 0
  393.         remove_task(id+TASKID)
  394.        
  395.         show_icon(id, STATUS_HIDE);
  396.        
  397.         return PLUGIN_HANDLED;
  398.     }
  399.     return PLUGIN_CONTINUE;
  400. }
  401.  
  402. show_icon(id, status)
  403. {
  404.     message_begin(MSG_ONE,gmsgStatusIcon,_,id);
  405.     write_byte(status); // status (0=hide, 1=show, 2=flash)
  406.     write_string("dmg_shock"); // sprite name
  407.     write_byte(255); // red
  408.     write_byte(200); // green
  409.     write_byte(0); // blue
  410.     message_end();
  411. }
  412.  
  413. Float:radius_calc(Float:distance,Float:radius,Float:maxVal,Float:minVal)
  414. {
  415.     if(maxVal <= 0.0) return 0.0;
  416.     if(minVal >= maxVal) return minVal;
  417.     return minVal + ((1.0 - (distance / radius)) * (maxVal - minVal));
  418. }
  419.  
  420. UTIL_DLight( iEnt, iRadius, iRed, iGreen, iBlue, iBright, iLife, iDecay )
  421. {
  422.     new Float:vOrigin[ 3 ];
  423.     pev( iEnt, pev_origin, vOrigin );
  424.    
  425.     message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  426.     write_byte( TE_DLIGHT );
  427.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
  428.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
  429.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] );
  430.     write_byte( iRadius );
  431.     write_byte( iRed );
  432.     write_byte( iGreen );
  433.     write_byte( iBlue );
  434.     write_byte( iBright );
  435.     write_byte( iLife );
  436.     write_byte( iDecay );
  437.     message_end();
  438. }
  439.  
  440. UTIL_Explosion( iEnt, iSprite, iScale, iFramerate, Flags )
  441. {
  442.     new Float:vOrigin[ 3 ];
  443.     pev( iEnt, pev_origin, vOrigin );
  444.    
  445.     message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  446.     write_byte( TE_EXPLOSION );
  447.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
  448.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
  449.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] );
  450.     write_short( iSprite );
  451.     write_byte( iScale );
  452.     write_byte( iFramerate );
  453.     write_byte( Flags );
  454.     message_end();
  455. }
  456.  
  457. UTIL_SpriteTrail( iEnt, iSprite, iCount, iLife, iScale, iVelocity, iVary )
  458. {
  459.     new Float:vOrigin[ 3 ];
  460.     pev( iEnt, pev_origin, vOrigin );
  461.    
  462.     message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  463.     write_byte( TE_SPRITETRAIL );
  464.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
  465.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
  466.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 100 );
  467.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] + random_float( -200.0, 200.0 ) );
  468.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] + random_float( -200.0, 200.0 ) );
  469.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] );
  470.     write_short( iSprite );
  471.     write_byte( iCount );
  472.     write_byte( iLife );
  473.     write_byte( iScale );
  474.     write_byte( iVelocity );
  475.     write_byte( iVary );
  476.     message_end();
  477. }
  478.  
  479. UTIL_BeamFollow( iEnt, iSprite, iLife, iWidth, iRed, iGreen, iBlue, iBright )
  480. {
  481.     message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  482.     write_byte( TE_BEAMFOLLOW );
  483.     write_short( iEnt );
  484.     write_short( iSprite );
  485.     write_byte( iLife );
  486.     write_byte( iWidth );
  487.     write_byte( iRed );
  488.     write_byte( iGreen );
  489.     write_byte( iBlue );
  490.     write_byte( iBright );
  491.     message_end()
  492. }
  493.  
  494. UTIL_BeamCylinder( iEnt, iSprite, iFramerate, iLife, iWidth, iAmplitude, iRed, iGreen, iBlue, iBright, iSpeed )
  495. {
  496.     new Float:vOrigin[ 3 ];
  497.     pev( iEnt, pev_origin, vOrigin );
  498.    
  499.     message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  500.     write_byte( TE_BEAMCYLINDER );
  501.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
  502.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
  503.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 10 );
  504.     engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
  505.     engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] + 400 );
  506.     engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 400 );
  507.     write_short( iSprite );
  508.     write_byte( 0 );
  509.     write_byte( iFramerate );
  510.     write_byte( iLife );
  511.     write_byte( iWidth );
  512.     write_byte( iAmplitude );
  513.     write_byte( iRed );
  514.     write_byte( iGreen );
  515.     write_byte( iBlue );
  516.     write_byte( iBright );
  517.     write_byte( iSpeed );
  518.     message_end()
  519. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top