[Solved] Help with formatting

Status
Not open for further replies.

Lionheart123

Veteran
Veteran
Joined
Dec 14, 2019
Messages
63
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I found this script from browsing across the forum (https://forums.rpgmakerweb.com/index.php?threads/show-enemy-hp-gauge-de-buffs.43717/).

I came across this jumbled-up code and don't know how to fix it and make it work. Can anyone help me?

#==============================================================================# Display State icons# By Lecode# Requested from BCj#----------------------# Free to use in commercial games as long as you credit me#==============================================================================module Lecode_StatesIcons #- :top or :bottom Position = :bottom Offset_X = 0 Offset_Y = 0 #- Space between icons Space = 2 #- false = show only when the battler is selected Always_Visible = true #- Icons z Z = 5 Opacity = 205 #- Show turn count ? Turn_Count= true TC_Size = 16 TC_Color = Color.new(255,255,255) #- Change text color when current turn count = TC_Warning_Turn TC_Warning_Turn = 1 TC_Warning_Color = Color.new(245,100,100) TC_Warning_Blink = true TC_Blink_Color = Color.new(255,255,255) TC_Blink_Duration = 30 #- Wait x frames before looping TC_Blink_Wait = 5 end#==============================================================================# END OF CONFIGURATION#==============================================================================class LeState_Icons def initialize(battler,sprite) @battler = battler @sprite = sprite @last_record = [] @icons = [] @turns = [] @blinking_ics = [] @blink_frame = 0 end def update return if @battler.nil? update_icons refresh_icons update_positions update_visibility update_blinks end def update_icons @icons.each { |i| i.update } @turns.each { |i| i.update } end def refresh_icons dispose_icons if @battler.dead? return if @battler.dead? return if current_record == @last_record @last_record = @battler.states dispose_icons @battler.states.each { |state| #- Icon icon = Sprite.new icon.bitmap = Bitmap.new(24,24) icon_index = state.icon_index bitmap = Cache.system("Iconset") rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24) icon.bitmap.blt(0, 0, bitmap, rect) icon.z = Lecode_StatesIcons::Z icon.opacity = Lecode_StatesIcons::opacity @icons.push(icon) #- Turn count turn_count = state_turns(state) tc_sprite = Sprite.new dum_bitmap = Bitmap.new(1,1) dum_bitmap.font.size = Lecode_StatesIcons::TC_Size rect = dum_bitmap.text_size(turn_count) tc_sprite.bitmap = Bitmap.new(rect.width+4,rect.height+4) tc_sprite.bitmap.font.size = Lecode_StatesIcons::TC_Size if turn_count == Lecode_StatesIcons::TC_Warning_Turn tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Warning_Color else tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Color end if state.auto_removal_timing == 2 tc_sprite.bitmap.draw_text(0,0,rect.width+2,rect.height+2,turn_count.to_s) end tc_sprite.z = icon.z+1 @turns.push(tc_sprite) if Lecode_StatesIcons::TC_Warning_Blink && state.auto_removal_timing == 2 start_blink(icon) if turn_count == Lecode_StatesIcons::TC_Warning_Turn end #- @last_record.push(turn_count) } @blink_frame = Lecode_StatesIcons::TC_Blink_Duration end def current_record arr = @battler.states @battler.states.each { |s| arr.push(state_turns(s)) } return arr end def start_blink(sprite) @blinking_ics.push(sprite) end def update_positions #- Icons total_width = @icons.size*(24+space) x = @battler.screen_x - total_width/2 if position == :top y = @battler.screen_y - @sprite.height - 24 else y = @battler.screen_y - 24 end x += Lecode_StatesIcons::offset_X y += Lecode_StatesIcons::offset_Y @icons.each_with_index { |ic,i| ic.x = x+i*(24+space) ic.y = y } #- Turn counts @turns.each_with_index { |ic,i| ic.x = x+i*(24+space) ic.y = y } end def update_visibility @icons.each { |i| i.visible = visible? } @turns.each { |i| i.visible = visible? } end def visible? return true if Lecode_StatesIcons::Always_Visible return false unless SceneManager.scene_is?(Scene_Battle) return false unless SceneManager.scene.enemy_window.visible return true if SceneManager.scene.enemy_window.enemy == @battler return true if SceneManager.scene.enemy_window.select_all? return false end def update_blinks color = Lecode_StatesIcons::TC_Blink_Color duration = Lecode_StatesIcons::TC_Blink_Duration wait = Lecode_StatesIcons::TC_Blink_Wait @blink_frame = [@blink_frame+1,duration+wait].min if @blink_frame == duration+wait @blink_frame = 0 @blinking_ics.each { |ic| ic.flash(color,duration) } end end def space Lecode_StatesIcons::Space end def position Lecode_StatesIcons::position end def state_turns(state) if $imported["YEA-Buff&StateManager"] return @battler.state_turns(state) end return @battler.state_turns[state.id] end def dispose_icons @icons.each { |i| i.bitmap.dispose i.dispose } @icons.clear @turns.each { |i| i.bitmap.dispose i.dispose } @turns.clear @blinking_ics.clear end endclass Sprite_Battler < Sprite_Base alias lecode_siinitialize initialize def initialize(viewport, battler = nil) lecode_siinitialize(viewport, battler) @state_icons = LeState_Icons.new(@battler,self) end alias lecode_sidispose dispose def dispose lecode_sidispose @state_icons.dispose_icons end alias lecode_siupdate update def update lecode_siupdate @state_icons.update end endclass Scene_Battle attr_reader :enemy_windowendunless $imported["YEA-Buff&StateManager"]class Game_Battler attr_reader :state_turnsendend
 
Last edited:

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
480
Reaction score
1,468
First Language
Indonesia
Primarily Uses
RMMV
Done...

Ruby:
#==============================================================================
# Display State icons
# By Lecode
#==============================================================================
module Lecode_StatesIcons
    #- :top or :bottom
    Position = :top
    Offset_X = 0
    Offset_Y = 0
    #- Space between icons
    Space = 2
    #- false = show only when the battler is selected
    Always_Visible = true
    #- Icons z
    Z = 5
    Opacity = 205
end

class LeState_Icons
    def initialize(battler,sprite)
        @battler = battler
        @sprite = sprite
        @last_record = []
        @icons = []
    end
    def update
        return if @battler.nil?
        update_icons
        refresh_icons
        update_positions
        update_visibility
    end
    def update_icons
        @icons.each { |i| i.update }
    end
    def refresh_icons
        dispose_icons if @battler.dead?
        return if @battler.dead?
        return if @battler.states == @last_record
        @last_record = @battler.states
        dispose_icons
        x = 0
        @battler.states.each { |state|
            icon = Sprite.new
            icon.bitmap = Bitmap.new(24,24)
            icon_index = state.icon_index
            bitmap = Cache.system("Iconset")
            rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
            icon.bitmap.blt(0, 0, bitmap, rect)
            icon.x = x
            icon.z = Lecode_StatesIcons::Z
            icon.opacity = Lecode_StatesIcons::opacity
            x += 24
            @icons.push(icon)
        }
    end
    def update_positions
        total_width = @icons.size*(24+space)
        x = @battler.screen_x - total_width/2
        if position == :top
            y = @battler.screen_y - @sprite.height - 24 else y = @battler.screen_y - 24
        end
        x += Lecode_StatesIcons::offset_X
        y += Lecode_StatesIcons::offset_Y
        @icons.each_with_index { |ic,i|
            ic.x = x+i*(24+space)
            ic.y = y
        }
    end
    def update_visibility
        @icons.each { |i|
            i.visible = visible?
        }
    end
    def visible?
        return true if Lecode_StatesIcons::Always_Visible
        return false unless SceneManager.scene_is?(Scene_Battle)
        return false unless SceneManager.scene.enemy_window.visible
        return true if SceneManager.scene.enemy_window.enemy == @battler
        return true if SceneManager.scene.enemy_window.select_all?
        return false
    end
    def space
        Lecode_StatesIcons::Space
    end
    def position
        Lecode_StatesIcons::position
    end
    def dispose_icons
        @icons.each { |i|
            i.bitmap.dispose
            i.dispose
        }
        @icons.clear
    end
end

class Sprite_Battler < Sprite_Base
    alias lecode_siinitialize initialize
    def initialize(viewport, battler = nil)
        lecode_siinitialize(viewport, battler)
        @state_icons = LeState_Icons.new(@battler,self)
    end
    alias lecode_sidispose dispose
    def dispose lecode_sidispose
        @state_icons.dispose_icons
    end
    alias lecode_siupdate update
    def update lecode_siupdate
        @state_icons.update
    end
end

class Scene_Battle
    attr_reader :enemy_window
end
I'm still a bit unsure tho...
 
Last edited:

Lionheart123

Veteran
Veteran
Joined
Dec 14, 2019
Messages
63
Reaction score
1
First Language
English
Primarily Uses
RMVXA
umm... I meant the code I mentioned in my post.... Sorry if I'm a bit unclear...
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
480
Reaction score
1,468
First Language
Indonesia
Primarily Uses
RMMV
That's the jumbled code you mentioned in your post.
 

Lionheart123

Veteran
Veteran
Joined
Dec 14, 2019
Messages
63
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I must've edited it before I knew that someone is already working on it...... Sorry!!)
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
480
Reaction score
1,468
First Language
Indonesia
Primarily Uses
RMMV
Oooh... it's indeed different.
okay, done...


Ruby:
#==============================================================================
# Display State icons
# By Lecode
# Requested from BCj
#----------------------
# Free to use in commercial games as long as you credit me
#==============================================================================
module Lecode_StatesIcons
    #- :top or :bottom
    Position = :bottom Offset_X = 0
    Offset_Y = 0
    #- Space between icons
    Space = 2
    #- false = show only when the battler is selected
    Always_Visible = true
    #- Icons z
    Z = 5
    Opacity = 205
    #- Show turn count ?
    Turn_Count = true
    TC_Size = 16
    TC_Color = Color.new(255,255,255)
    #- Change text color when current turn count = TC_Warning_Turn
    TC_Warning_Turn = 1
    TC_Warning_Color = Color.new(245,100,100)
    TC_Warning_Blink = true
    TC_Blink_Color = Color.new(255,255,255)
    TC_Blink_Duration = 30
    #- Wait x frames before looping
    TC_Blink_Wait = 5
end
#==============================================================================
# END OF CONFIGURATION
#==============================================================================

class LeState_Icons
    def initialize(battler,sprite)
        @battler = battler
        @sprite = sprite
        @last_record = []
        @icons = []
        @turns = []
        @blinking_ics = []
        @blink_frame = 0
    end
    def update
        return if @battler.nil?
        update_icons
        refresh_icons
        update_positions
        update_visibility
        update_blinks
    end
    def update_icons
        @icons.each { |i| i.update }
        @turns.each { |i| i.update }
    end
    def refresh_icons
        dispose_icons if @battler.dead?
        return if @battler.dead?
        return if current_record == @last_record
        @last_record = @battler.states
        dispose_icons
        @battler.states.each { |state|
            #- Icon
            icon = Sprite.new
            icon.bitmap = Bitmap.new(24,24)
            icon_index = state.icon_index
            bitmap = Cache.system("Iconset")
            rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
            icon.bitmap.blt(0, 0, bitmap, rect)
            icon.z = Lecode_StatesIcons::Z
            icon.opacity = Lecode_StatesIcons::opacity
            @icons.push(icon)
            #- Turn count
            turn_count = state_turns(state)
            tc_sprite = Sprite.new
            dum_bitmap = Bitmap.new(1,1)
            dum_bitmap.font.size = Lecode_StatesIcons::TC_Size
            rect = dum_bitmap.text_size(turn_count)
            tc_sprite.bitmap = Bitmap.new(rect.width+4,rect.height+4)
            tc_sprite.bitmap.font.size = Lecode_StatesIcons::TC_Size
            if turn_count == Lecode_StatesIcons::TC_Warning_Turn
                tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Warning_Color
            else
                tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Color
            end
            if state.auto_removal_timing == 2
                tc_sprite.bitmap.draw_text(0,0,rect.width+2,rect.height+2,turn_count.to_s)
            end
            tc_sprite.z = icon.z+1
            @turns.push(tc_sprite)
            if Lecode_StatesIcons::TC_Warning_Blink && state.auto_removal_timing == 2
                start_blink(icon) if turn_count == Lecode_StatesIcons::TC_Warning_Turn
            end
            #- @last_record.push(turn_count)
        }
        @blink_frame = Lecode_StatesIcons::TC_Blink_Duration
    end
    def current_record
        arr = @battler.states
        @battler.states.each { |s|
            arr.push(state_turns(s))
        }
        return arr
    end
    def start_blink(sprite)
        @blinking_ics.push(sprite)
    end
    def update_positions
        #- Icons
        total_width = @icons.size*(24+space)
        x = @battler.screen_x - total_width/2
        if position == :top
            y = @battler.screen_y - @sprite.height - 24
        else
            y = @battler.screen_y - 24
        end
        x += Lecode_StatesIcons::offset_X
        y += Lecode_StatesIcons::offset_Y
        @icons.each_with_index { |ic,i|
            ic.x = x+i*(24+space)
            ic.y = y
        }
        #- Turn counts
        @turns.each_with_index { |ic,i|
            ic.x = x+i*(24+space)
            ic.y = y
        }
    end
    def update_visibility
        @icons.each { |i|
        i.visible = visible?
    }
    @turns.each { |i|
        i.visible = visible?
    }
    end
    def visible?
        return true if Lecode_StatesIcons::Always_Visible
        return false unless SceneManager.scene_is?(Scene_Battle)
        return false unless SceneManager.scene.enemy_window.visible
        return true if SceneManager.scene.enemy_window.enemy == @battler
        return true if SceneManager.scene.enemy_window.select_all?
        return false
    end
    def update_blinks
        color = Lecode_StatesIcons::TC_Blink_Color
        duration = Lecode_StatesIcons::TC_Blink_Duration
        wait = Lecode_StatesIcons::TC_Blink_Wait
        @blink_frame = [@blink_frame+1,duration+wait].min
        if @blink_frame == duration+wait
            @blink_frame = 0
            @blinking_ics.each { |ic|
                ic.flash(color,duration)
            }
        end
    end
    def space
        Lecode_StatesIcons::Space
    end
    def position
        Lecode_StatesIcons::position
    end
    def state_turns(state)
        if $imported["YEA-Buff&StateManager"]
            return @battler.state_turns(state)
        end
        return @battler.state_turns[state.id]
    end
    def dispose_icons
        @icons.each { |i|
            i.bitmap.dispose
            i.dispose
        }
        @icons.clear
        @turns.each { |i|
            i.bitmap.dispose
            i.dispose
        }
        @turns.clear
        @blinking_ics.clear
    end
end

class Sprite_Battler < Sprite_Base
    alias lecode_siinitialize initialize
    def initialize(viewport, battler = nil)
        lecode_siinitialize(viewport, battler)
        @state_icons = LeState_Icons.new(@battler,self)
    end
    alias lecode_sidispose dispose
    def dispose
        lecode_sidispose
        @state_icons.dispose_icons
    end
    alias lecode_siupdate update
    def update
        lecode_siupdate
        @state_icons.update
    end
end

class Scene_Battle
    attr_reader :enemy_windowendunless
    $imported["YEA-Buff&StateManager"]

    class Game_Battler
        attr_reader :state_turns
    end

end
It's kind of confusing since it doesn't use semicolons. Also there are part which I'm not sure was it supposed to be a comment or not. So I can't guarantee.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,672
Reaction score
566
First Language
English
Primarily Uses
RMVXA
okay, done.
I think it is a little off
Ruby:
#==============================================================================
# Display State icons
# By Lecode
# Requested from BCj
#----------------------
# Free to use in commercial games as long as you credit me
#==============================================================================
module Lecode_StatesIcons 
    #- :top or :bottom 
    Position = :bottom 
    Offset_X = 0 
    Offset_Y = 0 
    #- Space between icons 
    Space = 2 
    #- false = show only when the battler is selected 
    Always_Visible = true
    #- Icons z 
    Z = 5 
    Opacity = 205 
    #- Show turn count ? 
    Turn_Count= true 
    TC_Size = 16 
    TC_Color = Color.new(255,255,255) 
    #- Change text color when current turn count = TC_Warning_Turn 
    TC_Warning_Turn = 1 
    TC_Warning_Color = Color.new(245,100,100) 
    TC_Warning_Blink = true 
    TC_Blink_Color = Color.new(255,255,255) 
    TC_Blink_Duration = 30 
    #- Wait x frames before looping 
    TC_Blink_Wait = 5 
end
#==============================================================================
# END OF CONFIGURATION
#==============================================================================
class LeState_Icons 
    def initialize(battler,sprite) 
        @battler = battler 
        @sprite = sprite 
        @last_record = [] 
        @icons = [] 
        @turns = [] 
        @blinking_ics = [] 
        @blink_frame = 0 
    end 
    def update 
        return if @battler.nil? 
        update_icons 
        refresh_icons 
        update_positions 
        update_visibility 
        update_blinks 
    end 
    def update_icons 
        @icons.each { |i| i.update }
        @turns.each { |i| i.update } 
    end 
    def refresh_icons 
        dispose_icons if @battler.dead? 
        return if @battler.dead? 
        return if current_record == @last_record 
        @last_record = @battler.states 
        dispose_icons 
        @battler.states.each { |state| 
            #- Icon 
            icon = Sprite.new 
            icon.bitmap = Bitmap.new(24,24) 
            icon_index = state.icon_index 
            bitmap = Cache.system("Iconset") 
            rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24) 
            icon.bitmap.blt(0, 0, bitmap, rect) 
            icon.z = Lecode_StatesIcons::Z 
            icon.opacity = Lecode_StatesIcons::opacity 
            @icons.push(icon) 
            #- Turn count 
            turn_count = state_turns(state) 
            tc_sprite = Sprite.new 
            dum_bitmap = Bitmap.new(1,1) 
            dum_bitmap.font.size = Lecode_StatesIcons::TC_Size 
            rect = dum_bitmap.text_size(turn_count) 
            tc_sprite.bitmap = Bitmap.new(rect.width+4,rect.height+4) 
            tc_sprite.bitmap.font.size = Lecode_StatesIcons::TC_Size 
            if turn_count == Lecode_StatesIcons::TC_Warning_Turn 
                tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Warning_Color 
            else 
                tc_sprite.bitmap.font.color = Lecode_StatesIcons::TC_Color 
            end 
            if state.auto_removal_timing == 2 
                tc_sprite.bitmap.draw_text(0,0,rect.width+2,rect.height+2,turn_count.to_s) 
            end 
            tc_sprite.z = icon.z+1 
            @turns.push(tc_sprite) 
            if Lecode_StatesIcons::TC_Warning_Blink && state.auto_removal_timing == 2 
                start_blink(icon) if turn_count == Lecode_StatesIcons::TC_Warning_Turn 
            end 
            #- @last_record.push(turn_count) 
            } 
        @blink_frame = Lecode_StatesIcons::TC_Blink_Duration
    end 
    def current_record 
        arr = @battler.states 
        @battler.states.each { |s| arr.push(state_turns(s)) } 
        return arr 
    end 
    def start_blink(sprite) 
        @blinking_ics.push(sprite) 
    end 
    def update_positions 
        #- Icons 
        total_width = @icons.size*(24+space) 
        x = @battler.screen_x - total_width/2 
        if position == :top 
            y = @battler.screen_y - @sprite.height - 24 
        else 
            y = @battler.screen_y - 24 
        end 
        x += Lecode_StatesIcons::Offset_X 
        y += Lecode_StatesIcons::Offset_Y 
        @icons.each_with_index { |ic,i| 
        ic.x = x+i*(24+space) 
        ic.y = y 
        } 
        #- Turn counts 
        @turns.each_with_index { |ic,i| 
        ic.x = x+i*(24+space) 
        ic.y = y 
        } 
    end 
    def update_visibility 
        @icons.each { |i| i.visible = visible? } 
        @turns.each { |i| i.visible = visible? } 
    end 
    def visible? 
        return true if Lecode_StatesIcons::Always_Visible 
        return false unless SceneManager.scene_is?(Scene_Battle) 
        return false unless SceneManager.scene.enemy_window.visible 
        return true if SceneManager.scene.enemy_window.enemy == @battler 
        return true if SceneManager.scene.enemy_window.select_all? 
        return false 
    end 
    def update_blinks 
        color = Lecode_StatesIcons::TC_Blink_Color 
        duration = Lecode_StatesIcons::TC_Blink_Duration 
        wait = Lecode_StatesIcons::TC_Blink_Wait 
        @blink_frame = [@blink_frame+1,duration+wait].min 
        if @blink_frame == duration+wait 
            @blink_frame = 0 
            @blinking_ics.each { |ic| ic.flash(color,duration) } 
        end
    end 
    def space 
        Lecode_StatesIcons::Space 
    end 
    def position 
        Lecode_StatesIcons::Position 
    end 
    def state_turns(state) 
        if $imported["YEA-Buff&StateManager"] 
            return @battler.state_turns(state) 
        end 
        return @battler.state_turns[state.id] 
    end 
    def dispose_icons 
    @icons.each { |i| 
        i.bitmap.dispose 
        i.dispose 
        } 
        @icons.clear 
        @turns.each { |i| 
        i.bitmap.dispose 
        i.dispose 
        } 
        @turns.clear 
        @blinking_ics.clear 
    end 
end

class Sprite_Battler < Sprite_Base 
    alias lecode_siinitialize initialize 
    def initialize(viewport, battler = nil) 
        lecode_siinitialize(viewport, battler) 
        @state_icons = LeState_Icons.new(@battler,self) 
    end 
    alias lecode_sidispose dispose 
    def dispose 
        lecode_sidispose 
        @state_icons.dispose_icons 
    end 
    alias lecode_siupdate update 
    def update 
        lecode_siupdate 
        @state_icons.update 
    end 
end

class Scene_Battle 
    attr_reader :enemy_window
end
unless $imported["YEA-Buff&StateManager"]
    class Game_Battler 
    attr_reader :state_turns
    end
end
I tested it and there are no errors now.
 

Lionheart123

Veteran
Veteran
Joined
Dec 14, 2019
Messages
63
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Okay! Thanks to all of you!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,862
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,358
Members
137,803
Latest member
andrewcole
Top