show variables on screen rpg maker xp
#7
No, but I'll sure try to teach you how to do it! Teach a man to fish, etc. First off, I have edited that script to be more readable. I also fixed the "Stack level too deep" error you'd get if you pushed F12. Keep in mind this won't fix it if you have other scripts that alias things dumbly.

Code:
#==============================================================================
# ** Window_YourHUD
#------------------------------------------------------------------------------
# This Window displays relavent values to the player during gameplay.
# by emeraldcyndaquil
#==============================================================================
class Window_YourHUD < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.opacity = 0
    self.contents = Bitmap.new(640 - 32, 64 - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 0, 0)
    draw_actor_sp(@actor, 200, 0)
    draw_actor_exp(@actor, 400, 0)
  end
  #--------------------------------------------------------------------------
  # * Reset Stored Variables
  #--------------------------------------------------------------------------
  def reset_variables
    @actor = $game_party.actors[0]
    @old_hp = @actor ? @actor.hp : 0
    @old_maxhp = @actor ? @actor.maxhp : 0
    @old_sp = @actor ? @actor.sp : 0
    @old_maxsp = @actor ? @actor.maxsp : 0
  end
  #---------------------------------------------------------------------------
  # * Update (called once a frame)
  #---------------------------------------------------------------------------
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  We've edited this to add a HUD
#==============================================================================
class Scene_Map
  #---------------------------------------------------------------------------
  # * Alias Listings (fixes F12 bug)
  #---------------------------------------------------------------------------
  unless method_defined?(:yourhud_main)
    alias_method(:yourhud_main, :main)
    alias_method(:yourhud_update, :update)
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @yourhud.update
    yourhud_update
  end
end

Step one, we need a way to draw the variable, so grab the draw_variable(x, y) method from my script and put in into Window_YourHUD. For it to work it has to go after the end of a method but before the def of another. So put it between
Code:
end
  #--------------------------------------------------------------------------

Now there are only three more steps! Next we want to tell the script to draw our Event Variable. So we add a call to our method, draw_variable(x, y). But where? See if you can't figure it out (HINT: look for other draw_stuff)


The next thing to do is to add our own variable to track the game's Event Variables. We do this because drawing something on-screen takes a long time and so we only want to do it if we need to (when the number changes).

Variables in ruby are made by typing a word. old_ammo would be a variable! We also have a thing called Scope, which means "who can look at my variable?" Putting an @ in front of a word means the entire class can access its value, and putting $ means the entire game can access it. So look at the reset_variables method, and add:
Code:
@old_ammo = $game_variables[WHICH_VARIABLE]
Now the whole Window_YourHUD can see the value of @old_ammo. Don't forget to change WHICH_VARIABLE to your Event Variable number.

Now we just have to modify the update method, so it can check our ammo and call refresh if it is different. The update method currently looks like
Code:
#---------------------------------------------------------------------------
  # * Update (called once a frame)
  #---------------------------------------------------------------------------
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end

Wait... what? I think we found a bug! This code says "Refresh if, oh but also set these old variables to the current value." I am assume the author mean to use == which compares two values, but even that is wrong. What we want is "Refresh if our old variables do NOT equal the current value" The current way is going to draw on every frame, which is going to cause lag. It SHOULD be
Code:
#---------------------------------------------------------------------------
  # * Update (called once a frame)
  #---------------------------------------------------------------------------
  def update
    super
    refresh if (@actor != $game_party.actors[0] or
                @old_hp != @actor ? @actor.hp : 0 or
                @old_maxhp != @actor ? @actor.maxhp : 0 or
                @old_sp != @actor ? @actor.sp : 0 or
                @old_maxsp != @actor ? @actor.maxsp : 0)
  end

Sorry, got off track... We need to add a Conditional! So it knows to refresh if our ammo changed. Can you figure out what we need to add?
Content Hidden

So now it should work!

Bonus: Maybe you want to make it say "Ammo: 12" instead of just "12"? Push CTRL+SHIFT+F in the script editor and search for "def draw_actor_hp". And then study how it is different from my draw_variable method.

Good luck!
Reply }


Messages In This Thread
RE: show variables on screen rpg maker xp - by MechanicalPen - 10-11-2014, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Scan skill should show states Tumen 5 9,211 05-02-2017, 03:33 AM
Last Post: DerVVulfman
   Display State Ranks in Status Screen Mel 3 7,412 04-02-2017, 12:46 AM
Last Post: marketing small business ideas
   RMXP SKill animations too bright (overlaying the battle screen) Starmage 4 10,152 06-13-2016, 03:41 AM
Last Post: Starmage
   Custom Save/Load screen Raou 2 7,556 04-01-2015, 08:18 PM
Last Post: Raou
   Game Variables List for Copy/Paste JayRay 4 7,000 01-15-2015, 06:18 AM
Last Post: JayRay
   in FPLE touching events after battle causes rpg maker to crash ThePrinceofMars 1 5,503 11-27-2014, 09:11 PM
Last Post: MechanicalPen
   Script Request - Variables Specific Save File JayRay 2 5,109 04-28-2014, 05:15 AM
Last Post: JayRay
   Help with Shop Menu [RPG Maker XP] JackMonty 6 12,970 05-23-2013, 10:14 AM
Last Post: JackMonty
   Analyse show HP Bars Ace 12 16,848 12-28-2010, 04:39 PM
Last Post: Ace
   Showing the evade stat in the status screen corpsegirl 2 6,281 10-25-2010, 11:40 PM
Last Post: corpsegirl



Users browsing this thread: 4 Guest(s)