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.

[Review] Put a Bomb Script.

Well, I want to make use of the new Feature of the Support Forum, and ask for a little guide for this script that I was making today.

Then I splitted the script in the parts, but it's a little large, so I'll Include a demo for this uses.

First, I created some methods for personal uses, I only copy from the MACL and Re-edited to fit with my requests.

The Only problem that I cant solve, if the Event.Name, so I was wondering if there is another way to get the name, and another bad ways in the methods

events_name_has_string?
event_with_name

Code:
#==============================================================================

# ** Game_Map

#==============================================================================

 

class Game_Map

  #-------------------------------------------------------------------------

  # * Name      : delete_event_at

  #   Info      : Delete event at [x,y] position

  #   Author    : MephistoX

  #   Call Info : Two Arguments Integer X, Y - Event coordinates to delete

  #-------------------------------------------------------------------------

  def delete_event_at(x, y)

    # If exist an event at [x,y] position, store the event_id

    event_id = event?(x, y) ? event_at(x, y).id : nil

    # Delete event with id = id

    delete_event(event_id)

  end

  #-------------------------------------------------------------------------

  # * Name      : Events names have string?

  #   Info      : If any event on map include string

  #   Author    : MephistoX

  #   Call Info : One Argument, String to check

  #-------------------------------------------------------------------------

  def events_name_has_string?(string)

    # Pass through all Map Events

    @events.each_value do |event|

      # If any map events names include the string

      return true if event.name.include?(string)

    end

    return false

  end

  #-------------------------------------------------------------------------

  # * Name      : Event With Name

  #   Info      : Return Event ID with Defined Name

  #   Author    : MephistoX

  #   Call Info : One Argument, Name to Check(String)

  #-------------------------------------------------------------------------

  def event_with_name(name)

    # Pass through all Map Events

    @events.each_value do |event|

      return event.id if event.name.include?(name)

    end

    return nil  

  end

  #-------------------------------------------------------------------------

  # * Name      : Event With Name

  #   Info      : Return Event ID with Defined Name and Delete It!

  #   Author    : MephistoX

  #   Call Info : One Argument, Name of the Event to delete

  #-------------------------------------------------------------------------

  def event_with_name!(name)

    delete_event(event_with_name(name))

  end

end

 

 

#==============================================================================

# ** Game_Event

#==============================================================================

 

class Game_Event < Game_Character

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader :name

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias_method :meph_furni_gvent_init, :initialize

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(*args)

    # Original Initialize

    meph_furni_gvent_init(*args)

    # Set Event Name

    @name = @event.name

  end

end


The Second part is the Comment Function, It Looks fine, but I want, in the future, put more kinds of Destructions Engines (Arrows and that), a tip to get ride of this part?

Code:
#==============================================================================

# ** Game_Event

#==============================================================================

 

class Game_Event

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader :destroyable

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias_method :meph_dyne_bombs_gvent_refresh, :refresh

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    # Original Refresh

    meph_dyne_bombs_gvent_refresh

    # Clear Destroyable Flag

    @destroyable = false

    # Return if Erased

    return if @erased || @list.nil?

    # Pass through event commands

    for ec in @list

      # Skip if not comment

      next unless ec.code == 108

      # If Comment Inlclude Destroyable

      if ec.parameters[0].include?(Bombs::Destroyable_Comment)

        @destroyable = true

        break

      end

    end

  end

end


And the Last Part it's the engine itself, I get some problems with the Animation Display, so I used one of Tricksters Scripts (Display Animations) but it is old, so i was searching another form to display the animation at bomb x,y spot, (The animation isn't displayed because I delete the bomb event at the same time, but I use a Counter to determine when, so i have the problem there)..


Code:
 

module Bombs

  Bomb_Item_ID = 1

  Bomb_Graphic = 'MP_001-Bomb01'

  Bomb_Name = 'Bomb_Event'

  Bomb_Counter = 60

  Bomb_Range = 1

  Destroyable_Comment = 'Destroyable'

  Bomb_Animation = 99

  Bombable_Maps = [1]

  #--------------------------------------------------------------------------

  # * Put Bomb

  #--------------------------------------------------------------------------

  def self.put_bomb

    unless self.can_put_bomb?

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

      return

    end

    # Play Equip SE

    $game_system.se_play($data_system.equip_se)

    # Create Bomb Event

    Event_Spawner::Events.bomb_event

    # Lose Bomb Item from Inventory

    $game_party.lose_item(Bomb_Item_ID, 1)

  end

  #--------------------------------------------------------------------------

  # * Can Put Bomb? : Determine If it's possible put the bomb in the map

  #--------------------------------------------------------------------------

  def self.can_put_bomb?

    # Return False if in the Current Map Can put Bombs

    return false unless Bombable_Maps.include?($game_map.map_id)

    # Return False if Party doesn't have Bombs

    return false if $game_party.item_number(Bomb_Item_ID) == 0

    # Return False if There is a Bomb at the moment of Check

    return false if $game_map.events_name_has_string?(Bomb_Name)

    # Return True/Flase If the Tile in-front of Player is Pasable

    return (gp = $game_player).passable?(gp.x, gp.y, gp.direction)

  end

  #--------------------------------------------------------------------------

  # * Bomb Detonation : Begin Bomb Detonation Engine

  #--------------------------------------------------------------------------

  def self.bomb_detonation

    # Set Bomb Event ID

    bomb = (gm = $game_map).events[gm.event_with_name(Bomb_Name)]

    # Show Animation where is the Bomb

    $animations.push(Animation.new('tile', bomb.x, bomb.y, Bomb_Animation))

    # Pass Through Events in the Map

    $game_map.events.each_value do |event|

      # Check if Events in Bomb Range are Destroyables

      if VR.in_range?(bomb, event, Bomb_Range) && event.destroyable

        # Erase the Events

        event.erase

      end

    # Remove Bomb from Events List

    $game_map.event_with_name!(Bomb_Name)

    end

  end

end

 

#==============================================================================

# ** Scene_Map

#==============================================================================

 

class Scene_Map

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  alias_method :meph_dyne_bombs_scmap_main,    :main

  alias_method :meph_dyne_bombs_scmap_update,  :update

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    @bomb_counter = Bombs::Bomb_Counter

    meph_dyne_bombs_scmap_main

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Original Update

    meph_dyne_bombs_scmap_update

    # If Z Button was pressed

    if Input.trigger?(Input::Z)

      # Put Bomb

      Bombs.put_bomb

    end

    # Begin the Chronometer if There is a bomb in the map (Checked by Name)

    @bomb_counter -= 1 if $game_map.events_name_has_string?(Bombs::Bomb_Name)

    # If Bomb Counter is 0

    if @bomb_counter == 0

      # Detone Bomb

      Bombs.bomb_detonation

      # Reset the Bomb Counter to Original Counter

      @bomb_counter = Bombs::Bomb_Counter

    end 

  end

end

Well, that's all, I used other scripts to get this (Like EventSpawner, SDK and some macl methods).

Because there are too may scripts, I make a demo, so you can view how it works, and give a complete diagnostic of this code.

http://www.4shared.com/file/90807698/e4 ... ect18.html

That's all, thanks for giveme your help, tips, and whatever you say :)
 
First part looks like it will function just fine. However, you might want to return a list of events with names in your event_with_name method.

Second part looks fine, just with what you have, it is case-sensitive. I suggest changing this so it converts both the ec.parameters[0] to downcase, and your constant to downcase.

if ec.parameters[0].downcase.include?(Bombs::Destroyable_Comment.downcase)

The engine looks pretty good (very close to something I have done myself). I wouldn't personally make Scene_Map control your bomb counter. You would probably be better off actually controlling this with event commands when you spawn your event.

Make Event
Make first page to auto-start
Wait x-frames
Play animation
Wait x-frames
check destroyable events in range
-- do whatever to those events and erase them
erase event
delete event

That would actually cut some of your code down, and remove a lot of un-needed code in Scene_Map.

Looking good mephisto. Your scripting has come a long ways. :thumb:
 
Hey thanks again, I take all your tips, less the last, because waiting frames will stop the player movement while the bomb is exploding, but maybe there is another ways to do this, so meanwhile i will make the mods to my code and check for the 'B door' for the counter.


Thanks Again :fap:

pd: I'll waiting for another masters to evaluate my code :)


EDIT: I modified the methods, so what do you think about these?

Code:
  #-------------------------------------------------------------------------

  # * Name      : Events With Name

  #   Info      : Return an Array with Event IDs with defined name

  #   Author    : MephistoX

  #   Call Info : One Argument, Name to Check(String)

  #-------------------------------------------------------------------------

  def event_with_name(name)

    # Clear Ids Array

    ids = []

    # Check Each Event and Push each one with the name

    @events.each_value {|event| ids << event.id if event.name.include?(name)}

    # Return Ids Array

    return ids.sort

  end

  #-------------------------------------------------------------------------

  # * Name      : Event With Name

  #   Info      : Delete all Events with Defined Name

  #   Author    : MephistoX

  #   Call Info : One Argument, Name of the Events to delete

  #-------------------------------------------------------------------------

  def event_with_name!(name)

    # Delete Each event with name

    event_with_name(name).each {|id| delete_event(id)}

  end

end
 

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