10-11-2014, 05:49 PM
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.
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
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: 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
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
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?
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!
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 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!