global script hpmpcounters{
	void run(){
		int fastWalkTimer;
        int lastScreen = Game->GetCurDMapScreen();
        int lastDMap = Game->GetCurDMap();
		
		
		while(true)
		{
			Game->Counter[CR_SCRIPT2] = Link->HP;
			Game->Counter[CR_SCRIPT3] = Link->MP;
			Game->Counter[CR_SCRIPT4] = Link->MaxHP;
			Game->Counter[CR_SCRIPT5] = Link->MaxMP;
			UpdateEWeapons();
            CleanUpGhostFFCs(); // Only needed if __GH_USE_DRAWCOMBO is 0

            Waitdraw();
            
            AutoGhost();
            DrawGhostFFCs();
			{
			if (Link->Item[231] == true) //If Link has the fake item designated in D0
			{
				Link->Item[230] = false; //Removes the fake item user selects in D0
				Link->Item[231] = false; //Removes the item the user selects in in D1   
				Link->MP += 256; //Increases MP by value of D3
				Link->MaxMP += 256; //Increases Max MP by value of D2
			}
			else (Link->Item[230] == true); //Gives Link the specified item in D4.{
           
			}
			{
     
      if(SecretTimer > -1) {
        SecretTimer--;
        if (SecretTimer == -1) {
          Screen->TriggerSecrets();
		  Game->PlaySound(27);}}
			}



			float angle;
			{
				if (usebombodo == 1)
				{            
					slower ++;
					if (slower == 5)
					{  
						rad++;
						slower = 0;
					}  
					angle = (angle + ORBIT_SPEED) % 360;          
					f1 = 100 + rad * Cos(angle);
					f2 = 100 + rad * Sin(angle);
					Screen->FastCombo(6, f1, f2, 80, 2, 128);
					
					r1 = 40+Rand(150);
					r2 = 40+Rand(100);
					
					slowera++;
					if (slowera  == 20)
					{
						slowera = 0;
						if (bombs < 30)
						{
							bombs ++;  
							lweapon bomb = CreateLWeaponAt(LW_BOMBBLAST, r1, r2);
							Game->PlaySound(SFX_BOMB);
							if (bombs == 30) usebombodo = 0;
						}
					}
				}
				
				///////////////////////
				/// BEHIN XP SCRIPT ///
				///////////////////////
				
				//Exp gain and level up
            if ( Game->Counter[CR_LEVEL] < EXP_MAX_LEVEL ){ //Disable if level is maxed
                setMaxHP();
                checkEnemiesKilled();
                expMeter();
            }
            
            //Fast walk
            if ( Link->Item[I_FASTWALK] ){
                fastWalkTimer++;
                fastWalkTimer %= EXP_FASTWALKRATE;
                if ( fastWalkTimer == 0 )
                    fastWalk(1);
            }
            
            //Treasure Hunter
            if ( Link->Item[I_TREASUREHUNTER] //If skill learned
                && (lastScreen != Game->GetCurDMapScreen() || lastDMap != Game->GetCurDMap()) //If new screen
                && checkScreenFlag(SF_TREASURE) //And flag active
                && !Screen->State[ST_ITEM] //And item not taken
                && !Screen->State[ST_CHEST]
                && !Screen->State[ST_LOCKEDCHEST]
                && !Screen->State[ST_BOSSCHEST]
            ){
                Game->PlaySound(SFX_TREASURESCREEN); //Play SFX
            }
            lastScreen = Game->GetCurDMapScreen(); //Update last screen/DMap
            lastDMap = Game->GetCurDMap();
			
			/////////////////////
			/// END XP SCRIPT ///
			/////////////////////	
				
				Waitframe();
				
			}
			if ( ringOn && Link->MP ){                
                //Decrement magic
                ringTimer = (ringTimer+1) % ringTimePerMP;
                if ( !ringTimer ) Link->MP--;
				
				//Draw shadow under Link
                //Screen->FastTile( 2, Link->X, Link->Y, ringShadowTile, ringShadowCset, OP_TRANS );
                
                if ( Link->MP <= 0 //If magic ran out
                || Link->Action == LA_SCROLLING //Or left screen
                ){ //Take off ring
                    ringOn = false;
                    Link->CollDetection = true;
                    Link->Invisible = false;
                }

            }
            else if ( !ringOn ){ //Disable ring
                Link->CollDetection = true;
                Link->Invisible = false;
				
            }
			
			//////////////
			///END RING///
			//////////////
			
			/////////////////////////
			///BEGIN CANE OF BYRNA///
			/////////////////////////
			
			 if ( byrnaOn && Link->MP ){                
                //Decrement magic
                byrnaTimer = (byrnaTimer+1) % byrnaTimePerMP;
                if ( !byrnaTimer ) Link->MP--;
                
                if ( Link->MP <= 0 //If magic ran out
                || Link->Action == LA_SCROLLING //Or left screen
                ){ //Take off ring
                    byrnaOn = false;
                    Link->CollDetection = true;
                    Link->Invisible = false;
                }

            }
            else if ( !byrnaOn ){ //Disable ring
                Link->CollDetection = true;
                Link->Invisible = false;
			
            }
			
			///////////////////////
			///END CANE OF BYRNA///
			///////////////////////
			
			/////////////////
			///BEGIN BOOTS///
			/////////////////
			
			 if ( bootsOn && Link->MP ){                
                //Decrement magic
                bootsTimer = (bootsTimer+1) % bootsTimePerMP;
                if ( !bootsTimer ) Link->MP--;
                
                if ( Link->MP <= 0 //If magic ran out
                || Link->Action == LA_SCROLLING //Or left screen
                ){ //Take off ring
                    bootsOn = false;
                    Link->CollDetection = true;
                    Link->Invisible = false;
                }

            }
            else if ( !bootsOn ){ //Disable ring
                Link->CollDetection = true;
                Link->Invisible = false;
            }
			
			///////////////
			///END BOOTS///
			///////////////
		}
	}
}