
   #include <amxmod>
   #include <amxmisc>
   #include <Vexd_Utilities>
   new boom
   new LLamacage[33]
   new smoke
   new white
   new fire
   new gPlayerOrigin[33][3]
   new gPlayerCageOrigin[33][3]
   new pName[33][32]
   new bool:gIsCaged[33]
   //--------------------------------------------------------------------
   --------------------------
   public plugin_init(){
      register_plugin("Llamacage","1.0","AssKicR")
      register_clcmd("amx_llamacage","Ass_acc_Llamacage",ADMIN_LEVEL_E)
      register_clcmd("amx_detspecialcage","Ass_acc_detcage",ADMIN_LEVEL_E
   )
      register_clcmd("amx_llamaport","Ass_acc_Llamaport",ADMIN_LEVEL_E,"<
   authid, nick or #userid>")
      register_clcmd("amx_freellama","Ass_acc_freeLlama",ADMIN_LEVEL_E,"<
   authid, nick or #userid>")
      register_event("ResetHUD","cage_old_llama","b")
      register_cvar("LLamacage_radius", "400" )
      register_cvar("LLamacage_maxdamage", "200" )
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public plugin_precache() {
      precache_model("models/neo_cage.mdl")
      smoke = precache_model("sprites/steam1.spr")
      white = precache_model("sprites/white.spr")
      fire = precache_model("sprites/explode1.spr")
      return PLUGIN_CONTINUE
      }
   //--------------------------------------------------------------------
   --------------------------
   public client_disconnect(id) {
      if (gIsCaged[id]) {
         gIsCaged[id]=false
      }
   }
   //--------------------------------------------------------------------
   --------------------------
   public cage_old_llama(id) {
      if (gIsCaged[id]) {
         set_user_origin(id,gPlayerCageOrigin[id])
         if            (is_running("tfc"))            Entvars_Set_Int(id,
   EV_INT_playerclass,11)
      }
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_acc_Llamacage(id,level,cid) {
      if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED
      Ass_Llamacage(id)
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_Llamacage(id) {
      if (!is_user_alive(id)) {
       client_print(id,print_chat,"**** Llamacage Placement Denied ****")
       return PLUGIN_HANDLED
      }
      if (LLamacage[id] != 0)
      {
         new Float:vExplodeAt[3]
         Entvars_Get_Vector(LLamacage[id], EV_VEC_origin, vExplodeAt)
         blowUp(id, vExplodeAt)
         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
         write_byte(3)
         write_coord(floatround(vExplodeAt[0]))
         write_coord(floatround(vExplodeAt[1]))
         write_coord(floatround(vExplodeAt[2]))
         write_short(boom)
         write_byte(50)
         write_byte(15)
         write_byte(0)
         message_end()
         RemoveEntity(LLamacage[id])
         client_print(id,print_chat,"**** Llamacage Detonated ****")
         LLamacage[id] = false
         return PLUGIN_CONTINUE
      } else if (LLamacage[id] == 0) {
         LLamacage[id] = CreateEntity("info_target")
         if(LLamacage[id] == 0) return PLUGIN_HANDLED_MAIN
         Entvars_Set_String(LLamacage[id], EV_SZ_classname, "llama_cage")
         ENT_SetModel(LLamacage[id], "models/neo_cage.mdl")
         new Float:MinBox[3]
         new Float:MaxBox[3]
         MinBox[0] = -100.0
         MinBox[1] = -100.0
         MinBox[2] = -100.0
         MaxBox[0] = 100.0
         MaxBox[1] = 100.0
         MaxBox[2] = 100.0
         Entvars_Set_Vector(LLamacage[id], EV_VEC_mins, MinBox)
         Entvars_Set_Vector(LLamacage[id], EV_VEC_maxs, MaxBox)
         new Float:PlayerOrigin[3]
         Entvars_Get_Vector(id, EV_VEC_origin, PlayerOrigin)
         ENT_SetOrigin(LLamacage[id], PlayerOrigin)
         Entvars_Set_Int(LLamacage[id], EV_INT_solid, 2)
         Entvars_Set_Int(LLamacage[id], EV_INT_movetype, 4)
         Entvars_Set_Edict(LLamacage[id], EV_ENT_owner, id)
         client_print(id,print_chat,"**** Llamacage Placed ****")
      }
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public blowUp( id, Float:vExplodeAt[3] )
   {
      new distanceBetween
      new damage, multiplier

      new name[32]
      get_user_name(id,name,31)
      set_user_rendering(id,kRenderFxNone,255,255,255, kRenderNormal,16);
      new FFOn= get_cvar_num("mp_friendlyfire")
      new origin[3]
      for(new a = 0; a < 2; a++) {
         origin[a]=floatround(vExplodeAt[a])
      }
      origin[2]=floatround(vExplodeAt[2])+37

      explode(origin) // blowup even if dead

      for(new a = 1; a <= 33; a++)
      {
        if(  is_user_alive(a)  && ( get_user_team(id) != get_user_team(a)
   || FFOn != 0 || a==id ) )
        {
          new origin1[3]
          get_user_origin(a,origin1)
          distanceBetween = get_distance(origin, origin1 )
          if( distanceBetween < get_cvar_num("LLamacage_radius") )
          {
            multiplier=(get_cvar_num("LLamacage_maxdamage")*get_cvar_num(
   "LLamacage_maxdamage"))/get_cvar_num("LLamacage_radius")
            damage=(get_cvar_num("LLamacage_radius")-distanceBetween)*mul
   tiplier
            damage=sqrt(damage)
            ExtraDamage(a, a, damage, "LLamacage Detonation")
            gIsCaged[a]=false
          } // distance
        } // alive target...
      } // loop
   }
   //--------------------------------------------------------------------
   --------------------------
   public explode( vec1[3] )
   {
      // blast circles
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1)
      write_byte( 21 )
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2] + 16)
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2] + 1936)
      write_short( white )
      write_byte( 0 ) // startframe
      write_byte( 0 ) // framerate
      write_byte( 2 ) // life 2
      write_byte( 20 ) // width 16
      write_byte( 0 ) // noise
      write_byte( 188 ) // r
      write_byte( 220 ) // g
      write_byte( 255 ) // b
      write_byte( 255 ) //brightness
      write_byte( 0 ) // speed
      message_end()
      //Explosion2
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY)
      write_byte( 12 )
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2])
      write_byte( 188 ) // byte (scale in 0.1's) 188
      write_byte( 10 ) // byte (framerate)
      message_end()
      //TE_Explosion
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1)
      write_byte( 3 )
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2])
      write_short( fire )
      write_byte( 60 ) // byte (scale in 0.1's) 188
      write_byte( 10 ) // byte (framerate)
      write_byte( 0 ) // byte flags
      message_end()
      //Smoke
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1)
      write_byte( 5 ) // 5
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2])
      write_short( smoke )
      write_byte( 10 )  // 2
      write_byte( 10 )  // 10
      message_end()
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_acc_Llamaport(id,level,cid) {
      if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED

      new arg[32]
      read_argv(1,arg,31)
      new victim = cmd_target(id,arg,3)
      if (!victim) return PLUGIN_HANDLED
      if (gIsCaged[victim]) {
         client_print(id,print_console,"Client Is Already Caged")
         return PLUGIN_HANDLED
      }
      if (LLamacage[id] == 0) {
         client_print(id,print_console,"You do not have a cage to put the
   llama in")
         return PLUGIN_HANDLED
      }
      Ass_Llamaport(id,victim)
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_Llamaport(id,victim) {
      new tCage = FindCage(id)
      if (tCage!=0) {
         get_user_origin(victim,gPlayerOrigin[victim])
         gIsCaged[victim]=true
         new Float: CageOrig[3]
         Entvars_Get_Vector(tCage, EV_VEC_origin, CageOrig)
         for(new a = 0; a < 3; a++) {
            gPlayerCageOrigin[victim][a]=floatround(CageOrig[a])
         }
         set_user_origin(victim,gPlayerCageOrigin[victim])
         get_user_origin(victim,gPlayerCageOrigin[victim])
      }
      get_user_name(victim,pName[victim],31)
      if (is_running("tfc")) Entvars_Set_Int(id, EV_INT_playerclass,11)
      console_print(id,"[AMX] You Caged the Llama %s",pName[victim])
      client_print(id,print_chat,"[AMX]    The    llama   %s   has   been
   caged",pName[victim])
      return PLUGIN_HANDLED
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_acc_freeLlama(id,level,cid) {
      if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED

      new arg[32]
      read_argv(1,arg,31)
      new victim = cmd_target(id,arg,3)
      if (!victim) return PLUGIN_HANDLED
      if (!gIsCaged[victim]) return PLUGIN_HANDLED

      Ass_FreeLlama(id,victim)
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_FreeLlama(id,victim) {
      gIsCaged[victim]=false
      get_user_name(victim,pName[victim],31)
      set_user_origin(victim,gPlayerOrigin[id])
      console_print(id,"[AMX] You set the Llama %s free",pName[victim])
      client_print(id,print_chat,"[AMX]   The   llama  %s  has  been  let
   free",pName[victim])
      return PLUGIN_HANDLED
   }
   public Ass_acc_detcage(id,level,cid) {
      if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED

      Ass_detcage(id)
      return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   public Ass_detcage(id) {
   if (LLamacage[id] != 0)
      {
         new Float:vExplodeAt[3]
         Entvars_Get_Vector(LLamacage[id], EV_VEC_origin, vExplodeAt)
         blowUp(id, vExplodeAt)
         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
         write_byte(3)
         write_coord(floatround(vExplodeAt[0]))
         write_coord(floatround(vExplodeAt[1]))
         write_coord(floatround(vExplodeAt[2]))
         write_short(boom)
         write_byte(50)
         write_byte(15)
         write_byte(0)
         message_end()
         RemoveEntity(LLamacage[id])
         client_print(id,print_chat,"**** Llamacage Detonated ****")
         LLamacage[id] = false
      }
   return PLUGIN_CONTINUE
   }
   //--------------------------------------------------------------------
   --------------------------
   /* Do Exta Damage to a Player */
   public ExtraDamage(id, attacker, damage, weaponDescription[] )
     {
        if ( is_user_alive(id) )
        {
          new userHealth=get_user_health(id)
          set_user_health(id, userHealth - damage )
          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 )
            }
            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)

            }

            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()
          }
        }
     }
   //--------------------------------------------------------------------
   --------------------------
   /* Log a kill using standard HL-logging format */
   public logKill(attacker, victim, weaponDescription[] )
     {
       //Save Hummiliation
       new namea[24],namev[24],authida[20],authidv[20],teama[8],teamv[8]

       //Info On Attacker
       get_user_name(attacker,namea,23)
       get_user_team(attacker,teama,7)
       get_user_authid(attacker,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(attacker),authida,teama,namev,get_user_useri
   d(victim),authidv,teamv, weaponDescription )
     }
   //--------------------------------------------------------------------
   --------------------------
   public sqrt(num)
     {
      // Cool - Newton's Method - Ludwig
      new div = num
      new result = 1
      while (div > result)
      {  // end when div == result, or just below
         div = (div + result) / 2 // take mean value as new divisor
         result = num / div
      }
      return div
     }
   //--------------------------------------------------------------------
   --------------------------
   stock FindCage(id)
   {
      new iCage = FindEntity(-1, "llama_cage")
      while(iCage > 0)
      {
         if(Entvars_Get_Edict(iCage, EV_ENT_owner) == id)
            return iCage
         iCage = FindEntity(iCage, "llama_cage")
      }
      return 0
   }
