class Window_HUD < Window_Base #------------------------------------------------------------------ # * Display a HUD(Heads Up Display) #------------------------------------------------------------------ attr_accessor :actor def initialize super(0, 0, -110, -96) self.contents = Bitmap.new(width - 32, height - 32)
# Don't show this window by default self.visable = false
# Make the window semi transparent so the player can see behind it self.opacity = 240
# Get the first actor in the party to display their data @actor = $game_party.actors[0] # Display charater HP @hp = @actor.hp # Display Character SP @sp = @actor.sp # Current number of gold @coins = $game_variables[1]
refresh end
# Clear the window and redraw it def refresh self.contents.clear
# Draw HP icon on the window bitmap = RPG::Cache.icon('hp') self.contents.blt(0, 4, bitmap, Rect.new(0, 0, 24, 24))
# Draw the actual HP of the character self.contents.draw_text(32, 0, 96, 32, @hp.to_s)
# Draw the actual SP of the charcter self.contents.draw_text(64, 0, 194, 64, @sp.to_s)
#Draw the coin icon on the window bitmap = RPG::Cache.icon('coins') self.contents.blt(0, 4, bitmap, Rect.new(0, 0, 24, 24)) # draw the variable holding the number of coins self.contents.draw_text(32, 32, 96, 32, @coins.to_s) end end
# Run each and every frame def update # HUD is only visable when this switch is on self.visable = $game_switches[1]
# Don't update if we can't see the window. Prevents lag. if !self.visable return end
# Only refresh if something has changed. Prevents lag. if (@hp != @actor.hp) or (@coins != @game_variables[1]) # Current HP of Actor @hp = @actor.hp # Current number of coins @coins = @game_variables[1]
refresh end
# Do everything the parent window needs to do each frame super 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 # 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 @hud_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 #-------------------------------------------------------------------------- # * Battle Call #-------------------------------------------------------------------------- def call_battle # Clear battle calling flag $game_temp.battle_calling = false # Clear menu calling flag $game_temp.menu_calling = false $game_temp.menu_beep = false # Make encounter count $game_player.make_encounter_count # Memorize map BGM and stop BGM $game_temp.map_bgm = $game_system.playing_bgm $game_system.bgm_stop # Play battle start SE $game_system.se_play($data_system.battle_start_se) # Play battle BGM $game_system.bgm_play($game_system.battle_bgm) # Straighten player position $game_player.straighten # Switch to battle screen $scene = Scene_Battle.new end #-------------------------------------------------------------------------- # * Shop Call #-------------------------------------------------------------------------- def call_shop # Clear shop call flag $game_temp.shop_calling = false # Straighten player position $game_player.straighten # Switch to shop screen $scene = Scene_Shop.new end #-------------------------------------------------------------------------- # * Name Input Call #-------------------------------------------------------------------------- def call_name # Clear name input call flag $game_temp.name_calling = false # Straighten player position $game_player.straighten # Switch to name input screen $scene = Scene_Name.new end #-------------------------------------------------------------------------- # * Menu Call #-------------------------------------------------------------------------- def call_menu # Clear menu call flag $game_temp.menu_calling = false # If menu beep flag is set if $game_temp.menu_beep # Play decision SE $game_system.se_play($data_system.decision_se) # Clear menu beep flag $game_temp.menu_beep = false end # Straighten player position $game_player.straighten # Switch to menu screen $scene = Scene_Menu.new end #-------------------------------------------------------------------------- # * Save Call #-------------------------------------------------------------------------- def call_save # Straighten player position $game_player.straighten # Switch to save screen $scene = Scene_Save.new end #-------------------------------------------------------------------------- # * Debug Call #-------------------------------------------------------------------------- def call_debug # Clear debug call flag $game_temp.debug_calling = false # Play decision SE $game_system.se_play($data_system.decision_se) # Straighten player position $game_player.straighten # Switch to debug screen $scene = Scene_Debug.new end #-------------------------------------------------------------------------- # * Player Place Move #-------------------------------------------------------------------------- def transfer_player # Clear player place move call flag $game_temp.player_transferring = false # If move destination is different than current map if $game_map.map_id != $game_temp.player_new_map_id # Set up a new map $game_map.setup($game_temp.player_new_map_id) end # Set up player position $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y) # Set player direction case $game_temp.player_new_direction when 2 # down $game_player.turn_down when 4 # left $game_player.turn_left when 6 # right $game_player.turn_right when 8 # up $game_player.turn_up end # Straighten player position $game_player.straighten # Update map (run parallel process event) $game_map.update # Remake sprite set @spriteset.dispose @spriteset = Spriteset_Map.new # If processing transition if $game_temp.transition_processing # Clear transition processing flag $game_temp.transition_processing = false # Execute transition Graphics.transition(20) end # Run automatic change for BGM and BGS set on the map $game_map.autoplay # Frame reset Graphics.frame_reset # Update input information Input.update end end
Group: +Gold Member
Posts: 1,007
Type: Scripter
RM Skill: Undisclosed
CODE
super(0, 0, -110, -96)
Why is this negative?
CODE
self.visable = false
You spelt 'visible' wrong ^^
CODE
self.visable = $game_switches[1]
Spelt 'visible' wrong again. Also, $game_switches[1] has to be equal to 'true' or 'false' else you will get an error. Like, you can still use it, but you will have to set the value with a Call Script Command.
As for Scene_Map: Make sure you define @hud_window to equal Window_HUD.new in def main. You didn't post your main method here, so I am just making sure. If you forgot to define it, when the windows are updated @hud_window.update will try to update @hud_window, but since the window was not defined you will error.
This post has been edited by Synthesize: Jan 21 2008, 03:26 PM
hehe thanks, works...near perfectly now. My major issue is that the gold icon collides with HP and the SP doesn't fit on the screen...again, how do I replace the window with a picture?
As you can see...I've gone wrong somewhere....
This post has been edited by Jadak: Jan 21 2008, 07:50 PM
These lines are the reason why your icons are overlapping. You are drawing both icons in the exact same spot. In order to draw a picture, you would do it the exact same way as you are drawing your icons, except you would replace .icon with .picture.
Also, $game_switches[1] has to be equal to 'true' or 'false' else you will get an error. Like, you can still use it, but you will have to set the value with a Call Script Command.
Not true. In Ruby, anything that is not false or nil is true. All switches begin as nil, so are false. Therefore, anything can be evaluated for truth value, even if it hasn't been assigned a value.
To increase the size of your window, change this line (which you've presumably changed once already):
super(0, 0, -110, -96)
That's the x coordinate of the window, the y coordinate, the width, and the height, respectively. To make the window wider, make the third number larger.
Group: Revolutionary
Posts: 188
Type: Artist
RM Skill: Beginner
QUOTE (ccoa @ Jan 19 2008, 04:24 PM)
Aha!
Ruby is case sensitive. Window_Hud and Window_HUD are two different things, as far as it's concerned. You either need to rename your class Window_HUD or change the line in Scene_Map to Window_Hud.
thanks <3 new error ;.;
edit - no wait, it was a line 19 error >.>; in Window_Hud
@coins = Game_Variables[1]
nevermind >.> more case issues
This post has been edited by Heavyblues: Jan 22 2008, 02:13 PM
Very nice, darkyros. For how to add items, I'd check out Window_Item. The relevent parts are:
CODE
@data = [] # Add item for i in 1...$data_items.size if $game_party.item_number(i) > 0 @data.push($data_items[i]) end end # Also add weapons and items if outside of battle unless $game_temp.in_battle for i in 1...$data_weapons.size if $game_party.weapon_number(i) > 0 @data.push($data_weapons[i]) end end for i in 1...$data_armors.size if $game_party.armor_number(i) > 0 @data.push($data_armors[i]) end end end
and
CODE
def draw_item(index) item = @data[index] case item when RPG::Item number = $game_party.item_number(item.id) when RPG::Weapon number = $game_party.weapon_number(item.id) when RPG::Armor number = $game_party.armor_number(item.id) end if item.is_a?(RPG::Item) and $game_party.item_can_use?(item.id) self.contents.font.color = normal_color else self.contents.font.color = disabled_color end x = 4 + index % 2 * (288 + 32) y = index / 2 * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 240, y, 16, 32, ":", 1) self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2) end
If you have any questions about it, feel free to ask here or PM me.
# don't show this window by default self.visible = false
# make the window semi-transparent so the player can see what's behind it self.opacity = 160
#get the first actor in the party to display their data @actor = $game_party.actors[0] #current hp of actor @hp = @actor_hp #current number of coins @coins = $game_variables[1]
refresh end
#clear the window and redraw it def refresh self.contents.clear
#draw the hp icon on the window bitmap = RPG::Cache.icon('Rank 1') self.contents.blt(0, 4, bitmap, Rect.new(0, 0, 24, 24))
#draw the actual hp of the actor self.contents.draw_text(32, 0, 96, 32, @hp.to_s)
#draw the coin icon on the window bitmap = RPG::Cache.icon('Rank 2') self.contents.blt(0, 40, bitmap, Rect.new(0, 0, 24, 24))
# draw the variable holding the number of coins self.contents.draw_text(0, 0, 96, 32, @coins.to_s)
end
# run each and every frame def update
# we're only visible if this switch is on self.visible = $game_switches[1]
# don't update if we can't see the window. Prevents lag. if !self.visible return end # only refresh if something has changed. Prevents lag. if (@hp != @actor.hp) or (@coins != $game_variables[1]) # current hp of actor @hp = @actor.hp # current number of coins @coins = $game_variables[1]
refresh end
# do anything the parent windows need to do each frame super end end
This post has been edited by Ulmarion: Feb 2 2008, 05:35 PM
If your text isn't displaying, the most likely problem is that you're using Postality or some other crack of the Japanese program. The solution is to get the English version.
Group: Member
Posts: 3
Type: Scripter
RM Skill: Beginner
Well, here's my entry. (Yay, my first post! ) HUD_0011.jpg ( 169.33K )
Number of downloads: 24
Here's my script.
CODE
#====================================================================== ========= # Window_HUD by KyoRen aka Yannmas # The first useful script that I've made! #------------------------------------------------------------------------------- # This script shows a HUD (Heads-Up Display) while on the map. # It shows: # Actor's name, # Actor's HP/MaxHP, # Actor's SP/MaxHP, # Actor's EXP/NextEXP, # Actor's level, # Actor's sprite, # And the party's gold. #------------------------------------------------------------------------------- # Thanks to ccoa for the lesson. #===============================================================================
class Window_HUD < Window_Base
attr_accessor :actor
def initialize # super(x, y, width, height) super (0, 0, 160, 124) self.contents = Bitmap.new(width - 32, height - 32) # Is the HUD visible at the start? self.visible = true # The opacity of the HUD self.opacity = 160
# Switch to turn the HUD on/off @hud_switch = 1 # Variable ID for the HUD @hud_variable = 1 # This is so that you can change which party member your looking at @hud_system = $game_variables[@hud_variable] # Member's data @actor = $game_party.actors[@hud_system] # Member's name @name = @actor.name # Member's current HP @hp = @actor.hp # Member's Max HP @maxhp = @actor.maxhp # Member's current SP @sp = @actor.sp # Member's Max SP @maxsp = @actor.maxsp # Member's current exp @exp = @actor.exp # EXP required for the next level @nexp = $game_party.actors[@hud_system].next_exp_s # Member's current level @level = @actor.level # Party's current gold @gold = $game_party.gold # Actor sprite @actor_sprite = $game_party.actors[@hud_system] refresh end
# Clears the window and draws the information def refresh self.contents.clear
# Draws the name of the member. draw_text(x, y, width, height, text) text = "text" + @.to_s self.contents.draw_text(53, 2, 75, 25, @name.to_s) # Draws the number of HPs self.contents.draw_text(70, 20, 55, 25, "HP: " + @hp.to_s + "/" + @maxhp.to_s) # Draws the number of SPs self.contents.draw_text(70, 33, 55, 25, "SP: " + @sp.to_s + "/" + @maxsp.to_s) # Draws the number of EXP points self.contents.draw_text(70, 46, 55, 25, "EXP: " + @exp.to_s + "/" + @nexp) # Draws the actor's level self.contents.draw_text(70, 59, 55, 25, "LVL: " + @level.to_s) # Draws the party's gold self.contents.draw_text(53, 72, 55, 25, "Gold: " + @gold.to_s) # Draws the actor's sprite draw_actor_graphic(@actor_sprite, 20, 50) end
# Runs each frame def update # Updates only if something has changed. Prevents lag. if (@hp != @actor.hp) or (@sp != @actor.sp) or (@exp != @actor.exp) or (@level != @actor.level) or (@gold != $game_party.gold) # Member's name @name = @actor.name # Member's current HP @hp = @actor.hp # Member's current Max HP @maxhp = @actor.maxhp # Member's current SP @sp = @actor.sp # Member's current Max SP @maxsp = @actor.maxsp # Member's current exp @exp = @actor.exp # EXP required for next level @nexp = $game_party.actors[@hud_system].next_exp_s # Member's current level @level = @actor.level # Party's current gold @gold = $game_party.gold # Actor's Sprite @actor_sprite = $game_party.actors[@hud_variable] refresh end
# Does all that the "parent" class has to each frame super end
end
Hey ccoa, I was wondering, I'd like to know how to make it so that when a specific button is pressed, the HUD will change to the next/previous member in the party? I looked through the script that is there at the start and thought that this:
CODE
# Pressing R cycles forward if Input.trigger?(Input::R) if @actor == 1 if $game_party.actors[1] = nil return else @actor = 2 refresh end if @actor == 2 if $game_party.actors[2] = nil return else @actor = 3 refresh end if @actor == 3 if $game_party.actors[3] = nil return else @actor = 4 refresh end if @actor == 4 if $game_party.actors[0] = nil return else @actor = 1 refresh end
# Pressing L cycles backwards if Input.trigger?(Input::L) if @actor == 1 if $game_party.actors[3] = nil return else @actor = 4 refresh end if @actor == 2 if $game_party.actors[0] = nil return else @actor = 1 refresh end if @actor == 3 if $game_party.actors[1] = nil return else @actor = 2 refresh end if @actor == 4 if $game_party.actors[2] = nil return else @actor = 3 refresh end
This is all I can think of, but it doesn't work. An error comes up saying there was a SyntaxError on the very last "end" of the script.
Group: +Gold Member
Posts: 1,007
Type: Scripter
RM Skill: Undisclosed
@KyoRen: You are missing a bunch of 'end's in your code, the reason you get a syntax error on 'end.' Each of the if branches you have needs their own end. Since I am not good at explaining, below is an example:
CODE
if case? p "I have a suitcase!" end
A typical IF branch.
CODE
if case? p "I have a suitcase!" else p "I don't have a suitcase." end
Typical IF branch with an else branch.
CODE
if case? if dash p "I have suitcase while I dash!" end else p "I do not have a case" end
Notice how each if has its own end for the branch. However, we can simplify the above with this:
CODE
if case? and dash p "I have a suitcase while I dash" else p "I do not have a case" end
In the above example, we are checking case? AND dash in the same if branch. This checks if case? and dash is true, if both are true then print "I have a suitcase while I dash" but if one is false, even if the other is true, print "I do not have a case"
CODE
if case? p "I have a case!" elsif dash == false p "I am not dashing, nor do I have a case" end
The above example is an elsif. It allows you to create an if branch when the previous condition is not meant without creating another if branch. Since it is apart of the original if, you do not need additional ends. So in this case, if case is false and dash is false then print "I am not dashing, nor do I have a case."
Group: Member
Posts: 3
Type: Scripter
RM Skill: Beginner
Ah yes, so simple that I can't believe I missed that. Well, I've figured out a lot about the RGSS now, perhaps I can tackle something bigger than windows...
Group: Member
Posts: 2
Type: None
RM Skill: Undisclosed
Hey, I just started to script and I need to thank you for these tutorials. But I run already in a problem -.-'' I wrote that script of yours just a like and when I try to test that in actual game it says something about syntaxerror. Like: Window_HUD 30 SyntaxError. Any clue what the heck that means? I thought it would mean I have writen something wrong in the 30th line but it's same as yours...help...
I tried to aply this to vx, it does work a little but I can't get any var. nummer in there, also not any icon or pic...could anyone help me or direct me to an other form where i can learn that?
For the past couple of months I've been learning RGSS and I've got the basic stuff down such windows, variables, conditional statements, ect. But, I can't see myself making big scripts such as a jumping system or a side view battle system. I was wondering how you learned to script because I really want to know how to script really well.
Thanks in advance.
Hey there,
Well I don't make battle neither though I can still teach you some things :)... The way I've learned to script is by reading other scripts for the most part. I've allways been interested in other peoples work but this time I though I had to try to make something myself...and it worked!! The most importand thing when you go scripting is (at least in my case) that you want to make something to help an other wich can't script. You also need to feel the competition that's around in the scripting-community. Cause, I have to say, if you get pushed to get a sertain request done before an other scripter does, you feel POWERFULL!! :P So that's an other thing... You also don't need to be afraid to learn from others or helpfiles. When I write my scripts, I actualy always have the helpfiles open to look things up I don't know or remember. Then, you must be calm, cause you need to try the script a lot of times. When I write a script, I test it after almost every changes. First I set up the major structure. Like when I make a window-script or part of a script I start with something like this:
CODE
class Window_Name < Window_Base def initialize(x,y,width,height) super(x,y,width,height) refresh end
def refresh self.contents.clear draw_contents end
def draw_contents draw_something(with, some, parameters) end
def update refresh if @something != @what_it_should_be end end
So that's also very important. Then, the biggest thing I learned scripting from is TRIAL AND ERROR. That's the most irritating way to learn something, cause it's more ERROR than TRIAL, but it does the trick realy good.
So that's it how I did it. Now it's up to you. Do some requests (if I didn't do it allready :P) and learn from them.
Hope that helped you out a little. If not, keep your eye on the Scriptology-topic (see my sig) where I'll be updating for my scripting(video)tutorials. Perhaps they're going to be usefull for you one day ;)
Group: Member
Posts: 54
Type: None
RM Skill: Beginner
Great tutorial but is it compatible at all with VX?
I'm no scripter (nor am I good with graphics yet!) so if there are any changes that have to be made I'll probably get lost
If it's too hard to change, is there anything similar to this for VX? Also, is there a way that I could find a HUD like the one you've used which I could use with Moghunter's Location Name VX script?
Sorry if this isn't possible and I've just wasted valuable post space but I was just wondering!