
   /* AMX Mod script.
   *
   *  Health Replinish
   *  (C)2003  by  GeekGod  Industries, this script is provided as is (No
   Warranties)
   *  Based  on  Jailbreak  by SpaceDude, rewritten to only handle health
   recharges
   *
   */
   #include <amxmod>
   #define TE_BEAMPOINTS 0
   #define TE_SPRITETRAIL 15
   #define HEALTHSIZE 40
   #define HEALTHLIFE 20     // seconds*10
   #define HEALTHBEAMWIDTH 15
   #define HEALTHBEAMNOISE 0
   #define HEALTHBEAMBRIGHTNESS 64
   #define RESCUETIME 30.0
   #define MAXESCAPEATTEMPTS 3
   #define BURYDEPTH 40
   #define RESCUECOUNTDOWN 5
   new bool:THealthSet       // Terrorist = Team 1
   new bool:CTHealthSet      // Counter-Terrorist = Team 2
   new THealthCoords[3]
   new CTHealthCoords[3]
   new PlayerCoords[33]
   new bool:IsInHealth[33]
   new bool:CheckIfStuck[33]
   new bool:IsBuried[33]
   new EscapeAttempts[33]
   new HealthBeam
   //new flaresprite
   //new gmsgDeathMsg
   new gmsgScoreAttrib
   public new_round(id)
   {
           if        (get_cvar_num("gg_replinishhealth")==0)       return
   PLUGIN_CONTINUE
           new teamnumber=get_user_team(id)
           if (teamnumber==1 && !THealthSet)
                   {
                   get_user_origin(id, THealthCoords)
                   THealthSet=true
           }
           else if (teamnumber==2 && !CTHealthSet)
                   {
                   get_user_origin(id, CTHealthCoords)
                   CTHealthSet=true
           }
           IsInHealth[id]=false
           IsBuried[id]=false
           EscapeAttempts[id]=0
           CheckIfStuck[id]=false
           set_user_godmode(id)
           set_user_rendering(id)
           return PLUGIN_CONTINUE
   }
   public create_health_box(){
           if        (get_cvar_num("gg_replinishhealth")==0)       return
   PLUGIN_CONTINUE
           new red, green, blue
           new origin[3]
           new x1, y1, x2, y2, height
           new i, j, k
           new shape[4][2] = {{1,1},{-1,1},{-1,-1},{1,-1}}
           for (j=0; j<4; j++){
                   height=30*j-30
                   for (i=0; i<4; i++){
                           x1=shape[i][0]*HEALTHSIZE
                           y1=shape[i][1]*HEALTHSIZE
                           if (i<3){
                                   x2=shape[i+1][0]*HEALTHSIZE
                                   y2=shape[i+1][1]*HEALTHSIZE
                           }
                           else{
                                   x2=shape[0][0]*HEALTHSIZE
                                   y2=shape[0][1]*HEALTHSIZE
                           }
                           for (k=1; k<3; k++){
                                   if (k==1){
                                           copy(origin,3,THealthCoords)
                                           red=255
                                           green=0
                                           blue=0
                                   }
                                   else if (k==2){
                                           copy(origin,3,CTHealthCoords)
                                           red=0
                                           green=0
                                           blue=255
                                   }
                                   message_begin(          MSG_BROADCAST,
   SVC_TEMPENTITY )
                                   write_byte( TE_BEAMPOINTS )
                                   write_coord(origin[0]+x1)
                                   write_coord(origin[1]+y1)
                                   write_coord(origin[2]+height)
                                   write_coord(origin[0]+x2)
                                   write_coord(origin[1]+y2)
                                   write_coord(origin[2]+height)
                                   write_short(HealthBeam)   // model
                                   write_byte( 0 ) // start frame
                                   write_byte( 0 ) // framerate
                                   write_byte( HEALTHLIFE ) // life
                                   write_byte(    HEALTHBEAMWIDTH   )  //
   width
                                   write_byte(   HEALTHBEAMNOISE   )   //
   noise
                                   write_byte( red )   // r, g, b
                                   write_byte( green )   // r, g, b
                                   write_byte( blue )   // r, g, b
                                   write_byte(       HEALTHBEAMBRIGHTNESS
   )        // brightness
                                   write_byte( 0 )         // speed
                                   message_end()
                           }
                   }
           }
           return PLUGIN_CONTINUE
   }
   public check_position(){
           if        (get_cvar_num("gg_replinishhealth")==0)       return
   PLUGIN_CONTINUE
           new origin[3], playerorigin[3], players[32]
           new i, numofplayers, id
           new teamnumber
           get_players(players, numofplayers)
           for (i=0; i<numofplayers; i++){
                   id=players[i]
                   if (!is_user_alive(id)) continue
                   get_user_origin(id, playerorigin)
                   teamnumber = get_user_team(id)
                   if (teamnumber==2)
                                   {
                           copy(origin,3,CTHealthCoords)
                   }
                   else if (teamnumber==1)
                                   {
                           copy(origin,3,THealthCoords)
                   }
                   if (CheckIfStuck[id] &&
   PlayerCoords[id]==playerorigin[2]){
                           origin[0]+=random_num(-HEALTHSIZE+20,HEALTHSIZ
   E-20)
                           origin[1]+=random_num(-HEALTHSIZE+20,HEALTHSIZ
   E-20)
                           origin[2]+=1            //    Avoid    getting
   teleported all over the place on certain maps
                           set_user_origin(id, origin)
                           PlayerCoords[id]=origin[2]
                           CheckIfStuck[id]=true
                   }
                   CheckIfStuck[id]=false
                   if(!(origin[0]-playerorigin[0]    >    HEALTHSIZE   ||
   origin[0]-playerorigin[0] < -HEALTHSIZE ||
                     origin[1]-playerorigin[1]     >     HEALTHSIZE    ||
   origin[1]-playerorigin[1] < -HEALTHSIZE ||
                     origin[2]-playerorigin[2]     >     HEALTHSIZE    ||
   origin[2]-playerorigin[2] < -HEALTHSIZE))
                                   {
                                                   // person is in health
   box, replinish health by 5 or 10
                                                   if(get_user_health(id)
   <100)
                                                   {
                                                           set_user_healt
   h(id,get_user_health(id)+5)
                                                           set_user_money
   (id,get_user_money(id)+1000)
                                                           client_print(i
   d,print_chat,"[AMX] Increasing health by 5 points");
                                                           if(get_user_he
   alth(id)>99)
                                                           {
                                                                   client
   _print(id,print_chat,"[AMX] Health is now maxed.  Go fight!");
                                                                   client
   _cmd(id, "spk ^"fvox/administering_medical^"")
                                                           }
                                                   }
                                   }
           }
           return PLUGIN_CONTINUE
   }
   public end_round(){
           if        (get_cvar_num("gg_replinishhealth")==0)       return
   PLUGIN_CONTINUE
           THealthSet=false
           CTHealthSet=false
           return PLUGIN_CONTINUE
   }
   public scoreboard(id,state){    // 0 - nothing, 1 - dead, 2 - bomb
           message_begin( MSG_ALL, gmsgScoreAttrib,{0,0,0},0)
           write_byte(id)
           write_byte(state)
           message_end()
           return PLUGIN_HANDLED
   }
   public client_connect(id){
           if        (get_cvar_num("gg_replinishhealth")==0)       return
   PLUGIN_CONTINUE
           IsInHealth[id]=false
           return PLUGIN_CONTINUE
   }
   public plugin_precache(){
           HealthBeam = precache_model("sprites/zbeam4.spr")
           //flaresprite = precache_model( "sprites/blueflare2.spr")
           return PLUGIN_CONTINUE
   }
   public plugin_init()
   {
           //gmsgDeathMsg = get_user_msgid("DeathMsg")
           gmsgScoreAttrib = get_user_msgid("ScoreAttrib")
           register_plugin("Health Replinish","0.1.0","GeekGod")
           register_cvar("Health_Replinish","1.02",FCVAR_SERVER)
           register_event("SendAudio","end_round","a","2=%!MRAD_terwin","
   2=%!MRAD_ctwin","2=%!MRAD_rounddraw")
           register_event("ResetHUD", "new_round", "b")
           register_cvar("gg_replinishhealth","1",0)
           set_task(2.5,"create_health_box",987,"",0,"b")
           set_task(1.0,"check_position",963,"",0,"b")
           return PLUGIN_CONTINUE
   }
