
#include <amxmod.inc> 
#include <Vexd_Utilities.inc> 

new gMsgDeathMsg 
new gCurrentNade 

public plugin_init() 
{ 
   // Plugin Info 
   register_plugin("Greandes Are Heavy", "0.1", "AssKicR") 
   register_event("RoundTime", "newRound", "bc") 
   register_cvar("amx_heimpactdmg","5") 
   register_cvar("amx_fbimpactdmg","5") 
   register_cvar("amx_sgimpactdmg","5") 
   gMsgDeathMsg = get_user_msgid("DeathMsg") 
} 
public newRound() { 
   new Float:roundtime = get_cvar_float("mp_roundtime") * 60.0 
   new rtime = read_data(1) 
   if(roundtime == rtime) { 
      gCurrentNade=0 
   } 
} 

public vexd_pfntouch(pToucher, pTouched) 
{ 
   new pTouchername[32], pTouchedname[32], pToucherModel[32] 
   Entvars_Get_String(pToucher, EV_SZ_classname, pTouchername, 31) 
   Entvars_Get_String(pTouched, EV_SZ_classname, pTouchedname, 31) 
   if(equal(pTouchername, "grenade") && equal(pTouchedname, "player")) { 
      if (gCurrentNade==pToucher) return 
      gCurrentNade=pToucher 
      new pToucherOwner = Entvars_Get_Edict(pToucher, EV_ENT_owner) 
      Entvars_Get_String(pToucher, EV_SZ_model, pToucherModel, 31) 
      //client_print(0, 3, "Grenade with model ^"%s^" has hit a player",pToucherModel) //This is for debugging 
      if (equali(pToucherModel,"models/w_hegrenade.mdl")) {
         emit_sound(pToucher, CHAN_ITEM, "weapons/ric_metal-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         emit_sound(pTouched, CHAN_BODY, "player/bhit_flesh-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         ImpactDamage(pTouched,pToucher)
         ScreenShake(pTouched, 14, 14, 14 )
         ScreenFlash(pTouched, 255, 0, 0, 1, 200 )
         HazedView(pTouched, 120 )
         ExtraDamage(pTouched, pToucherOwner, get_cvar_num("amx_heimpactdmg"), "grenade" ) 
      }else if (equali(pToucherModel,"models/w_flashbang.mdl")) { 
         emit_sound(pToucher, CHAN_ITEM, "weapons/ric_metal-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         emit_sound(pTouched, CHAN_BODY, "player/bhit_flesh-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         ImpactDamage(pTouched,pToucher)
         ScreenShake(pTouched, 14, 14, 14 )
         ScreenFlash(pTouched, 255, 0, 0, 1, 200 ) 
         HazedView(pTouched, 120 )
         ExtraDamage(pTouched, pToucherOwner, get_cvar_num("amx_fbimpactdmg"), "flashbang" ) 
      }else if (equali(pToucherModel,"models/w_smokegrenade.mdl")) { 
         emit_sound(pToucher, CHAN_ITEM, "weapons/ric_metal-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         emit_sound(pTouched, CHAN_BODY, "player/bhit_flesh-1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM)
         ImpactDamage(pTouched,pToucher)
         ScreenShake(pTouched, 14, 14, 14 )
         ScreenFlash(pTouched, 255, 0, 0, 1, 200 )
         HazedView(pTouched, 120 )
         ExtraDamage(pTouched, pToucherOwner, get_cvar_num("amx_sgimpactdmg"), "smokegreande" ) 
      } 
   } 
} 

public ExtraDamage(id, attacker, damage, weaponDescription[] ) 
  { 
     if ( is_user_alive(id) ) 
     { 
       new userHealth=get_user_health(id) 
       MessageBlock(gMsgDeathMsg, BLOCK_SET) 
       set_user_health(id, userHealth - damage ) 
       MessageBlock(gMsgDeathMsg, BLOCK_NOT) 
       if ( userHealth - damage <= 0 ) 
       { 
         logKill(attacker,id, weaponDescription) 
         if ( get_user_team(id) != get_user_team(attacker) ) 
         { 
           // The person dying shouldn't get negative credit for this kill (so add it back) 
           set_user_frags( id, get_user_frags(id) + 1 ) 
            
           // The killing should get credit for the frag 
           set_user_frags( attacker, get_user_frags(attacker)+ 1 ) 
           new money = get_user_money(attacker) 
           if (get_user_money(attacker) < 16000) 
              set_user_money(attacker,money + 300,1) 
         } 
         else 
         { 
           // The person dying shouldn't get negative credit for this kill (so add it back) 
           set_user_frags( id, get_user_frags(id)+ 1 )  
            
           // The killer killed a teammember or self 
           // Engine gives credit for the kill so let's take away that + 1 
           set_user_frags( attacker, get_user_frags(attacker) - 2) 
            
           new money = get_user_money(attacker) 
           if (get_user_money(attacker) != 0) 
              set_user_money(attacker,money - 150,1) 
         } 
                  
         message_begin( MSG_BROADCAST, get_user_msgid("DeathMsg"),{0,0,0},0) 
         write_byte(attacker) 
         write_byte(id) 
         write_byte(0) 
         write_string(weaponDescription) 
         message_end() 
       } 
     } 
  } 

public logKill(id, victim, weaponDescription[] ) 
  { 
    //Save Hummiliation 
    new namea[24],namev[24],authida[20],authidv[20],teama[8],teamv[8] 
    
    //Info On Attacker 
    get_user_name(id,namea,23) 
    get_user_team(id,teama,7) 
    get_user_authid(id,authida,19) 
    //Info On Victim 
    get_user_name(victim,namev,23) 
    get_user_team(victim,teamv,7) 
    get_user_authid(victim,authidv,19) 
    //Log This Kill 
    log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"%s^"", 
    namea,get_user_userid(id),authida,teama,namev,get_user_userid(victim),authidv,teamv, weaponDescription ) 
  }

public ScreenShake(id, amplitude, duration, frequency )
  {
    if ( !is_user_alive(id) ) return
    message_begin(MSG_ONE, get_user_msgid("ScreenShake"),{0,0,0},id)
    write_short( 1<<amplitude )// amplitude
    write_short( 1<<duration )// duration
    write_short( 1<<frequency )// frequency
    message_end()
  }

public ScreenFlash(id, red, green, blue, decisecs, alpha)
  {
    if ( !is_user_alive(id) ) return
    message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},id)
    write_short( decisecs<<12 ) // fade lasts this long duration
    write_short( 1<<16 ) // fade lasts this long hold time
    write_short( 1<<1 ) // fade type (in / out)
    write_byte( red ) // fade red
    write_byte( green ) // fade green
    write_byte( blue ) // fade blue
    write_byte( alpha ) // fade alpha
    message_end()
  }

public HazedView(id, frequency )
  {
    if ( !is_user_alive(id) ) return
    message_begin(MSG_ONE, get_user_msgid("SetFOV"), {0,0,0}, id) 
    write_byte( frequency ) // FOV Distance
    message_end() 
    set_task(2.0,"RestoreVision",id)
  }

public RestoreVision(id)
  {
    message_begin(MSG_ONE, get_user_msgid("SetFOV"), {0,0,0}, id) 
    write_byte( 90 ) // FOV Default
    message_end() 
  }

public ImpactDamage(id,grenadeid) {
    new Float:gorigin[3], origin[3]
    Entvars_Get_Vector(grenadeid, EV_VEC_origin, gorigin)
    origin[0]=floatround(gorigin[0])
    origin[1]=floatround(gorigin[1])
    origin[2]=floatround(gorigin[2])
    if ( !is_user_alive(id) ) return
    message_begin(MSG_ONE, get_user_msgid("Damage"), {0,0,0}, id)  
    write_byte(30) // dmg_save  
    write_byte(30) // dmg_take  
    write_long(0) // visibleDamageBits  
    write_coord(origin[0]) // damageOrigin.x  
    write_coord(origin[1]) // damageOrigin.y  
    write_coord(origin[2]) // damageOrigin.z
    message_end()
}