Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Tiamat5774 on October 24, 2014, 11:24:29 pm

Title: Enemy stat block (needed for visual for playtesting)
Post by: Tiamat5774 on October 24, 2014, 11:24:29 pm
I'm just learning about scripting so my knowledge is limited.  I need help with editing (altering) this script  The script shows the enemy's Hp but would like to also see the sp, str, dex, int, agil, mdef, and pdef of the enemy as well.  I'm trying to event a level up system for the enemies and I need something visual DURING the battles to see if my events are working.  I know there are monster adaption/difficulty/level up scripts out there, but they don't work the way I want them to.  Should be able to create an event that will do the same thing.  I just need to see the event's workings in detail as I test play.

Spoiler: ShowHide


class Window_EnemyHP < Window_Base
 
 def initialize
   super(0, 0, 640, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.opacity = 0
   @old_hp = []
   refresh
 end
 
 def refresh
   self.contents.clear
   for i in 0...$game_troop.enemies.size
     @enemy = $game_troop.enemies[i]
     @old_hp[i] = @enemy.hp
     unless @enemy.hp == 0
       self.contents.font.size = 15
       self.contents.font.bold = true
       self.contents.font.color = Color.new(0,0,0)
       self.contents.font.color = normal_color
       self.contents.draw_text(0, i * 45 + 37, 100, 32, @enemy.name)
       draw_actor_hp(@enemy, 0, i*45 + 50)
     end
   end
 end
 def update
   for i in 0...$game_troop.enemies.size
     enemy = $game_troop.enemies[i]
     if enemy.hp != @old_hp[i]
       refresh
     end
   end
 end
end

class Scene_Battle
 
 alias raz_update_phase5 update_phase5
 alias raz_update_phase4_step1 update_phase4_step1
 alias raz_update_phase4_step5 update_phase4_step5
 alias raz_enemy_hp_main main
 
  def main
   @troop_id = $game_temp.battle_troop_id
   $game_troop.setup(@troop_id)
   @enemy_window = Window_EnemyHP.new
   @enemy_window.z = 95
   raz_enemy_hp_main
   @enemy_window.dispose
 end
 
 def update_phase5
   # If wait count is larger than 0
   if @phase5_wait_count > 0
     # Decrease wait count
     @phase5_wait_count -= 1
     # If wait count reaches 0
     if @phase5_wait_count == 0
       @enemy_window.visible = false
       # Show result window
       @result_window.visible = true
       # Clear main phase flag
       $game_temp.battle_main_phase = false
       # Refresh status window
       @status_window.refresh
       @enemy_window.refresh
     end
     return
   end
  raz_update_phase5
end

def update_phase4_step1
 raz_update_phase4_step1
 @enemy_window.refresh
end

 def update_phase4_step5
   # Hide help window
   @help_window.visible = false
   # Refresh status window
   @status_window.refresh
   @enemy_window.refresh
   raz_update_phase4_step5
 end
end



this script works with the scripts I have, as is.  However, I'm requesting help in modifying the script to do what I need or for some one with more know-how to modify it for me.
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: Tiamat5774 on November 19, 2014, 12:22:30 am
Is there any other info I need to add to this or is it that no one is interested in helping?
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: Heretic86 on November 19, 2014, 08:31:38 am
People are interested, but this site isnt that active.

All the data youre looking for is already in the @enemy Object.  For example @enemy.hp so you can use @enemy to show more data to the Player with @enemy.sp, @enemy.str, etc...

A good place to start reading is in Game_Enemy and Game_Battler
Enemy inherits all properties from Battler, but has some unique ones specific to Enemies, like item drop probabilities

Anything in Battler that has attr_reader or attr_accessor you can grab by using .property, like @enemy.sp.

Then you have methods, which also give you some data you want.  Like @enemy.maxhp is a method that gives you its current value.

Does that help?
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: KK20 on November 19, 2014, 01:32:41 pm
*added code tags*

Look at the refresh method inside the Window_EnemyHP class. Anyone with half a brain should know what draw_actor_hp does. But what about the values in it?
@enemy refers to the enemy object you would like to extract the HP from
0 is the x-coordinate to start the drawing, which should be on the far left of the window
i*45 + 50 is the y-coordinate to start the drawing, assuming a value of 0 would be at the very top of the window. The use of i allows you to space out the different enemies' HP values, as you could probably see in-game.

You can learn the origin of this method by looking at the Window_Base class in the default RMXP scripts:
Spoiler: ShowHide

  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw "HP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    # Draw HP
    self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
    # Draw MaxHP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
    end
  end

Scroll down more and you will come across two more methods: draw_actor_sp and draw_actor_parameter. These are the things you want to use. All you have to do is just add these method calls directly below your draw_actor_hp in your script.

  def refresh
    self.contents.clear
    for i in 0...$game_troop.enemies.size
      @enemy = $game_troop.enemies[i]
      @old_hp[i] = @enemy.hp
      unless @enemy.hp == 0
        self.contents.font.size = 15
        self.contents.font.bold = true
        self.contents.font.color = Color.new(0,0,0)
        self.contents.font.color = normal_color
        self.contents.draw_text(0, i * 45 + 37, 100, 32, @enemy.name)
        draw_actor_hp(@enemy, 0, i*45 + 50)
        # ADD THEM HERE #####################
        draw_actor_sp(@enemy, 80, i*45 + 50)
        draw_actor_parameter(@enemy, 160, i*45 + 50, 0) # Draws enemy ATK stat
        draw_actor_parameter(@enemy, 240, i*45 + 50, 1) # Draws enemy PDEF stat
        # and so on and so forth...
      end
    end
  end

The only thing that remains for you to do is adjust the x-/y-coordinates of where to draw the stats that is most meaningful to you (since this is just to debug/test your eventing).

Also, if you want the changes to update as soon as any stat changes (because right now, it's set to only update if the enemy's HP changes)
Spoiler: ShowHide

class Window_EnemyHP < Window_Base
 
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    @old_enemy = []
    refresh
  end
 
  def refresh
    self.contents.clear
    for i in 0...$game_troop.enemies.size
      @enemy = $game_troop.enemies[i]
      @old_enemy[i] = @enemy.clone
      unless @enemy.hp == 0
        self.contents.font.size = 15
        self.contents.font.bold = true
        self.contents.font.color = Color.new(0,0,0)
        self.contents.font.color = normal_color
        self.contents.draw_text(0, i * 45 + 37, 100, 32, @enemy.name)
        draw_actor_hp(@enemy, 0, i*45 + 50)
        # ADD THEM HERE #####################
        draw_actor_sp(@enemy, 80, i*45 + 50)
        draw_actor_parameter(@enemy, 160, i*45 + 50, 0) # Draws enemy ATK stat
        draw_actor_parameter(@enemy, 240, i*45 + 50, 1) # Draws enemy PDEF stat
        # and so on and so forth...
      end
    end
  end
  def update
    for i in 0...$game_troop.enemies.size
      enemy = $game_troop.enemies[i]
      if enemy.hp != @old_enemy[i].hp || enemy.sp != @old_enemy[i].sp || enemy.atk != @old_enemy[i].atk || enemy.pdef != @old_enemy[i].pdef ||
      enemy.mdef != @old_enemy[i].mdef || enemy.str != @old_enemy[i].str || enemy.dex != @old_enemy[i].dex || enemy.int != @old_enemy[i].int || enemy.agi != @old_enemy[i].agi
        refresh
      end
    end
  end
end
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: Tiamat5774 on November 19, 2014, 09:44:06 pm
To Heretic86 and KK20,  Thank you both for your tips, advice, and instruction.  This does help some and I appreciate it. :D

The only problem I'm having now is coordinates (placement and spacing of the information).  So far all I understand is that y is vertical and x is horizontal.  The numbers are to what degree they are spaced on the 2 axis.  No matter how I fiddle with the coordinates of the stats , it winds up like this:

Hell hound
HP     888/888      SP     888/888      ATK    100       PDEF    100

Basically, all the way across the screen, and with some coordinate changes, the stat names and the values would overlap. What I'm trying to accomplish is something like this:

Hell hound
HP  888/888  SP  888/888
ATK  100       PDEF  100

something to that effect, anyway
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: KK20 on November 20, 2014, 01:42:42 am
Then try using a different interval for each enemy's y-coordinate. Rather than i*45, try i*90:

        self.contents.draw_text(0, i * 90 + 37, 100, 32, @enemy.name)
        draw_actor_hp(@enemy, 0, i*90 + 50)
        draw_actor_sp(@enemy, 80, i*90 + 50)
        draw_actor_parameter(@enemy, 0, i*90 + 63, 0) # Draws enemy ATK stat
        draw_actor_parameter(@enemy, 80, i*90 + 63, 1) # Draws enemy PDEF stat

I do hope you understand what the i is even doing in the y-coordinate equations.
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: Tiamat5774 on November 27, 2014, 03:54:24 am
no, I don't know what i* is for, but I have an idea, just not sure.

I looked at the window_base and couldn't seem to find what I was looking for, as far as text spacing goes.  I could easily fit 6 stats using two lines if I could shorten the amount of space between the stat and the value.

Also am I correct in assuming that changing the spacing of the text for the hp and sp for the monsters will also affect the spacing for the actors below?

Spoiler: ShowHide
(http://i963.photobucket.com/albums/ae114/tiamat5774/Untitled_zps7e8fa572.png) (http://s963.photobucket.com/user/tiamat5774/media/Untitled_zps7e8fa572.png.html)
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: KK20 on December 02, 2014, 01:18:37 am
In Window_Base under draw_actor_parameter, near the end you see this

    self.contents.draw_text(x + 120, y, 36, 32, parameter_value.to_s, 2)

You will want to change the 120 to a smaller number. This will push the numbers closer to the stat words. Since this is a temporary thing, be sure to change it back to 120 when you're done.
Title: Re: Enemy stat block (needed for visual for playtesting)
Post by: Tiamat5774 on December 09, 2014, 01:33:04 am
thank you for your help :D