I'm making a sonic rpg and would like to have a ring counter. Is there a script like this out there? if not would anyone be willing to help? I must admit that I am a complete noob at this, so I am unable to do it myself. any help would be greatly appreciated!
looking for a visual variable counter
RGSS3 Script RequestsNeed some type of info.
How are you making the rings? Is a variable? a consumable item?
Where dou you want to show?
How are you making the rings? Is a variable? a consumable item?
Where dou you want to show?
I would like it in the top left corner. I figure making it a variable with a icon for the counter would be the best (so it could be used for rings, coins, kills etc.) like this http://schestowitz.com/Interests/Screenshots/Sonic_2/sonic.jpg I want to use it to access new maps that require a certain amount of rings. sorry for all the edits, I'm using my phone at work.
Try this (no icon):
Oh yeah and to use it make a script call in an event:
add_game_variable_display(index) # index is the index of the game_variable, starting at 1.rem_game_variable_display(index)Adding an icon is very easy.
$imported ||= {}$imported[:nap_dis_var] = 0.90#===============================================================================# Configurable Section#===============================================================================module Nap module Var_Dis X = 10 Z_INDEX = 200 BG_COLOR = Color.new(0, 0, 0, 0) FONT_SIZE = 40 FONT_COLOR = Color.new(255, 255, 0) FONT_SHADOW = true FONT_BOLD = true FONT_ITALIC = false FONT_OUT_COLOR = Color.new(0, 0, 0, 128) FONT_OUTLINE = true#===============================================================================# Variable Container#=============================================================================== class Variable_Container attr_reader :index attr_accessor :sprite @@txt_measure_bmp = Bitmap.new(1,1) def self.txt_measure_bmp; @@txt_measure_bmp; end def initialize(index) #index starts at 1 @index = index @sprite = Variable_Container.create_sprite(index) @current_value = $game_variables[index] end def update return if @current_value == $game_variables[@index] @sprite.bitmap.dispose size = @@txt_measure_bmp.text_size($game_variables[@index]) @sprite.bitmap = Bitmap.new(size.width, size.height) Variable_Container.set_font(@sprite.bitmap) @sprite.bitmap.fill_rect(Rect.new(0,0,@sprite.bitmap.width,@sprite.bitmap.height), Nap::Var_Dis::BG_COLOR) @sprite.bitmap.draw_text(0,0,@sprite.bitmap.width, @sprite.bitmap.height, $game_variables[@index], 1) @current_value = $game_variables[@index]#~ puts "changed: y:#{@sprite.y} bmp: #{@sprite.bitmap.width}x#{@sprite.bitmap.height}"#~ puts @sprite.visible end def self.create_sprite(index) sprite = Sprite.new size = @@txt_measure_bmp.text_size($game_variables[index]) sprite.x = Nap::Var_Dis::X sprite.y = get_next_y sprite.z = Z_INDEX sprite.bitmap = Bitmap.new(size.width, size.height) set_font(sprite.bitmap) sprite.bitmap.fill_rect(Rect.new(0,0,sprite.bitmap.width,sprite.bitmap.height), Nap::Var_Dis::BG_COLOR) sprite.bitmap.draw_text(0,0,sprite.bitmap.width, sprite.bitmap.height, $game_variables[index], 1) return sprite end def self.set_font(bmp) bmp.font.size = Nap::Var_Dis::FONT_SIZE bmp.font.color = Nap::Var_Dis::FONT_COLOR bmp.font.bold = Nap::Var_Dis::FONT_BOLD bmp.font.italic = Nap::Var_Dis::FONT_ITALIC bmp.font.shadow = Nap::Var_Dis::FONT_SHADOW bmp.font.out_color = Nap::Var_Dis::FONT_OUT_COLOR bmp.font.outline = Nap::Var_Dis::FONT_OUTLINE end def self.get_next_y y = 0 $nap_vardis_data.each { |d| y += d.sprite.height } return y end def self.sort_y $nap_vardis_data.sort_by! { |d| d.index} end def self.reset_y y = 0 $nap_vardis_data.each { |d| d.sprite.y = y y += d.sprite.height } end def dispose @sprite.dispose end end Variable_Container.set_font(Variable_Container.txt_measure_bmp) endend$nap_vardis_data = []#===============================================================================# Scene Base#===============================================================================class Scene_Base alias nap_vardis_update update def update nap_vardis_update $nap_vardis_data.each { |d| d.update } endend#===============================================================================# Game Interpreter#===============================================================================class Game_Interpreter def add_game_variable_display(index) $nap_vardis_data << Nap::Var_Dis::Variable_Container.new(index) end def rem_game_variable_display(index) $nap_vardis_data.each{ |d| d.dispose if d.index == index} $nap_vardis_data.delete_if { |x| x.index == index} Nap::Var_Dis::Variable_Container.sort_y Nap::Var_Dis::Variable_Container.reset_y endend#===============================================================================# Saving & Loading#===============================================================================module DataManager class << self alias nap_var_dis_make_save_contents make_save_contents alias nap_var_dis_extract_save_contents extract_save_contents end def self.make_save_contents contents = nap_var_dis_make_save_contents contents = contents.merge(make_var_dis_contents) contents end def self.make_var_dis_contents contents = nap_var_dis_make_save_contents contents[:nap_var_dis] = [] $nap_vardis_data.each { |d| contents[:nap_var_dis] << d.index } contents end def self.extract_save_contents(contents) nap_var_dis_extract_save_contents(contents) extract_var_dis_contents(contents) end def self.extract_var_dis_contents(contents) contents[:nap_var_dis].each { |index| $nap_vardis_data << Nap::Var_Dis::Variable_Container.new(index) } endend
add_game_variable_display(index) # index is the index of the game_variable, starting at 1.rem_game_variable_display(index)Adding an icon is very easy.
thanks so much! this is perfect! how would I add an icon? I have zero experience with scripts...
Try this:
Code:
$imported ||= {}$imported[:nap_dis_var] = 0.91#===============================================================================# Configurable Section#===============================================================================module Nap module Var_Dis X = 10 Z_INDEX = 200 BG_COLOR = Color.new(0, 0, 0, 0) FONT_SIZE = 40 FONT_COLOR = Color.new(255, 255, 0) FONT_SHADOW = true FONT_BOLD = true FONT_ITALIC = false FONT_OUT_COLOR = Color.new(0, 0, 0, 128) FONT_OUTLINE = true#===============================================================================# Variable Container#=============================================================================== class Variable_Container attr_accessor :sprite attr_reader :index attr_reader :icon_idx @@txt_measure_bmp = Bitmap.new(1, 1) def self.txt_measure_bmp; @@txt_measure_bmp; end def initialize(index, icon_idx=nil) #index starts at 1 @index = index @sprite = Variable_Container.create_sprite(index, icon_idx) @current_value = $game_variables[index] @icon_idx = icon_idx end def update return if @current_value == $game_variables[@index] @sprite.bitmap.dispose size = Variable_Container.get_size(@index, @icon_idx) @sprite.bitmap = Bitmap.new(size.width, size.height) Variable_Container.set_font(@sprite.bitmap) @sprite.bitmap.fill_rect(Rect.new(0,0,@sprite.bitmap.width,@sprite.bitmap.height), Nap::Var_Dis::BG_COLOR) if @icon_idx draw_icon(@sprite.bitmap, @icon_idx) x = 24 align = 0 else x = 0 align = 1 end @sprite.bitmap.draw_text(x, 0, @sprite.bitmap.width, @sprite.bitmap.height, $game_variables[@index], align) @current_value = $game_variables[@index]#~ puts "changed: y:#{@sprite.y} bmp: #{@sprite.bitmap.width}x#{@sprite.bitmap.height}"#~ puts @sprite.visible end def self.get_size(index, icon_idx) if icon_idx.nil? return @@txt_measure_bmp.text_size($game_variables[index]) else s = @@txt_measure_bmp.text_size($game_variables[index]) return Rect.new(s.x, s.y, s.width + 24, s.height) end end def self.draw_icon(bitmap, icon_idx) icon_bmp = Cache.system("Iconset") rect = Rect.new(icon_idx % 16 * 24, icon_idx / 16 * 24, 24, 24) y = (bitmap.height - rect.height) / 2 y = 0 if y < 0 bitmap.blt(0, y, icon_bmp, rect) end def self.create_sprite(index, icon_idx=nil) sprite = Sprite.new size = get_size(index, icon_idx) sprite.x = Nap::Var_Dis::X sprite.y = get_next_y sprite.z = Z_INDEX sprite.bitmap = Bitmap.new(size.width, size.height) set_font(sprite.bitmap) sprite.bitmap.fill_rect(Rect.new(0,0,sprite.bitmap.width,sprite.bitmap.height), Nap::Var_Dis::BG_COLOR) if icon_idx draw_icon(sprite.bitmap, icon_idx) x = 24 align = 0 else x = 0 align = 1 end sprite.bitmap.draw_text(x, 0, sprite.bitmap.width, sprite.bitmap.height, $game_variables[index], align) return sprite end def self.set_font(bmp) bmp.font.size = Nap::Var_Dis::FONT_SIZE bmp.font.color = Nap::Var_Dis::FONT_COLOR bmp.font.bold = Nap::Var_Dis::FONT_BOLD bmp.font.italic = Nap::Var_Dis::FONT_ITALIC bmp.font.shadow = Nap::Var_Dis::FONT_SHADOW bmp.font.out_color = Nap::Var_Dis::FONT_OUT_COLOR bmp.font.outline = Nap::Var_Dis::FONT_OUTLINE end def self.get_next_y y = 0 $nap_vardis_data.each { |d| y += d.sprite.height } return y end def self.sort_y $nap_vardis_data.sort_by! { |d| d.index} end def self.reset_y y = 0 $nap_vardis_data.each { |d| d.sprite.y = y y += d.sprite.height } end def dispose @sprite.dispose end end Variable_Container.set_font(Variable_Container.txt_measure_bmp) endend$nap_vardis_data = []#===============================================================================# Scene Base#===============================================================================class Scene_Base alias nap_vardis_update update def update nap_vardis_update $nap_vardis_data.each { |d| d.update } endend#===============================================================================# Game Interpreter#===============================================================================class Game_Interpreter def add_game_variable_display(index, icon_idx=nil) $nap_vardis_data << Nap::Var_Dis::Variable_Container.new(index, icon_idx) end def rem_game_variable_display(index) $nap_vardis_data.each{ |d| d.dispose if d.index == index} $nap_vardis_data.delete_if { |x| x.index == index} Nap::Var_Dis::Variable_Container.sort_y Nap::Var_Dis::Variable_Container.reset_y endend#===============================================================================# Saving & Loading#===============================================================================module DataManager class << self alias nap_var_dis_make_save_contents make_save_contents alias nap_var_dis_extract_save_contents extract_save_contents end def self.make_save_contents contents = nap_var_dis_make_save_contents contents = contents.merge(make_var_dis_contents) contents end def self.make_var_dis_contents contents = nap_var_dis_make_save_contents contents[:nap_var_dis] = [] $nap_vardis_data.each { |d| contents[:nap_var_dis] << [d.index, d.icon_idx] } contents end def self.extract_save_contents(contents) nap_var_dis_extract_save_contents(contents) extract_var_dis_contents(contents) end def self.extract_var_dis_contents(contents) contents[:nap_var_dis].each { |index, icon_idx| $nap_vardis_data << Nap::Var_Dis::Variable_Container.new(index, icon_idx) } endend
Code:
add_game_variable_display(index, icon_idx) # index is the index of the game_variable, starting at 1. Icon_index 1 is empty for default projects.rem_game_variable_display(index)
that did wonders for the icon, but when i collect a ring now i get
"Script 'Ring counter' line 49:NoMethodError occurred.
undefined method 'draw_icon' for
#<Nap::Var_Dis::Variable_Container:0x46cdd48>"
thats "draw_icon(@sprite.bitmap, @icon_idx)"
should i have used both scripts?
"Script 'Ring counter' line 49:NoMethodError occurred.
undefined method 'draw_icon' for
#<Nap::Var_Dis::Variable_Container:0x46cdd48>"
thats "draw_icon(@sprite.bitmap, @icon_idx)"
should i have used both scripts?
Oops.
Replace line 49 with this line:
Variable_Container.draw_icon(@sprite.bitmap, @icon_idx)I created the script very quickly so it could have some issues. I also still need to refactor it.
Replace line 49 with this line:
Variable_Container.draw_icon(@sprite.bitmap, @icon_idx)I created the script very quickly so it could have some issues. I also still need to refactor it.
ok! works perfect now thanks so much! should i close this now? (first day on the site (well as a member))
Up to you. But future versions of this script will be added to my master demo (see my signature).
Alright...i'll take a look at that. and thanks, you were extremely helpful. and since the script is far enough along for my purposes id like to close this.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
Original thread: https://forums.rpgmakerweb.com/threads/looking-for-a-visual-variable-counter.22388/