Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Timer bar

hello everyone!
  So basiclly i put this exact same topic on the script support page, with the intention of creating a script myself. However after nearly shattering my brain over the script, I took the helpful advice of a member and decided to post it in the requests. Anyhow here is my request...

  I need a script that will help me create an steadily depleting bar, let me explain. In my game you have to eat so im making a hunger meter that slowly drops to zero. When this bar hits zero it you die. I need certain items to restore this bar and other items to pause it for a short while. It would be awsome if it were a HUD aswell. Thats about it...

Thanks guys!
 

khmp

Sponsor

I don't really come here as much as I should but I would like to handle your request if thats alright. Could you draw a picture of what the HUD should look like?
 

khmp

Sponsor

Well there's plenty of different ways to do it. The most common is creating a custom window and on that window writing all the information you want to see. You could also just have a picture displayed which we can still draw on top of. That's really up to you as the requester. Also, do you want the bar to run vertically, horizontally? Do you want it to be gradient. What colors do you want used? How big do you want it to be? I'm not so creative so you can't complain if I hand you a gray cube and tell you its the world. :wink:
 
LMAO!!! Let me plot this out, give me a couple minutes...

EDIT:

well here is the image i uploaded. I'll just give you the link: http://gallery.filefront.com/thermalburn//940977/

There has been a slight change of plans sorry lol. I changed the entire theme of the game to Survival, so i'll need
a hunger and thirst bar. The hunger bar depletes slower than the thirst bar. Food restores hunger and water restores thirst (obviously haha). Oh and just disregard the fatigue bar lol, ill just use SP to represent that. In terms of where the bars should be located, im not too sure. As an experienced RMXP user where would you say the HUD should be displayed?
 

khmp

Sponsor

Well I'm right handed and more important items are perspectively closer to the user. So bottom right is where I would if it was for me. The standard is the upper left corner because it seems out of the way. This is your request though, not mine. :shades: Alright give me a bit of time placement is a trivial manner.
 
Ya I think it should be bottom right as well.

Btw, is there any publication/book/internet resource that teaches you the basics of this RMXP scripting? I want to learn so i dont feel as though im just leeching off the RMXP.ORG community...
 

khmp

Sponsor

RMXP/VX scripting is built on top of Ruby. So any literature that you can get about that language will be good for learning syntax. There's also a Tutorial Thread in the Tutorial Section created by Mr. SephirothSpawn that lists a bunch of good Ruby/RGSS Resources.
 

khmp

Sponsor

http://files.filefront.com/State+Actorr ... einfo.html

Made a demo so my explanation could be shorter if possible. Uh not much to tell really. The bars work and drain slowly with the exception of fatigue which is based on Party Leader's SP. The HUD draws its data from the party leader. And also only the party leader's hunger/thirst are updated. So technically you could cheat and keep switching the leader but eventually one of you will need to eat and drink. The amount of decrement for thirst is 0.00005 while hunger is 0.000002.

Specific Items can be used to restore thirst and hunger. There are two modules which only contain constants.

Hunger_Settings contains two hashes and the rate at which hunger is decremented per update. The first hash holds the ids of the items that restore hunger and the value that they point to is the amount of hunger they restore. Example:
Code:
  3 => 0.2
Item number 3 in the Database restores 20% of your hunger. The second hash holds the ids of the items that postpone hunger from decrementing for a period of time. Example:
Code:
 4 => 400
For four hundred update calls hunger will not drop. It seems like a lot but it isn't a whole lot. Thirst_Settings which is the second module contains the a mirror image of what is contained within Hunger_Settings.

The script:
Code:
#==============================================================================
# ** Hunger_Settings
#------------------------------------------------------------------------------
#  This module holds hunger constants that are used over several classes.
#==============================================================================

module Hunger_Settings
  #--------------------------------------------------------------------------
  # HUNGER_ITEMS : this hash holds the item ids of the items that adjust your
  # hunger value for better or for worse.
  #--------------------------------------------------------------------------
  HUNGER_ITEMS = {
    # item_id => hunger_change Ex: 0 => 0.3 *No number larger than 1.0*
    33 => 0.1,
    34 => 0.5,
  }
  #--------------------------------------------------------------------------
  # HUNGER_FIXED_ITEMS : this hash holds the item ids of items that keep
  # your hunger value from lowering for a certain amount of time.
  #--------------------------------------------------------------------------
  HUNGER_FIXED_ITEMS = {
    # item_id => amount_of_time_hunger_isn't_affected
    35 => 500,
  }
  #--------------------------------------------------------------------------
  # HUNGER_RATE : the rate at which your hunger increases so to speak
  #--------------------------------------------------------------------------
  HUNGER_RATE = 0.00002
end

#==============================================================================
# ** Thirst_Settings
#------------------------------------------------------------------------------
#  This module holds thirst constants that are used over several classes.
#==============================================================================

module Thirst_Settings
  #--------------------------------------------------------------------------
  # THIRST_ITEMS : this hash holds the item ids of the items that adjust your
  # thirst value for better or for worse.
  #--------------------------------------------------------------------------
  THIRST_ITEMS = {
    # item_id => thirst_change Ex: 0 => 0.3 *No number larger than 1.0*
    36 => 0.1,
    37 => 0.5,
  }
  #--------------------------------------------------------------------------
  # THIRST_FIXED_ITEMS : this hash holds the item ids of items that keep
  # your thirst value from lowering for a certain amount of time.
  #--------------------------------------------------------------------------
  THIRST_FIXED_ITEMS = {
    # item_id => amount_of_time_thirst_isn't_affected
    38 => 500,
  }
  #--------------------------------------------------------------------------
  # THIRST_RATE : the rate at which your thirst increases so to speak
  #--------------------------------------------------------------------------
  THIRST_RATE = 0.00005
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_game_actor_initialize, :initialize
  alias_method :them_hunger_game_actor_item_effect, :item_effect
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :hunger
  attr_reader :hunger_fixed_cheat
  attr_reader :hunger_fixed_timer
  attr_reader :thirst
  attr_reader :thirst_fixed_cheat
  attr_reader :thirst_fixed_timer
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_id)
    them_hunger_game_actor_initialize(actor_id)
    # The current amount of hunger 1.0 means full 0.0 means starving.
    @hunger = 1.0
    # Is the current hunger amount fixed so it cannot move?
    @hunger_fixed_cheat = false
    # The amount of time before the hunger value begins to decrease again.
    @hunger_fixed_timer = 0
    # The current amount of hunger 1.0 means full 0.0 means starving.
    @thirst = 1.0
    # Is the current hunger amount fixed so it cannot move?
    @thirst_fixed_cheat = false
    # The amount of time before the hunger value begins to decrease again.
    @thirst_fixed_timer = 0
  end
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  def item_effect(item)
    them_hunger_game_actor_item_effect(item)
    
    # If the item is listed in the hash as affecting hunger. Change the 
    # hunger value for better or for worse.
    if Hunger_Settings::HUNGER_ITEMS.key?(item.id)
      @hunger += Hunger_Settings::HUNGER_ITEMS[item.id]
      @hunger = [@hunger, 1.0].min
    
    # If the item is in the item list that fixates hunger for a time.
    elsif Hunger_Settings::HUNGER_FIXED_ITEMS.key?(item.id)
      @hunger_fixed_timer = Hunger_Settings::HUNGER_FIXED_ITEMS[item.id]
    end
    
    # If the item is listed in the hash as affecting thirst. Change the 
    # thirst value for better or for worse.
    if Thirst_Settings::THIRST_ITEMS.key?(item.id)
      @thirst += Thirst_Settings::THIRST_ITEMS[item.id]
      @thirst = [@thirst, 1.0].min
    
    # If the item is in the item list that fixates thirst for a time.
    elsif Thirst_Settings::THIRST_FIXED_ITEMS.key?(item.id)
      @thirst_fixed_timer = Thirst_Settings::THIRST_FIXED_ITEMS[item.id]
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If the cheaty boolean is turned on then ignore hunger for this
    # actor.
    unless @hunger_fixed_cheat
      # If the hunger has been fixated for an amount of time update the timer
      # and return.
      if @hunger_fixed_timer > 0
        @hunger_fixed_timer -= 1
      else
        # Update the hunger value
        @hunger -= Hunger_Settings::HUNGER_RATE if @hunger > 0.0
      end
    end
    
    # If the cheaty boolean is turned on then ignore thirst for this
    # actor.
    unless @thirst_fixed_cheat
      # If the thirst has been fixated for an amount of time update the timer
      # and return.
      if @thirst_fixed_timer > 0
        @thirst_fixed_timer -= 1
      else
        # Update the thirst value
        @thirst -= Thirst_Settings::THIRST_RATE if @thirst > 0.0
      end
    end
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Hunger no longer drops
  #--------------------------------------------------------------------------
  def cheat_hunger_on
    @hunger_fixed_cheat = true
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Hunger can drop again
  #--------------------------------------------------------------------------
  def cheat_hunger_off
    @hunger_fixed_cheat = false
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Thirst no longer drops
  #--------------------------------------------------------------------------
  def cheat_thirst_on
    @thirst_fixed_cheat = true
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Thirst can drop again
  #--------------------------------------------------------------------------
  def cheat_thirst_off
    @thirst_fixed_cheat = false
  end
end

#==============================================================================
# ** State_HUD
#------------------------------------------------------------------------------
#  This hud displays the current state of the party leader.
#==============================================================================

class State_HUD < Sprite
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  STATE_HUD_DIR = 'Graphics/Pictures/State_HUD/'
  STATE_HUD_TEX = 'state_hud.png'
  STATE_HUD_HUNGER_TEX = 'hunger.png'
  STATE_HUD_FATIGUE_TEX = 'fatigue.png'
  STATE_HUD_THIRST_TEX = 'thirst.png'
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super()
    # Load the images in the initialize
    self.bitmap = Bitmap.new(STATE_HUD_DIR + STATE_HUD_TEX)
    @orig = Bitmap.new(STATE_HUD_DIR + STATE_HUD_TEX)
    @hunger_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_HUNGER_TEX)
    @fatigue_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_FATIGUE_TEX)
    @thirst_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_THIRST_TEX)
    
    # Instance variables that will be needed to check if we should refresh.
    @actor_hunger = @actor_fatigue = @actor_thirst = @actor = nil
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    x, y = 95, 0
    # If there was a change in hunger. Redraw hunger.
    if @actor_hunger != @actor.hunger
      # Save the instance variable for later checking.
      @actor_hunger = @actor.hunger
      
      # Re-adjust y
      y = 7
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @hunger_bp.width, @hunger_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, @hunger_bp.width * (@actor.hunger / 1.0), 
        @hunger_bp.height)
      
      # Draw the hunger bar
      self.bitmap.blt(x, y, @hunger_bp, draw_rect)
    end
    
    # If there was a change in hunger. Redraw fatigue.
    if @actor_fatigue != @actor.sp
      # Save the instance variable for later checking.
      @actor_fatigue = @actor.sp
      
      # Re-adjust y
      y = 26
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @fatigue_bp.width, @fatigue_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, 
        @fatigue_bp.width * (@actor.sp / @actor.maxsp), @fatigue_bp.height)
      
      # Draw the fatigue bar
      self.bitmap.blt(x, y, @fatigue_bp, draw_rect)
    end
    
    # If there was a change in thirst. Redraw thirst.
    if @actor_thirst != @actor.thirst
      # Save the instance variable for later checking.
      @actor_thirst = @actor.thirst
      
      # Re-adjust y
      y = 45
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @thirst_bp.width, @thirst_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, @thirst_bp.width * (@actor.thirst / 1.0), 
        @thirst_bp.height)
        
      # Draw the thirst bar.
      self.bitmap.blt(x, y, @thirst_bp, draw_rect)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @actor = $game_party.actors.first
    refresh
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super()
    self.bitmap.dispose unless self.bitmap.disposed?
    @orig.dispose unless @orig.disposed?
    @hunger_bp.dispose unless @hunger_bp.disposed?
    @fatigue_bp.dispose unless @fatigue_bp.disposed?
    @thirst_bp.dispose unless @thirst_bp.disposed?
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_scene_map_main, :main
  alias_method :them_hunger_scene_map_update, :update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create our Hunger HUD
    @state_hud = State_HUD.new
    @state_hud.x = 640 - @state_hud.bitmap.width - 10
    @state_hud.y = 480 - @state_hud.bitmap.height - 10
    @state_hud.z = 999
    @state_hud.opacity = 200
    
    them_hunger_scene_map_main
    
    # Dispose our Hunger HUD
    @state_hud.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update the party leader's hunger.
    $game_party.actors.first.update
    
    # Call the update for the hunger HUD.
    @state_hud.update
    
    # Call the old code.
    them_hunger_scene_map_update
  end
end

I think that's everything.

Good luck with your game Thermalburn! :thumb:
 
Haha! I dont mean to be rude but, do you know anyway that i can turn this script on or off? Like i dont want it to run during the intro to my game.

Edit: Another quick question; how should i modify the script so that when either the Hunger or Thirst hits zero you die(Gameover)?
 

khmp

Sponsor

Thermalburn":4mevhc9v said:
Haha! I dont mean to be rude but, do you know anyway that i can turn this script on or off? Like i dont want it to run during the intro to my game.

Edit: Another quick question; how should i modify the script so that when either the Hunger or Thirst hits zero you die(Gameover)?

Your intro takes place on a map? Le cry. Alright well I'll just have to have a boolean to be turned off or on.

Game Over when too thirsty or starved. In the Game_Actor update add a line that checks for the either of those values reach zero:
Code:
$scene = Scene_Gameover.new if @thirst <= 0.0 || @hunger <= 0.0

Or just add this tiny bit to the end it'll link up with the last part.
Code:
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_game_actor_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    them_hunger_game_actor_update
    # If thirst or hunger have reached 0 game over man... game over.
    $scene = Scene_Gameover.new if @thirst <= 0.0 || @hunger <= 0.0
  end
end

Replace Scene_Map section with this though:
Code:
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_scene_map_main, :main
  alias_method :them_hunger_scene_map_update, :update
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  HUD_VISIBLE_ID = 99
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create our Hunger HUD
    @state_hud = State_HUD.new
    @state_hud.x = 640 - @state_hud.bitmap.width - 10
    @state_hud.y = 480 - @state_hud.bitmap.height - 10
    @state_hud.z = 999
    @state_hud.opacity = 200
    @state_hud.visible = $game_switches[HUD_VISIBLE_ID]

    them_hunger_scene_map_main
    
    # Dispose our Hunger HUD
    @state_hud.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @state_hud.visible = $game_switches[HUD_VISIBLE_ID]
    if @state_hud.visible
      # Update the party leader's hunger.
      $game_party.actors.first.update
    
      # Call the update for the hunger HUD.
      @state_hud.update
    end
    
    # Call the old code.
    them_hunger_scene_map_update
  end
end

Now a switch controls whether or not hunger should be displayed or updated. I set the switch id to 99 but you can change it to anything you desire. Just change HUD_VISIBLE_ID to the value you want.
 
Hmmm, im getting syntax error. So all i have to do is copy that code and place it where exactly? Does it matter where in the Game_actor tab?

Edit:
Okay when i just put the HUD ID script i get a messege that says "script is hanging"...what the hecks that supposed mean lol?
 

khmp

Sponsor

I probably shouldn't have given it to you piece wise like that. Here's the whole script with those changes implemented.
Code:
#==============================================================================
# ** Hunger_Settings
#------------------------------------------------------------------------------
#  This module holds hunger constants that are used over several classes.
#==============================================================================

module Hunger_Settings
  #--------------------------------------------------------------------------
  # HUNGER_ITEMS : this hash holds the item ids of the items that adjust your
  # hunger value for better or for worse.
  #--------------------------------------------------------------------------
  HUNGER_ITEMS = {
    # item_id => hunger_change Ex: 0 => 0.3 *No number larger than 1.0*
  }
  #--------------------------------------------------------------------------
  # HUNGER_FIXED_ITEMS : this hash holds the item ids of items that keep
  # your hunger value from lowering for a certain amount of time.
  #--------------------------------------------------------------------------
  HUNGER_FIXED_ITEMS = {
    # item_id => amount_of_time_hunger_isn't_affected
  }
  #--------------------------------------------------------------------------
  # HUNGER_RATE : the rate at which your hunger increases so to speak
  #--------------------------------------------------------------------------
  HUNGER_RATE = 0.00002
end

#==============================================================================
# ** Thirst_Settings
#------------------------------------------------------------------------------
#  This module holds thirst constants that are used over several classes.
#==============================================================================

module Thirst_Settings
  #--------------------------------------------------------------------------
  # THIRST_ITEMS : this hash holds the item ids of the items that adjust your
  # thirst value for better or for worse.
  #--------------------------------------------------------------------------
  THIRST_ITEMS = {
    # item_id => thirst_change Ex: 0 => 0.3 *No number larger than 1.0*
  }
  #--------------------------------------------------------------------------
  # THIRST_FIXED_ITEMS : this hash holds the item ids of items that keep
  # your thirst value from lowering for a certain amount of time.
  #--------------------------------------------------------------------------
  THIRST_FIXED_ITEMS = {
    # item_id => amount_of_time_thirst_isn't_affected
  }
  #--------------------------------------------------------------------------
  # THIRST_RATE : the rate at which your thirst increases so to speak
  #--------------------------------------------------------------------------
  THIRST_RATE = 0.00005
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_game_actor_initialize, :initialize
  alias_method :them_hunger_game_actor_item_effect, :item_effect
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :hunger
  attr_reader :hunger_fixed_cheat
  attr_reader :hunger_fixed_timer
  attr_reader :thirst
  attr_reader :thirst_fixed_cheat
  attr_reader :thirst_fixed_timer
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_id)
    them_hunger_game_actor_initialize(actor_id)
    # The current amount of hunger 1.0 means full 0.0 means starving.
    @hunger = 1.0
    # Is the current hunger amount fixed so it cannot move?
    @hunger_fixed_cheat = false
    # The amount of time before the hunger value begins to decrease again.
    @hunger_fixed_timer = 0
    # The current amount of hunger 1.0 means full 0.0 means starving.
    @thirst = 1.0
    # Is the current hunger amount fixed so it cannot move?
    @thirst_fixed_cheat = false
    # The amount of time before the hunger value begins to decrease again.
    @thirst_fixed_timer = 0
  end
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  def item_effect(item)
    them_hunger_game_actor_item_effect(item)
    
    # If the item is listed in the hash as affecting hunger. Change the 
    # hunger value for better or for worse.
    if Hunger_Settings::HUNGER_ITEMS.key?(item.id)
      @hunger += Hunger_Settings::HUNGER_ITEMS[item.id]
    
    # If the item is in the item list that fixates hunger for a time.
    elsif Hunger_Settings::HUNGER_FIXED_ITEMS.key?(item.id)
      @hunger_fixed_timer = Hunger_Settings::HUNGER_FIXED_ITEMS.key?(item.id)
    end
    
    # If the item is listed in the hash as affecting thirst. Change the 
    # thirst value for better or for worse.
    if Thirst_Settings::THIRST_ITEMS.key?(item.id)
      @thirst += Thirst_Settings::THIRST_ITEMS[item.id]
    
    # If the item is in the item list that fixates thirst for a time.
    elsif Thirst_Settings::THIRST_FIXED_ITEMS.key?(item.id)
      @thirst_fixed_timer = Thirst_Settings::THIRST_FIXED_ITEMS.key?(item.id)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If the cheaty boolean is turned on then ignore hunger for this
    # actor.
    unless @hunger_fixed_cheat
      # If the hunger has been fixated for an amount of time update the timer
      # and return.
      if @hunger_fixed_timer > 0
        @hunger_fixed_timer -= 1
      else
        # Update the hunger value
        @hunger -= Hunger_Settings::HUNGER_RATE
      end
    end
    
    # If the cheaty boolean is turned on then ignore thirst for this
    # actor.
    unless @thirst_fixed_cheat
      # If the thirst has been fixated for an amount of time update the timer
      # and return.
      if @thirst_fixed_timer > 0
        @thirst_fixed_timer -= 1
      else
        # Update the thirst value
        @thirst -= Thirst_Settings::THIRST_RATE
      end
    end
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Hunger no longer drops
  #--------------------------------------------------------------------------
  def cheat_hunger_on
    @hunger_fixed_cheat = true
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Hunger can drop again
  #--------------------------------------------------------------------------
  def cheat_hunger_off
    @hunger_fixed_cheat = false
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Thirst no longer drops
  #--------------------------------------------------------------------------
  def cheat_thirst_on
    @thirst_fixed_cheat = true
  end
  #--------------------------------------------------------------------------
  # * &Cheat& Thirst can drop again
  #--------------------------------------------------------------------------
  def cheat_thirst_off
    @thirst_fixed_cheat = false
  end
end

#==============================================================================
# ** State_HUD
#------------------------------------------------------------------------------
#  This hud displays the current state of the party leader.
#==============================================================================

class State_HUD < Sprite
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  STATE_HUD_DIR = 'Graphics/Pictures/State_HUD/'
  STATE_HUD_TEX = 'state_hud.png'
  STATE_HUD_HUNGER_TEX = 'hunger.png'
  STATE_HUD_FATIGUE_TEX = 'fatigue.png'
  STATE_HUD_THIRST_TEX = 'thirst.png'
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super()
    # Load the images in the initialize
    self.bitmap = Bitmap.new(STATE_HUD_DIR + STATE_HUD_TEX)
    @orig = Bitmap.new(STATE_HUD_DIR + STATE_HUD_TEX)
    @hunger_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_HUNGER_TEX)
    @fatigue_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_FATIGUE_TEX)
    @thirst_bp = Bitmap.new(STATE_HUD_DIR + STATE_HUD_THIRST_TEX)
    
    # Instance variables that will be needed to check if we should refresh.
    @actor_hunger = @actor_fatigue = @actor_thirst = @actor = nil
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    x, y = 95, 0
    # If there was a change in hunger. Redraw hunger.
    if @actor_hunger != @actor.hunger
      # Save the instance variable for later checking.
      @actor_hunger = @actor.hunger
      
      # Re-adjust y
      y = 7
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @hunger_bp.width, @hunger_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, @hunger_bp.width * (@actor.hunger / 1.0), 
        @hunger_bp.height)
      
      # Draw the hunger bar
      self.bitmap.blt(x, y, @hunger_bp, draw_rect)
    end
    
    # If there was a change in hunger. Redraw fatigue.
    if @actor_fatigue != @actor.sp
      # Save the instance variable for later checking.
      @actor_fatigue = @actor.sp
      
      # Re-adjust y
      y = 26
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @fatigue_bp.width, @fatigue_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, 
        @fatigue_bp.width * (@actor.sp / @actor.maxsp), @fatigue_bp.height)
      
      # Draw the fatigue bar
      self.bitmap.blt(x, y, @fatigue_bp, draw_rect)
    end
    
    # If there was a change in thirst. Redraw thirst.
    if @actor_thirst != @actor.thirst
      # Save the instance variable for later checking.
      @actor_thirst = @actor.thirst
      
      # Re-adjust y
      y = 45
      
      # Clear out this portion so we can redraw to it.
      clear_rect = Rect.new(x, y, @thirst_bp.width, @thirst_bp.height)
      self.bitmap.blt(x, y, @orig, clear_rect)
      
      # Decide how much of the bitmap we will be using to draw.
      draw_rect = Rect.new(0, 0, @thirst_bp.width * (@actor.thirst / 1.0), 
        @thirst_bp.height)
        
      # Draw the thirst bar.
      self.bitmap.blt(x, y, @thirst_bp, draw_rect)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @actor = $game_party.actors.first
    refresh
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super()
    self.bitmap.dispose unless self.bitmap.disposed?
    @orig.dispose unless @orig.disposed?
    @hunger_bp.dispose unless @hunger_bp.disposed?
    @fatigue_bp.dispose unless @fatigue_bp.disposed?
    @thirst_bp.dispose unless @thirst_bp.disposed?
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :them_hunger_scene_map_main, :main
  alias_method :them_hunger_scene_map_update, :update
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  HUD_VISIBLE_ID = 99
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create our Hunger HUD
    @state_hud = State_HUD.new
    @state_hud.x = 640 - @state_hud.bitmap.width - 10
    @state_hud.y = 480 - @state_hud.bitmap.height - 10
    @state_hud.z = 999
    @state_hud.opacity = 200
    @state_hud.visible = $game_switches[HUD_VISIBLE_ID]

    them_hunger_scene_map_main
    
    # Dispose our Hunger HUD
    @state_hud.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @state_hud.visible = $game_switches[HUD_VISIBLE_ID]
    if @state_hud.visible
      # Update the party leader's hunger.
      $game_party.actors.first.update
    
      # Call the update for the hunger HUD.
      @state_hud.update
      
      if $game_party.actors.first.thirst <= 0.0 || 
        $game_party.actors.first.hunger <= 0.0
        $scene = Scene_Gameover.new 
      end
    end
    
    # Call the old code.
    them_hunger_scene_map_update
  end
end

Be careful if you have your item id for hunger/thirst and all set up. You might want to copy them to another location before you overwrite the old code.

[edit]
Woops. The code I put up I forgot the disposal code so the HUD stays around even after game over grab the new code if you see this.
 
Haha Sweet!! thanks bro its all good and working now! But for some reason my food items dont go away after using them. My thirst items do go away. So like i have 1 piece of bread and i can use indefinetly...

EDIT: Actually they dont even work...
 

khmp

Sponsor

I'd claim it as magic bread :wink: You need to set the scope of the item to "One Ally" or whatever. To get the item to disappear and actually use them.

If that doesn't work you'll need to make a demo for me to help you on this further. I can't guess all the variables.
 
LMAO magic bread!!! I did, still didnt work. Any thing that has to do with thirst is working. I even tried interchanging the items (ie the water fills up hunger) but still no luck.

EDIT: alrighty ill make a demo. once i figure out how lol
 

khmp

Sponsor

Just zip the folder of the project. Do not encrypt the project or I won't be able to see anything in the database or the scripts which are the place I need to see.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top