FANDOM


Created by Piysta.

Just felt like making something small, here you go. Heals 30 hp, and then 5 every second for 5 seconds. Should work, however I didn't test it. Feel free to do whatever with it.

Using "RC_Core.rcm"
; Define entry function 'Main'


; Health Potion Script
;
; Restores 30 health immediately, and then 5 health every second over 5 seconds.
;
; Requirements: Player Attribute "Health", Item called "Health Potion.
;
; This is a right click script for a health potion from the players inventory, or skill bar.


Function Main()

; Definitions
Player = Actor()
Health = Attribute(Player, "Health")
HealthMax = MaxAttribute(Player, "Health")

If Health >= HealthMax
   ; If the players health is/or greater than his max health. Do nothing. This way a potion is not used.
ElseIf Health < HealthMax
   ; If players health is less than his max health (he has taken some damage from something), then this will use the potion
   GiveItem(Player, "Health Potion", -1)
   NewHealth = Health + 30
   If NewHealth > HealthMax
      ; If when you get the +30 hp from the potion, that the new +30 of your hp is more than max hp. Set to max hp (so you dont go over your max)
      SetAttribute(Player, Health, HealthMax)
   Else
      ; if the +30 hp is still less, add the hp
      SetAttribute(Player, Health, NewHealth)
   EndIf
   
   ; this will add a buff on the player, so he can see that he has a health potion regening his hp. also, this loop will cause the hp to get every second for 5 seconds. if the hp goes over his max, he will gain 0 hp.
   AddActorEffect(Player, "Health Potion", "Health", 0, 5, 1) ; CHANGE THE 1 TO YOUR POTION TEXTURE ID
   HpClicks = 5
   .HpClick
      TotalHp = Attribute(Player, "Health")
      RegenHp = TotalHp + 5
      Floater = HealthMax - TotalHp
      If RegenHp >= HealthMax
         SetAttribute(Player, Health, HealthMax)
         CreateFloatingNumber(Player, Floater, 0, 255, 0)
      ElseIf RegenHp < HealthMax
         SetAttribute(Player, Health, RegenHp)
         CreateFloatingNumber(Player, Floater, 0, 255, 0)
      EndIf
      HpClicks = HpClicks - 1
   Until HpClicks = 0
EndIf

Return
End Function