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.

A Needs script (Like the sims)

1st Script
Hey everyone,
                   I'm asking whether anyone could create a Needs script for me, rather like a simplified version of Sims 2 Needs. Needs are basically, things your character needs to do to saty alive and happy. Your Needs decrease over time making you unhappy, EG. You have the Hunger need, You become more hungry over time(this is represented by a bar that slowly decreases over time), to replenish you hunger(And fill the bar to the top) you need to eat food. This is used over an array of needs including Hygene: You need to wash to replenish the bar, Toilet: You need to use the toilet to replenish this one and much, much more.

I want the Needs to be:

Hunger

Hygene

Pleasure

Social

Toilet

Sleep

I preferably want it so when you press a certain button, the needs screen pops up telling you how high all your needs are, so the player can tend to them as he/she wants. I also want it so I can add a script or variable or switch to an item, EG. Food, so when that item is used, it replenishes the appropriate need bar!

This script I am asking of, will be used i my new MMORPG, Simtopia Online, Credit will be given for your work.
Thanks in advance!

SOLVED!

2nd Script

Skills Script

Hey everyone,
                  Me again! I would now like to request a Sims Skill script! I want it to be like sims 2, where if you read a book about cooking, you gain a skill point in cooking EG: You have a skill called cooking with 8 grey bars, when you read a cooking book, you gain a skill point in cooking, so now one bar is orange, and the others are still grey. Again I would like the window to pop out when a certain button is pressed, like OS's window, but I don't want the button to be shift for obvious reasons. I want the skills to be:

Cook

Clean

Charisma

Logic

Lie

Thanks in advance

Sprugles 555
 

OS

Sponsor

Hiya. I needed a quick break from VRE, and this looked like fun, so I thought I'd try to help. The instructions are in the script. Oh, this may not work if you are using NetPlay or something; I don't work with those scripts, so I don't know if the edits I made to default classes will work with them or not.

If you get any errors, just post. My test runs went perfect, so I don't think you'll have too much to worry about. Oh, and a final note, as I stated in the header of the script, under IMPORTANT NOTICE, this script only gives actors extra data. That data doesn't influence the actors at all, so if, let's say, hunger were to reach 0, it would not do anything. I don't know what you want it to do, and it seems like several people can find a use for this script, so I thought I'd just leave it alone at this point. Though I might edit it later to allow Hunger and Toilet to kill the actor, while the others affect stats. idk, yet.

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

In order to make the window, I had to alter Scene_Map's update method, but other than that, everything I altered has been aliased.
 

OS

Sponsor

It works fine for me. Are you using the command correctly?

The window only shows Actor 0. You need to use my Window class to create a new instance for Actor 1.
 

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