Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Events Hp (Taked from another request)

Well, I was searching the Support topics to found anything that can help me, and i found this:

viewtopic.php?f=155&t=61837

Well, and inside I found this:

Code:
class Abs_Enemy

  attr_accessor :hp

  def initialize(hp = 100)

    @hp = hp

  end

end

 

class Game_Event

  attr_reader :abs_enemy

  alias_method :seph_absenemysetup_gmevt_refresh, :refresh

  def refresh

    seph_absenemysetup_gmevt_refresh

    @abs_enemy = nil

    return if @erased || @list == nil

    for ec in @list

      next unless ec.code == 108

      if ec.parameters[0].upcase.include?('ABS::ENEMY')

        parameters = ec.parameters[0].split

        @abs_enemy = Abs_Enemy.new(parameters[1].to_i)

        break

      end

    end

  end

end

This code works very well for me, I add Hp to the event and works, but when my character goes to another map, and return to the old map and check the event 
 
Hmmm... Try changing the code with this one:

[rgss]class Abs_Enemy
  attr_accessor :hp
  def initialize(hp = 100)
    @hp = hp
  end
end
 
class Game_Map
  alias_method :seph_absenemies_gmmap_init, :initialize
  def initialize
    seph_absenemies_gmmap_init
    @abs_enemies = {}
  end
  def enemy(event_id, map_id = @map_id)
    key = [map_id, event_id]
    return @abs_enemies[key] if @abs_enemies.has_key?(key)
    return nil
  end
  def set_enemy(event_id, abs_enemy, map_id = @map_id)
    key = [map_id, event_id]
    @abs_enemies[key] = abs_enemy
  end
end
 
class Game_Event
  attr_accessor :abs_enemy
  alias_method :seph_absenemysetup_gmevt_init, :initialize
  def initialize(map_id, event_id)
    seph_absenemysetup_gmevt_init(map_id, event_id)
    if (enemy = $game_map.enemy(event_id, map_id)) != nil
      @abs_enemy = enemy
    else
      return if @erased || @list == nil
      for ec in @list
        next unless ec.code == 108
        if ec.parameters[0].upcase.include?('ABS::ENEMY')
          parameters = ec.parameters[0].split
          @abs_enemy = Abs_Enemy.new(parameters[1].to_i)
          $game_map.set_enemy(event_id, @abs_enemy, map_id)
          break
        end
      end
    end
  end
end
[/rgss]

Try that.
 
I tested it, but Still no work.

I think the problem is on the 'comment' because all the time, the parameter(In this case Hp) will be recreated with the "ABS::Enemy HP", and the comment can't be changed by the scripts.. I mean...

I'm not the expert :crazy:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top