Health Potions

tbizzle

Well-known member
The first step in this health potion process will be to:
1. Make a Game Object or Monster and assign its Monster Flag to be a "Pickup/Powerup"

2. Next go to project settings and add a user variable and name it "healthPotion"

3. After that we will need to add this asm code to the Defined Scripts\Game\Pickup Script file. (In my script I used Monster #34. Also I am using both a Sprite HUD and Tile HUD in this example.) And you will probably need to change the HUD element # to match what your myHealth is assigned to.

Code:
 LDA Object_type,x
 CMP #$22
 BNE +notThisPickup
        
     LDA healthPotion
     CMP #$03
     BCS ++
  
     AddValue #$03, healthPotion, #$01, #$00
     ;PlaySound #sfx_ 
            ++
     ;UpdateHudElement #$03

Now we will need an input script to execute this Health Potion. Save this as an asm file and save it into your project. This example assumes your myHealth has 8 places. You can comment out or add to fit your game.

Code:
LDA healthPotion
    CMP #0
    BNE work10
    JMP canNotShoot45
    work10:
 
 
 
    LDA myHealth
    CMP #$08
    BNE faart
    JMP canNotShoot45
        faart:
  
    ;PlaySound #sfx_secretFound
    ;FlashScreen #$00, #$15

    LDA myHealth
    CMP #$07
    BNE faart1
    AddValue #$01, myHealth, #$01, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart1:
  
    LDA myHealth
    CMP #$06
    BNE faart2
    AddValue #$01, myHealth, #$02, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart2:
 
    LDA myHealth
    CMP #$05
    BNE faart3
    AddValue #$01, myHealth, #$03, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart3:
 
    LDA myHealth
    CMP #$04
    BNE faart4
    AddValue #$01, myHealth, #$04, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart4:
 
    LDA myHealth
    CMP #$03
    BNE faart5
    AddValue #$01, myHealth, #$05, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart5:
 
    LDA myHealth
    CMP #$02
    BNE faart6
    AddValue #$01, myHealth, #$06, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart6:
 
    LDA myHealth
    CMP #$01
    BNE faart7
    AddValue #$01, myHealth, #$07, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    ;UpdateHudElement #$00
        faart7:
 

                                                                                                                    
        canNotShoot45:
      
                        RTS

Now you will need to go into the input editor and assign this new script to a button of your choice and to "Main Game".
That should be enough to get you going! Comment if you need any help.

 
Last edited:

smilehero65

Active member
The first step in this health potion process will be to:
1. Make a Game Object or Monster and assign its Monster Flag to be a "Pickup/Powerup"

2. Next go to project settings and add a user variable and name it "healthPotion"

3. After that we will need to add this asm code to the Defined Scripts\Game\Pickup Script file. (In my script I used Monster #34. Also I am using a Sprite HUD and Tile HUD in this example.) And you will probably need to change the HUD element # to match what your myHealth is assigned to.

Code:
 LDA Object_type,x
 CMP #$22
 BNE +notThisPickup
         
     LDA healthPotion
     CMP #$03
     BCS ++
   
     AddValue #$03, healthPotion, #$01, #$00
     ;PlaySound #sfx_  
            ++
     UpdateHudElement #$03

Now we will need an input script to execute this Health Potion. Save this as an asm file and save it into your project. This example assumes your myHealth has 8 places. You can comment out or add to fit your game.

Code:
LDA healthPotion
    CMP #0
    BNE work10
    JMP canNotShoot45
    work10:
 
 
 
    LDA myHealth
    CMP #$08
    BNE faart
    JMP canNotShoot45
        faart:
   
    ;PlaySound #sfx_secretFound
    ;FlashScreen #$00, #$15

    LDA myHealth
    CMP #$07
    BNE faart1
    AddValue #$01, myHealth, #$01, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart1:
   
    LDA myHealth
    CMP #$06
    BNE faart2
    AddValue #$01, myHealth, #$02, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart2:
 
    LDA myHealth
    CMP #$05
    BNE faart3
    AddValue #$01, myHealth, #$03, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart3:
 
    LDA myHealth
    CMP #$04
    BNE faart4
    AddValue #$01, myHealth, #$04, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart4:
 
    LDA myHealth
    CMP #$03
    BNE faart5
    AddValue #$01, myHealth, #$05, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart5:
 
    LDA myHealth
    CMP #$02
    BNE faart6
    AddValue #$01, myHealth, #$06, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart6:
 
    LDA myHealth
    CMP #$01
    BNE faart7
    AddValue #$01, myHealth, #$07, #$00
    SubtractValue #$01, healthPotion, #$01, #$00
    UpdateHudElement #$00
        faart7:
 

                                                                                                                     
        canNotShoot45:
       
                        RTS

Now you will need to go into the input editor and assign this new script to a button of your choice and to "Main Game".
That should be enough to get you going! Comment if you need any help.

Very well done! Thank you for sharing! ⭐
 
Top Bottom