[Resolved] Merging one script into another

Started by kukusu, April 06, 2010, 01:59:23 pm

Previous topic - Next topic

kukusu

April 06, 2010, 01:59:23 pm Last Edit: May 02, 2010, 06:32:38 pm by Starrodkirby86
Please, if someone wants to help, just say so... If someone has an idea that is different from mine, but is still useful and practical, it'll be welcome.
I'm good spriter, I can even trade sprites from scripts.
So well... here is the request.

Hello everyone!
I'm looking for a script that handles hunger. Hunger level would increase over time and could be lowered by using certain items like food. I think there are scripts for that alone, but I would prefer a script that could show the hunger status on the menu, like the HP and SP are shown.
I don't need the class, level or experience bars showing in the menu, so, if one of them could be replaced with hunger bar, that would be perfect.
Not even a bar is necessary, the classical numbers (example 51/170) will do just fine.

Here's a screencap for better explanation.


The bars don't come with the menu they're from Tons of Add ons.

Here is the script for the menu I'm using, so you can modify it.
Code:

#------------------------------------------------------------------------------
#==============================================================================
#==============================================================================
#====================*Law's Custom Menu Screen*================================
#=========================Author: The Law G14==================================
#============================Version 1.0=======================================
#==============================================================================
#------------------------------------------------------------------------------
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :tileset_name             # tileset file name
 attr_accessor :autotile_names           # autotile file name
 attr_accessor :panorama_name            # panorama file name
 attr_accessor :panorama_hue             # panorama hue
 attr_accessor :fog_name                 # fog file name
 attr_accessor :fog_hue                  # fog hue
 attr_accessor :fog_opacity              # fog opacity level
 attr_accessor :fog_blend_type           # fog blending method
 attr_accessor :fog_zoom                 # fog zoom rate
 attr_accessor :fog_sx                   # fog sx
 attr_accessor :fog_sy                   # fog sy
 attr_accessor :battleback_name          # battleback file name
 attr_accessor :display_x                # display x-coordinate * 128
 attr_accessor :display_y                # display y-coordinate * 128
 attr_accessor :need_refresh             # refresh request flag
 attr_reader   :passages                 # passage table
 attr_reader   :priorities               # prioroty table
 attr_reader   :terrain_tags             # terrain tag table
 attr_reader   :events                   # events
 attr_reader   :fog_ox                   # fog x-coordinate starting point
 attr_reader   :fog_oy                   # fog y-coordinate starting point
 attr_reader   :fog_tone                 # fog color tone
 attr_reader   :name
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   @map_id = 0
   @display_x = 0
   @display_y = 0
 end
 #--------------------------------------------------------------------------
 # * Setup
 #     map_id : map ID
 #--------------------------------------------------------------------------
 def setup(map_id)
   # Put map ID in @map_id memory
   @map_id = map_id
   # Load map from file and set @map
   @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
   # set tile set information in opening instance variables
   tileset = $data_tilesets[@map.tileset_id]
   @tileset_name = tileset.tileset_name
   @autotile_names = tileset.autotile_names
   @panorama_name = tileset.panorama_name
   @panorama_hue = tileset.panorama_hue
   @fog_name = tileset.fog_name
   @fog_hue = tileset.fog_hue
   @fog_opacity = tileset.fog_opacity
   @fog_blend_type = tileset.fog_blend_type
   @fog_zoom = tileset.fog_zoom
   @fog_sx = tileset.fog_sx
   @fog_sy = tileset.fog_sy
   @battleback_name = tileset.battleback_name
   @passages = tileset.passages
   @priorities = tileset.priorities
   @terrain_tags = tileset.terrain_tags
   # Initialize displayed coordinates
   @display_x = 0
   @display_y = 0
   # Clear refresh request flag
   @need_refresh = false
   # Set map event data
   @events = {}
   for i in @map.events.keys
     @events[i] = Game_Event.new(@map_id, @map.events[i])
   end
   # Set common event data
   @common_events = {}
   for i in 1...$data_common_events.size
     @common_events[i] = Game_CommonEvent.new(i)
   end
   # Initialize all fog information
   @fog_ox = 0
   @fog_oy = 0
   @fog_tone = Tone.new(0, 0, 0, 0)
   @fog_tone_target = Tone.new(0, 0, 0, 0)
   @fog_tone_duration = 0
   @fog_opacity_duration = 0
   @fog_opacity_target = 0
   # Initialize scroll information
   @scroll_direction = 2
   @scroll_rest = 0
   @scroll_speed = 4
   @name = load_data("Data/MapInfos.rxdata")[@map_id].name
 end
end

#==============================================================================
# ** Window_Location
#-----------------------------------------------------------------------------
# A window that shows your current Location.
#==============================================================================

class Window_Location < Window_Base
 #-----------------------------------------------------------------------------
 # * Object Initialization
 #-----------------------------------------------------------------------------
 def initialize
   super(0, 0, 160, 96)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #-----------------------------------------------------------------------------
 # * Refresh
 #-----------------------------------------------------------------------------
 def refresh
   self.contents.clear
   self.contents.font.color = system_color
   self.contents.draw_text(4, 0, 120, 32, "Localización")
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 32, 120, 32, $game_map.name, 2)
 end
end

#==============================================================================
# ** Window_MenuStatus
#------------------------------------------------------------------------------
#  This window displays party member status on the menu screen.
#==============================================================================

class Window_MenuStatus < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 480, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
   self.active = false
   self.index = -1
 end
 #--------------------------------------------------------------------------
 # * Draw Face Graphic
 #     actor : actor
 #     x : draw spot x-coordinate
 #     y : draw spot y-coordinate
 #--------------------------------------------------------------------------
 def draw_actor_face_graphic(actor, x, y)
    bitmap = RPG::Cache.picture(actor.id.to_s)
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
  end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   @item_max = $game_party.actors.size
   for i in 0...$game_party.actors.size
     x = 64
     y = i * 116
     actor = $game_party.actors[i]
     draw_actor_face_graphic(actor, x - 64, y)
     draw_actor_name(actor, x + 93, y)
     draw_actor_class(actor, x + 135, y + 32)
     draw_actor_level(actor, x + 40, y + 32)
     draw_actor_state(actor, x + 270, y)
     draw_actor_exp(actor, x + 40, y + 64)
     draw_actor_hp(actor, x + 236, y + 32)
     draw_actor_sp(actor, x + 236, y + 64)
   end
 end
 #--------------------------------------------------------------------------
 # * Cursor Rectangle Update
 #--------------------------------------------------------------------------
 def update_cursor_rect
   if @index < 0
     self.cursor_rect.empty
   else
     self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
   end
 end
end

#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================

class Scene_Menu
 #--------------------------------------------------------------------------
 # * Object Initialization
 #     menu_index : command cursor's initial position
 #--------------------------------------------------------------------------
 def initialize(menu_index = 0)
   @menu_index = menu_index
 end
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
   # Make command window
   s1 = $data_system.words.item
   s2 = $data_system.words.skill
   s3 = $data_system.words.equip
   s4 = "Status"
   s5 = "Guardar"
   s6 = "Salir"
   @command_window = Window_Command_New.new(160, [s1, s2, s3, s4, s5, s6])
   @command_window.index = @menu_index
   @command_window.height = 225
   @command_window.x = 480
   # If number of party members is 0
   if $game_party.actors.size == 0
     # Disable items, skills, equipment, and status
     @command_window.disable_item(0)
     @command_window.disable_item(1)
     @command_window.disable_item(2)
     @command_window.disable_item(3)
   end
   # If save is forbidden
   if $game_system.save_disabled
     # Disable save
     @command_window.disable_item(4)
   end
   # Make play time window
   @playtime_window = Window_PlayTime.new
   @playtime_window.x = 480
   @playtime_window.y = 224
   # Make location window
   @location_window = Window_Location.new
   @location_window.x = 480
   @location_window.y = 320
   # Make gold window
   @gold_window = Window_Gold.new
   @gold_window.x = 480
   @gold_window.y = 416
   # Make status window
   @status_window = Window_MenuStatus.new
   @status_window.x = 0
   @status_window.y = 0
   # Execute transition
   Graphics.transition
   # Main loop
   loop do
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     if $scene != self
       break
     end
   end
   # Prepare for transition
   Graphics.freeze
   # Dispose of windows
   @command_window.dispose
   @playtime_window.dispose
   @location_window.dispose
   @gold_window.dispose
   @status_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Update windows
   @command_window.update
   @playtime_window.update
   @location_window.update
   @gold_window.update
   @status_window.update
   # If command window is active: call update_command
   if @command_window.active
     update_command
     return
   end
   # If status window is active: call update_status
   if @status_window.active
     update_status
     return
   end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (when command window is active)
 #--------------------------------------------------------------------------
 def update_command
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to map screen
     $scene = Scene_Map.new
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # If command other than save or end game, and party members = 0
     if $game_party.actors.size == 0 and @command_window.index < 4
       # Play buzzer SE
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     # Branch by command window cursor position
     case @command_window.index
     when 0  # item
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to item screen
       $scene = Scene_Item.new
     when 1  # skill
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Make status window active
       @command_window.active = false
       @status_window.active = true
       @status_window.index = 0
     when 2  # equipment
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Make status window active
       @command_window.active = false
       @status_window.active = true
       @status_window.index = 0
     when 3  # status
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Make status window active
       @command_window.active = false
       @status_window.active = true
       @status_window.index = 0
     when 4  # save
       # If saving is forbidden
       if $game_system.save_disabled
         # Play buzzer SE
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to save screen
       $scene = Scene_Save.new
     when 5  # end game
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to end game screen
       $scene = Scene_End.new
     end
     return
   end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (when status window is active)
 #--------------------------------------------------------------------------
 def update_status
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Make command window active
     @command_window.active = true
     @status_window.active = false
     @status_window.index = -1
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # Branch by command window cursor position
     case @command_window.index
     when 1  # skill
       # If this actor's action limit is 2 or more
       if $game_party.actors[@status_window.index].restriction >= 2
         # Play buzzer SE
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to skill screen
       $scene = Scene_Skill.new(@status_window.index)
     when 2  # equipment
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to equipment screen
       $scene = Scene_Equip.new(@status_window.index)
     when 3  # status
       # Play decision SE
       $game_system.se_play($data_system.decision_se)
       # Switch to status screen
       $scene = Scene_Status.new(@status_window.index)
     end
     return
   end
 end
end
#===============================================================================
# ** Window_Command_New
#-------------------------------------------------------------------------------
# This code allows the command window in the menu to display icons.
#===============================================================================

class Window_Command_New < Window_Selectable
 #-----------------------------------------------------------------------------
 # * Public Instance Variables
 #-----------------------------------------------------------------------------
 attr_reader :continue
 #-----------------------------------------------------------------------------
 # * Object Initialization
 #-----------------------------------------------------------------------------
 def initialize(index, continue)
   commands = [$data_system.words.item, $data_system.words.skill, $data_system.words.equip,
       'Status', 'Guardar', 'Salir']
   super(0, 0, 160, commands.size * 32 + 32)
   @item_max = commands.size
   @commands = commands
   self.contents = Bitmap.new(width - 32, @item_max * 32)
   refresh
   self.index = 0
 end
 #-----------------------------------------------------------------------------
 # * Draw Item
 #-----------------------------------------------------------------------------
 def draw_item(i, color)
   self.contents.fill_rect(0, i*32, 148, 32, Color.new(0, 0, 0, 0))
   bitmap = RPG::Cache.icon("Menu#{i}")
   opacity = (color == normal_color ? 255 : 128)
   self.contents.blt(4, 4 + i*32, bitmap, Rect.new(0, 0, 24, 24), opacity)
   self.contents.font.color = color
   self.contents.draw_text(28, i*32, 148, 32, @commands[i])
 end
 #-----------------------------------------------------------------------------
 # * Refresh
 #-----------------------------------------------------------------------------
 def refresh
   self.contents.clear
   for i in 0...@item_max
     draw_item(i, normal_color)
   end
 end
end
#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Gold < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 160, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Draw Picture
 #--------------------------------------------------------------------------  
 def draw_picture(x, y)
   bitmap = RPG::Cache.picture("Coin")
   cw = bitmap.width
   ch = bitmap.height
   src_rect = Rect.new(0, 0, cw, ch)
   self.contents.blt(x, y, bitmap, src_rect)
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   draw_picture(105, 4)
   cx = contents.text_size($data_system.words.gold).width
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
 end
end


I have searched for this, but I only found scripts about hunger or scripts for bars. I assume that there's no much people who wants the experience bar deleted... :P

I have no idea about scripting, so I don't know if this will be too difficult.
So, for anyone who tries to help me, thank you very much!
Here is this link to a hunger script that probably could be merged into this menu.

http://www.rpgrevolution.com/forums/index.php?showtopic=9764

Thank you again!

ForeverZer0

I may took a look into this, it shouldn't be too difficult at all.
I'm not sure exactly when I'll get a chance, I got another script in progress, but I'll see what I can do.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Jackolas

will take a quick look later today.

kukusu


Thank you for your responses!
I'll be waiting...

ForeverZer0

I just thought, it if I'm gonna do this, I'm gonna need a copy of your Hunger script and and a copy of your CMS so I can get the bars put in the right place.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

kukusu

What do you need?
I already provided the scripts i want to use in my post.
However, I've been testing the hunger script alone, in a new project (without any custom script except the hunger one), and it doesnt seem to work. An error mesage appears. Maybe this hunger script just doesn't work.
Anyways, i just provided that script to make it easier for the scripters to do it. I thought that if I provided a hunger script, it would be easier and there would be more probabilities for me to get help.
But I don't have any idea about scriptig, maybe this could be easily done by... i dont know, variables maybe??

Well, what I'm trying to say is that i dont need te hunger script to be THAT hunger script. Anything would do, i just need a hunger bar in the menu , and hunger increasing over time, and the possibility to lower hunger level with items.
If the items could be applied to any actor (like the default potions and items) it would be much better. I just say this because I believe that in this hunger script (the one provided) Items will only affect one actor. (I'm not sure). And if it is like that, it will be kind of strange to have 4 different kinds of apple, "apple for actor1" "apple for actor 2" etc.

Again thank you very much for your interest, I will provide anything you need, just let me know.

ForeverZer0

April 28, 2010, 07:06:22 pm #6 Last Edit: May 01, 2010, 12:33:56 am by ForeverZero
Okay, buddy, here ya go. Sorry I took so long.

I couldn't stand how your hunger script worked, so I wrote my own much improved one.
Its much easier to use, doesn't require 1000 common events and is coded MUCH better.
I haven't posted it up yet so you are gonna be the very first to try it out.
Don't you feel lucky? ;)

Here it is...
Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Hunger/Thirst
# Author: ForeverZer0
# Date:
# Version: 1.0
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Features:
#   - Easy to use
#   - MUCH less complicated than many other similar scripts, yet it has more
#     features and less code
#   - Can have hunger and thirst decrease by time intervals or by steps walked
#     by the player
#   - Ability to have each character's 'Max Hunger' increase so that they can go
#     longer in between food and drinks as they gain in power
#   - Can use script calls to easily change hunger/thirst values, and to disable
#     the system for long cutscenes, etc. so that nothing decreases while the
#     player does not have control
#
# Instructions:
#   - Place script below debug, and above main
#   - All configuration is below and described fully in its respective section
#   - The following script calls can be used in game:
#
#    ►  $game_party.hunger = true/false 
#       - If false, hunger/thirst rates will not decrease. Good for long scenes
#         where the player is not in control, etc.
#
#    ►  Zer0.set_hunger(ACTOR_ID, AMOUNT)
#    ►  Zer0.set_thirst(ACTOR_ID, AMOUNT)
#       - Sets the hunger/thirst of actor in your database with ACTOR_ID to the
#         number specified by AMOUNT
#
#    ►  Zer0.set_max_hunger(ACTOR_ID, AMOUNT)
#    ►  Zer0.set_max_thirst(ACTOR_ID, AMOUNT)
#       - Sets the MAX hunger/thirst of actor in your database with ACTOR_ID to
#         the number specified by AMOUNT
#
#    ►  Zer0.recover_hunger(ACTOR_ID)
#       - Will recover all hunger/thirst to actor with ACTOR_ID. If you omit the
#         ( ) at the end of the script call, it will recover the entire party.
#
#    ►  Zer0.actor_hunger(ACTOR_ID)
#       - Returns the current hunger of actor with ACTOR_ID
#
#    ►  Zer0.actor_thirst(ACTOR_ID)
#       - Returns the current thirst of actor with ACTOR_ID
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:


#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                         BEGIN CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

module Zer0
 
  DEFAULT_HUNGER = 100           
  DEFAULT_THIRST = 100         
  # Default max hunger/thirst players will begin with. This can be increased as
  # the player becomes more powerful, through items, etc. if desired.
 
  BY_TIME   = false
  BY_STEPS  = true
  # There are two ways hunger and thirst can be calculated; one by just how many
  # seconds pass, and the other by how many steps have been taken. You can use
  # both if you like, but I would suggest that if you do to try to keep it more
  # skewed to one or the other as the main method of decreasing, and use the
  # other as a minor added dynamic.
 
  STEPS_HUNGER_DOWN = 80 
  STEPS_THIRST_DOWN = 80
  # Only if using 'BY_STEPS', otherwise ignore these. These are the amount
  # of steps before hunger/thirst decrease.
 
  SECS_HUNGER_DOWN = 120
  SECS_THIRST_DOWN = 120
  # Only if using 'BY_TIME', otherwise ignore these. These are the amount
  # of seconds before hunger/thirst decrease.
 
  LVL_UP_INCREASE = false
  # If true, will increase max hunger/thirst at each level up, the amount of
  # increase is defined just below
  LVL_UP_AMOUNT = 5
  # This will be added to the actor's max hunger/thirst at each level up, only
  # if LVL_UP_INCREASE is true
 
#-------------------------------------------------------------------------------
# Food/Drink Items:
#
#   Set up your food/drink items recovery rates here. Food and drink are each in
#   their own section. Use this syntax to set them up:
#
#     when ITEM_ID the return RECOVERY_AMOUNT
#
#   For example, in the first example below, it means that the item in your
#   database with ID(1) will cure hunger by 15.
#
#   You can also create items that have negative effects by making the
#   RECOVERY_AMOUNT a negative number.
#
#-------------------------------------------------------------------------------

  def self.food(item_id)
    case item_id
    when 1 then return 15
    when 2 then return 25
    when 3 then return 35
    when 4 then return 50
    when 5 then return 75
    when 6 then return 100
    end
    return 0
  end
 
  def self.drink(item_id)
    case item_id
    when 1 then return 15
    when 2 then return 25
    when 3 then return 35
    when 4 then return 50
    when 5 then return 75
    when 6 then return 100
    end
    return 0
  end
 
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                         END CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

  def self.set_hunger(actor_id, amount)
    $game_party.actors.each {|a| a.hunger = amount if a.id == actor_id}
  end
   
  def self.set_thirst(actor_id, amount)
    $game_party.actors.each {|a| a.thirst = amount if a.id == actor_id}
  end 
 
  def self.set_max_hunger(actor_id, amount)
    $game_party.actors.each {|a| a.max_hunger = amount if a.id == actor_id}
  end
   
  def self.set_max_thirst(actor_id, amount)
    $game_party.actors.each {|a| a.max_thirst = amount if a.id == actor_id}
  end   
 
  def self.actor_hunger(actor_id)
    $game_party.actors.each {|a| return a.hunger if a.id == actor_id}
  end
 
  def self.actor_thirst(actor_id)
    $game_party.actors.each {|a| return a.thirst if a.id == actor_id}
  end
 
  def self.recover_hunger(actor_id = nil)
    $game_party.actors.each {|actor|
      if actor_id == nil
        actor.hunger = actor.max_hunger
        actor.thirst = actor.max_thirst
      elsif actor.id == actor_id
        actor.hunger = actor.max_hunger
        actor.thirst = actor.max_thirst
      end
    }
  end
end

#-------------------------------------------------------------------------------
# ** Game_Actor
#-------------------------------------------------------------------------------

class Game_Actor < Game_Battler
 
  attr_accessor :hunger
  attr_accessor :max_hunger
  attr_accessor :thirst
  attr_accessor :max_thirst
 
  alias zer0_hunger_setup setup
  def setup(actor_id)
    zer0_hunger_setup(actor_id)
    @hunger = @max_hunger = Zer0::DEFAULT_HUNGER
    @thirst = @max_thirst = Zer0::DEFAULT_THIRST
    if Zer0::LVL_UP_INCREASE && @level > 1
      increase = Zer0::LVL_UP_AMOUNT
      @hunger = @max_hunger = (@level - 1) * increase + Zer0::DEFAULT_HUNGER
      @thirst = @max_thirst = (@level - 1) * increase + Zer0::DEFAULT_THIRST
    end
  end
 
  alias zer0_hunger_level_up exp=
  def exp=(exp)
    zer0_hunger_level_up(exp)
    if Zer0::LVL_UP_INCREASE
      increase = Zer0::LVL_UP_AMOUNT
      @max_hunger = (@level - 1) * increase + Zer0::DEFAULT_HUNGER
      @max_thirst = (@level - 1) * increase + Zer0::DEFAULT_THIRST
    end
  end 
end

#-------------------------------------------------------------------------------
# ** Game_Battler
#-------------------------------------------------------------------------------

class Game_Battler
 
  alias test item_effect
  def item_effect(item)
    test(item)
    self.hunger += Zer0.food(item.id)
    self.thirst += Zer0.drink(item.id)
    self.hunger = self.max_hunger if self.hunger > self.max_hunger
    self.hunger = 0 if self.hunger < 0
    self.thirst = self.max_thirst if self.thirst > self.max_thirst
    self.thirst = 0 if self.thirst < 0
  end
end

#-------------------------------------------------------------------------------
# ** Game_Party
#-------------------------------------------------------------------------------

class Game_Party
 
  attr_accessor :hunger
  attr_accessor :time_hunger
  attr_accessor :time_thirst
  attr_accessor :step_hunger
  attr_accessor :step_thirst
 
  alias zer0_hunger_system_init initialize
  def initialize
    zer0_hunger_system_init
    @hunger = true
    @time_hunger = @time_thirst = 0
    @step_hunger = (Zer0::STEPS_HUNGER_DOWN / 2)
    @step_thirst = (Zer0::STEPS_THIRST_DOWN / 2)
  end
end

#-------------------------------------------------------------------------------
# ** Scene_Map
#-------------------------------------------------------------------------------

class Scene_Map
 
  alias zer0_hunger_map_upd update
  def update
    zer0_hunger_map_upd
    if $game_party.hunger
      update_hunger
    end
  end
 
  def update_hunger
    if Zer0::BY_TIME
      $game_party.time_hunger += 1
      $game_party.time_thirst += 1
      if $game_party.time_hunger == (Zer0::SECS_HUNGER_DOWN * 40)
        $game_party.actors.each {|actor| actor.hunger -= 1 if actor.hunger != 0}
        $game_party.time_hunger = 0
      end
      if $game_party.time_thirst == (Zer0::SECS_THIRST_DOWN * 40)
        $game_party.actors.each {|actor| actor.thirst -= 1 if actor.thirst != 0}
        $game_party.time_thirst = 0
      end
    end
    if Zer0::BY_STEPS
      if $game_party.steps == $game_party.step_hunger
        $game_party.actors.each {|actor| actor.hunger -= 1 if actor.hunger != 0}
        $game_party.step_hunger = $game_party.steps + (Zer0::STEPS_HUNGER_DOWN / 2)
      end
      if $game_party.steps == $game_party.step_thirst
        $game_party.actors.each {|actor| actor.thirst -= 1 if actor.thirst != 0}
        $game_party.step_thirst = $game_party.steps + (Zer0::STEPS_THIRST_DOWN / 2)
      end
    end
  end
end


I also went through your CMS and made a few major improvements and deleted a couple hundred worthless lines of code. I also created a a couple custom methods that would draw the hunger/thirst bars on your CMS. They require the hunger script I wrote to work, so I really hope you like it...   I didn't play around with the colors for the bars, I figured you could do that and find what you like best. Well, enough talk. Here it is. Just replace this with the script that you have posted above and take a look. (Remember to also have the Hunger script thats in the above spoiler)

Spoiler: ShowHide
#-------------------------------------------------------------------------------
# ** Game_Map (Zer0)
#-------------------------------------------------------------------------------

class Game_Map

  def name
    return load_data('Data/MapInfos.rxdata')[@map_id].name
  end
end

#-------------------------------------------------------------------------------
# ** Window_Base (Zer0)
#-------------------------------------------------------------------------------
class Window_Base
 
  def draw_actor_hunger(actor, x, y, w = 148)
    if $game_system.BARS
      w += 12
      rate = (actor.hunger != 0 ? actor.hunger.to_f / actor.max_hunger : 0)
      if rate < 0.5
        color1 = Color.new(20 * rate, 60, 80, 192)
        color2 = Color.new(60 * rate, 180, 240, 192)
      elsif rate >= 0.5
        color1 = Color.new(20 + 120 * (rate-0.5), 60 + 40 * (rate-0.5), 80, 192)
        color2 = Color.new(60 + 360 * (rate-0.5), 180 + 120 * (rate-0.5), 240, 192)
      end
      color3 = Color.new(80, 80, 80, 192)
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
    end
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 148, 32, 'Hunger')
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 24, y, 84, 32, actor.hunger.to_s, 2)
    self.contents.draw_text(x + 108, y, 12, 32, '/', 1)
    self.contents.draw_text(x + 120, y, 84, 32, actor.max_hunger.to_s)
  end 
 
  def draw_actor_thirst(actor, x, y, w = 148)
    if $game_system.BARS
      w += 12
      rate = (actor.thirst != 0 ? actor.thirst.to_f / actor.max_thirst : 0)
      if rate < 0.5
        color1 = Color.new(20 * rate, 60, 80, 192)
        color2 = Color.new(60 * rate, 180, 240, 192)
      elsif rate >= 0.5
        color1 = Color.new(20 + 120 * (rate-0.5), 60 + 40 * (rate-0.5), 80, 192)
        color2 = Color.new(60 + 360 * (rate-0.5), 180 + 120 * (rate-0.5), 240, 192)
      end
      color3 = Color.new(80, 80, 80, 192)
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
    end
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 148, 32, 'Thirst')
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 24, y, 84, 32, actor.thirst.to_s, 2)
    self.contents.draw_text(x + 108, y, 12, 32, '/', 1)
    self.contents.draw_text(x + 120, y, 84, 32, actor.max_thirst.to_s)
  end
end

#==============================================================================
# ** Window_Location
#-----------------------------------------------------------------------------
# A window that shows your current Location.
#==============================================================================

class Window_Location < Window_Base
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #-----------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Localización")
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, $game_map.name, 2)
  end
end

#==============================================================================
# ** Window_MenuStatus
#------------------------------------------------------------------------------
#  This window displays party member status on the menu screen.
#==============================================================================

class Window_MenuStatus < Window_Selectable

  #--------------------------------------------------------------------------
  # * Draw Face Graphic
  #     actor : actor
  #     x : draw spot x-coordinate
  #     y : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_face_graphic(actor, x, y)
     bitmap = RPG::Cache.picture(actor.id.to_s)
     self.contents.blt(x, y, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
   end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      x = 64
      y = i * 116
      actor = $game_party.actors[i]
      draw_actor_face_graphic(actor, x - 64, y)
      draw_actor_name(actor, x + 93, y)
      #--------------------------------------------
      draw_actor_hunger(actor, x + 40, y + 32)
      draw_actor_thirst(actor, x + 40, y + 64)
      #--------------------------------------------
      draw_actor_state(actor, x + 270, y)
      draw_actor_hp(actor, x + 236, y + 32)
      draw_actor_sp(actor, x + 236, y + 64)
    end
  end
end

#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================

class Scene_Menu

  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Guardar"
    s6 = "Salir"
    @command_window = Window_Command_New.new(160, [s1, s2, s3, s4, s5, s6])
    @command_window.index = @menu_index
    @command_window.height = 225
    @command_window.x = 480
    # If number of party members is 0
    if $game_party.actors.size == 0
      # Disable items, skills, equipment, and status
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # If save is forbidden
    if $game_system.save_disabled
      # Disable save
      @command_window.disable_item(4)
    end
    # Make play time window
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = 480
    @playtime_window.y = 224
    # Make location window
    @location_window = Window_Location.new
    @location_window.x = 480
    @location_window.y = 320
    # Make gold window
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 416
    # Make status window
    @status_window = Window_MenuStatus.new
    @status_window.x = 0
    @status_window.y = 0
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @command_window.dispose
    @playtime_window.dispose
    @location_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    @playtime_window.update
    @location_window.update
    @gold_window.update
    @status_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
    # If status window is active: call update_status
    if @status_window.active
      update_status
      return
    end
  end
end

#===============================================================================
# ** Window_Command_New
#-------------------------------------------------------------------------------
# This code allows the command window in the menu to display icons.
#===============================================================================

class Window_Command_New < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader :continue
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #-----------------------------------------------------------------------------
  def initialize(index, continue)
    commands = [$data_system.words.item, $data_system.words.skill, $data_system.words.equip,
        'Status', 'Guardar', 'Salir']
    super(0, 0, 160, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    refresh
    self.index = 0
  end
  #-----------------------------------------------------------------------------
  # * Draw Item
  #-----------------------------------------------------------------------------
  def draw_item(i, color)
    self.contents.fill_rect(0, i*32, 148, 32, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon("Menu#{i}")
    opacity = (color == normal_color ? 255 : 128)
    self.contents.blt(4, 4 + i*32, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.font.color = color
    self.contents.draw_text(28, i*32, 148, 32, @commands[i])
  end
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    (0...@item_max).each {|i| draw_item(i, normal_color)}
  end
end
#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Gold < Window_Base
  #--------------------------------------------------------------------------
  # * Draw Picture
  #-------------------------------------------------------------------------- 
  def draw_picture(x, y)
    bitmap = RPG::Cache.picture("Coin")
    cw = bitmap.width
    ch = bitmap.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x, y, bitmap, src_rect)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_picture(105, 4)
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

kukusu

May 01, 2010, 11:07:33 am #7 Last Edit: May 01, 2010, 03:35:06 pm by kukusu
Oh, sure i feel lucky!
I've requested for this script everywhere and waited for months... You're nice, very nice, buddy!
I'm trying it up right now, I'll tell you if everything works OK  ;)
--------------------------------------------------------

Hi!
I tried it!
It looks perfect to me ^^ the bars are perfect, it has more features than i expected... and you even made it for thirst, not only for hunger, thank you! And the hunger script system is waaay better than others i found on the internet. I'm really pleased indeed :D

I found an issue, but maybe I am doing something wrong.
When I use an item, hunger and thirst replenish like it is supposed to do, but the item does not dissapear after use, even if its "one use only". Why?
And second, is something supposed to happen when hunger and thirst descend to 0/0? Like hp damage or something... ? I couldn't figure how to do that.

And thank you for fixing that cms! You see, I dont know anything about scripting. I just wanted a cms that showed map location, and that just looked "pretty". Cause I can't do it myself, neither can I tell if it is a good script, I depend entirely on people who can script.
But I'm glad you fix it. Hopefully I'll get less incompatibility issues from now on.


Fantasist

FZ just earned +5 Paragon points a level :D *levels up*
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




ForeverZer0

As for the item disappearing after use, make sure it is 'Consumable' in the database.
I was going to include a confiq for adding states when the player's hunger/thirst is at 0, but I kinda just rushed it out real quick to get it done for you. I'm working on something a little bigger right now, but when that is done, I will add that feature and release it in the main Scripts section of the forum. I'll let you know when I do.

Glad you like it, though. I was just gonna make your scripts compatible with the bars, but I saw all kind of improvements that could be made, so I just wrote my own real quick.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

kukusu

I made sure. I inserted it in a new project with the three parts of tons. I didnt even create any item, and i left the configuration untouched. Potion (item 1 of the database that used to dissapear after use) works but doesnt consume after use.
Thank you again, I'm sure you'll fix this little issue.

SBR*

Hmmm, I like this! Anyway, I don't really understand why you defide the steps by two everytime. Like:

$game_party.step_hunger = $game_party.steps + (Zer0::STEPS_HUNGER_DOWN / 2))

And, just wondering, where do you update $game_party.step_hunger and $game_party.step_thirst?

Level up!

-SBR*

ForeverZer0

Quote from: SBR* on May 10, 2010, 12:00:16 pm
Hmmm, I like this! Anyway, I don't really understand why you defide the steps by two everytime. Like:

$game_party.step_hunger = $game_party.steps + (Zer0::STEPS_HUNGER_DOWN / 2))

And, just wondering, where do you update $game_party.step_hunger and $game_party.step_thirst?

Level up!

-SBR*

When I was testing it, the it would decrease by 2 for every step. I think the actual step count is figured the same way. I'm not sure, I didn't look too deep into it. When I did this, the step count decreased it properly. I could be wrong, though.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

SBR*

Quote from: ForeverZero on May 12, 2010, 06:18:11 pm
Quote from: SBR* on May 10, 2010, 12:00:16 pm
Hmmm, I like this! Anyway, I don't really understand why you defide the steps by two everytime. Like:

$game_party.step_hunger = $game_party.steps + (Zer0::STEPS_HUNGER_DOWN / 2))

And, just wondering, where do you update $game_party.step_hunger and $game_party.step_thirst?

Level up!

-SBR*

When I was testing it, the it would decrease by 2 for every step. I think the actual step count is figured the same way. I'm not sure, I didn't look too deep into it. When I did this, the step count decreased it properly. I could be wrong, though.



Well, I looked deeper into it now, and this is the syntax they use to increase steps:

@steps = [@steps + 1, 9999999].min

I don't know what .min means, so I will just leave it there...

-SBR*

ForeverZer0

Just to let you know, I released the hunger script in the main forum. I would suggest using it instead of the one I posted above. It 80% the same script, but with the following changes:

  • Coding has been greatly improved over-all
  • Added automatic state-changes when hunger/thirst fall within specified ranges
  • Fixed bug with item consumption/use not taking effect
  • Added ability to get hunger/thirst by actor ID or by the actors position in the party
  • Fixed mistake I made with the stepcount (Thanks SBR*)
  • Added method of a little debugger to easily check all important stats of the system
  • Altered method to turn system ON/OFF to avoid possible error with built-in RGSS bug
  • Altered method to calculate the LVL_UP_INCREASE so that you can change the max hunger/thirst in other ways as well
  • Found another bug with Zer0 Add-Ons, this script has to go below it.

It is basically better in every way, and addresses all known bugs that were in the original, so make sure you use the new one. If you already implemented the old system deep into your game, it won't require to much altering to swap the two scripts, just a few script calls might have to be changed.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.