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.

Hunger and Sleep Need script

U know. If player do not eat anything,
he'll die!
If player do not sleep for 5 days,
he'll lose his senses.
for example: apple recovers 20 points of hunger.
one night recovers the all points of sleep need.
for example: the sleep need and hunger HUD is setting on by S key.

If U saw a script like that, please reply.
 
I have not seen a script like that, but I can make one.  Just give more detail.  This is extremely vague.  I know nothing about how this system should work or how you check if it's been five days or anything.  Give detail, and I'll give it a shot.
 
Thanks,
Hmm..
Just a simple system,
when u push "s", the hunger and sleep HUD shows.
Hunger has always the same value: 100 points of hunger, and 1 point is decrasing by 1 minute.
That's the same with sleep-need,

can do You do sth like that?
 
Just look for an ammo system.
Ammo = time in miniutes (would also help to have a day night system for the player)

Performing an action will regenerate the ammo (sleep)

After running out of ammo, decrease stats.

Its not that hard to edit an exsisting code thats in RGSS ...
 
But, i heven't found that script.
I've found a script:
Code:
#===============================================================================
# OSim v1.0.0
# Basic Sim Engine
# By OS
#===============================================================================
# Instructions:
# Place above Main and Below Default Scripts.
#
# To enable a particular actor's Needs, use:
#
# $game_party.actors[actor_id].needs.enable
#
# To disable an Actor's needs, use:
#
# $game_party.actors[actor_id].needs.disable
#
# To increase a particular Need for an actor, use:
#
# $game_party.actors[actor_id].needs.which_need(value),
# where which_need is one oft he six needs to alter:
#
# hunger
# hygene
# pleasure
# social
# toilet
# sleep
#
# and value is a number to increase the Need by. It will never go above 100
# or below 0.
#
# To see Actor 0's stats while on the map, press (and hold) the SHIFT key.
#
# IMPORTANT NOTICE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# Note that this is a simple engine. It won't do anything when values reach 0.
# You'll need to edit the script to have negative effects on your actors.
#===============================================================================

module OSim
  # Use these to increase the Needs values by defined amounts.
  Little = 2
  Alot = 10
  Max = 100
  # Use this to speed up/slow down the rate that the values decrease
  module Rate
    Hunger = Graphics.frame_rate * 4
    Hygene = Graphics.frame_rate * 2
    Pleasure = Graphics.frame_rate * 1
    Social = Graphics.frame_rate * 6
    Toilet = Graphics.frame_rate * 3
    Sleep = Graphics.frame_rate * 7
  end
end

class Game_Needs
  attr_reader :hunger, :hygene, :pleasure, :social, :toilet, :sleep
  
  def initialize(enabled = false)
    @hunger = @hygene = @pleasure = @social = @toilet = @sleep = 100
    @hunRate = OSim::Rate::Hunger
    @hygRate = OSim::Rate::Hygene
    @pleRate = OSim::Rate::Pleasure
    @socRate = OSim::Rate::Social
    @toiRate = OSim::Rate::Toilet
    @sleRate = OSim::Rate::Sleep
    @hunCount = @hygCount = @pleCount = @socCount = @toiCount = @sleCount = 0
    @enabled = enabled
  end
  
  def enable
    @enabled = true
  end
  
  def disable
    @enabled = false
  end
  
  def enabled?
    return @enabled
  end
  
  def update
    if @enabled
      @hunCount += 1
      @hygCount += 1
      @pleCount += 1
      @socCount += 1
      @toiCount += 1
      @sleCount += 1
      
      if @hunCount == @hunRate
        @hunger -= 1
        @hunCount = 0
      end
      
      if @hygCount == @hygRate
        @hygene -= 1
        @hygCount = 0
      end
      
      if @pleCount == @pleRate
        @pleasure -= 1
        @pleCount = 0
      end
      
      if @socCount == @socRate
        @social -= 1
        @socCount = 0
      end
      
      if @toiCount == @toiRate
        @toilet -= 1
        @toiCount = 0
      end
      
      if @sleCount == @sleRate
        @sleep -= 1
        @sleCount = 0
      end
    end
  end
  #========================================#
  # Increase and Decrease Hunger Manually  #
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def hunger(value)
    if value > 0
      @hunger += value <= 100 ? value : 100
    elsif value < 0
      @hunger -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Increase and Decrease Hygene Manually  #
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def hygene(value)
    if value > 0
      @hygene += value <= 100 ? value : 100
    elsif value < 0
      @hygene -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Increase and Decrease Pleasure Manually#
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def pleasure(value)
    if value > 0
      @pleasure += value <= 100 ? value : 100
    elsif value < 0
      @pleasure -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Increase and Decrease Social Manually  #
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def social(value)
    if value > 0
      @social += value <= 100 ? value : 100
    elsif value < 0
      @social -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Increase and Decrease Toilet Manually  #
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def toilet(value)
    if value > 0
      @toilet += value <= 100 ? value : 100
    elsif value < 0
      @toilet -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Increase and Decrease Sleep Manually   #
  # Note: Values are allways >= 0 & <= 100 #
  #========================================#
  def sleep(value)
    if value > 0
      @sleep += value <= 100 ? value : 100
    elsif value < 0
      @sleep -= value >= 0 ? value : 0
    end
  end
  #========================================#
  # Check if two Game_Needs Instances are  #
  # the same.                              #
  #========================================#
  def self.==(other)
    if other.is_a?(Game_Needs)
      if self.hunger != other.hunger
        return false
      elsif self.hygene != other.hygene
        return false
      elsif self.pleasure != other.pleasure
        return false
      elsif self.social != other.social
        return false
      elsif self.toilet != other.toilet
        return false
      elsif self.sleep != other.sleep
        return false
      else
        return true
      end
    else
      return false
    end
  end
  
  def hunger
    return @hunger
  end
  
  def hygene
    return @hygene
  end
  
  def pleasure
    return @pleasure
  end
  
  def social
    return @social
  end
  
  def toilet
    return @toilet
  end
  
  def sleep
    return @sleep
  end
end

class Window_Needs < Window_Base
  def initialize(actor_id)
    super(-224,-192,224,192)
    self.contents = Bitmap.new(self.width - 32,self.height - 32)
    @needs = $game_party.actors[actor_id].needs
    @actor_id = actor_id
    refresh
  end
  
  def refresh
    @needs = $game_party.actors[@actor_id].needs
    self.contents.clear
    if @needs.enabled?
      self.contents.draw_text(0,0,self.width,32,"Hunger: " + @needs.hunger.to_s + "/100")
      self.contents.draw_text(0,32,self.width,32,"Hygene: " + @needs.hygene.to_s + "/100")
      self.contents.draw_text(0,64,self.width,32,"Pleasure: " + @needs.pleasure.to_s + "/100")
      self.contents.draw_text(0,96,self.width,32,"Social: " + @needs.social.to_s + "/100")
      self.contents.draw_text(0,128,self.width,32,"Toilet: " + @needs.toilet.to_s + "/100")
      self.contents.draw_text(0,160,self.width,32,"Sleep: " + @needs.sleep.to_s + "/100")
    else
      self.contents.draw_text(48,66,self.width,32,"DISABLED")
    end
  end
  
  def update
    if @needs != $game_party.actors[@actor_id].needs
      refresh
    end
  end
end

class Game_Actor < Game_Battler
  attr_accessor :needs
  alias os_game_actor_setup setup
  def setup(actor_id)
    @needs = Game_Needs.new
    os_game_actor_setup(actor_id)
  end
end

class Scene_Map
  alias os_scene_map_main main
  def main
    @window_needs = Window_Needs.new(0)
    os_scene_map_main
    @window_needs.dispose
  end
  
  def actors_needs_update
    i = 0
    while i < $game_party.actors.length
      $game_party.actors[i].needs.update
      i += 1
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Loop
    loop do
      # Update map, interpreter, and player order
      # (this update order is important for when conditions are fulfilled 
      # to run any event, and the player isn't provided the opportunity to
      # move in an instant)
      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update
      # Update system (timer), screen
      $game_system.update
      $game_screen.update
      #====================================#
      if Input.press?(Input::A)
        @window_needs.refresh
        if @window_needs.x != 0
          @window_needs.x += 16
        end
        if @window_needs.y != 0
          @window_needs.y += 16
        end
      else
        if @window_needs.x != -0 - @window_needs.width
          @window_needs.x -= 16
        end
        if @window_needs.y != 0 - @window_needs.height
          @window_needs.y -= 16
        end
      end
      actors_needs_update
      #====================================#
      # Abort loop if player isn't place moving
      unless $game_temp.player_transferring
        break
      end
      # Run place move
      transfer_player
      # Abort loop if transition processing
      if $game_temp.transition_processing
        break
      end
    end
    # Update sprite set
    @spriteset.update
    # Update message window
    @message_window.update
    # If game over
    if $game_temp.gameover
      # Switch to game over screen
      $scene = Scene_Gameover.new
      return
    end
    # If returning to title screen
    if $game_temp.to_title
      # Change to title screen
      $scene = Scene_Title.new
      return
    end
    # If transition processing
    if $game_temp.transition_processing
      # Clear transition processing flag
      $game_temp.transition_processing = false
      # Execute transition
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    # If showing message window
    if $game_temp.message_window_showing
      return
    end
    # If encounter list isn't empty, and encounter count is 0
    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      # If event is running or encounter is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        # Confirm troop
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        # If troop is valid
        if $data_troops[troop_id] != nil
          # Set battle calling flag
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end
    # If debug mode is ON and F9 key was pressed
    if $DEBUG and Input.press?(Input::F9)
      # Set debug calling flag
      $game_temp.debug_calling = true
    end
    # If player is not moving
    unless $game_player.moving?
      # Run calling of each screen
      if $game_temp.battle_calling
        call_battle
      elsif $game_temp.shop_calling
        call_shop
      elsif $game_temp.name_calling
        call_name
      elsif $game_temp.menu_calling
        call_menu
      elsif $game_temp.save_calling
        call_save
      elsif $game_temp.debug_calling
        call_debug
      end
    end
  end
end

God bless RMXP.ORG
 

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