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.

[Resolved] Extra Set of Events

I am currently attempting to create a premade event on the map as a projectile. I seem to be having a slight problem however.
The positioning is perfectly fine, but the graphic is not showing at all. Is there something special I need to set up a new set of events?

Here's my current code:
Code:
# Game_Map
# * Modification for projectiles.
class Game_Map
  attr_accessor :projectiles
  
  alias map_int initialize
  
  def initialize
    map_int
    @projectiles = {}
  end

  alias map_refresh refresh
  
  def refresh
    # Refresh all map projectiles
    for projectile in @projectiles.values
      projectile.refresh
    end
    map_refresh
  end
  
  alias map_update update
  
  def update
    # Refresh all map projectiles
    for projectile in @projectiles.values
      projectile.update
    end
    map_update
  end
end

Code:
# Projectile Class
# Bases upon Game_Event
class Projectile < Game_Event
  attr_accessor :projectile
  attr_accessor :range
  # Initialize the projectile
  def initialize(projectile, range)
    @range      = range
    @proc       = true
    super($game_map.map_id, projectile)
    @through    = true
  end
  # Processing?
  def proc?
    return @proc
  end
  # Update
  def update
    # Update superclass
    super
    # If range is more than 0 and not moving: move
    if @range > 0 and !moving?
      # Move one step forward
      move_forward
      # Reduce range by 1
      @range -= 1
      Debug.dump(@x.to_s + ", " + @y.to_s + " @ projectile " + @id.to_s)
    end
    # If range is 0: end processing
    if @range <= 0
      @proc = false
    end
    # If proc: refresh
    if proc?
      refresh
    # If not: erase
    else
      erase
    end
  end
  # Hit?
  # * target: the target as integer (0 = player, > 0 = event id)
  # * attacker: the attacker as integer (0 = player, > 0 = event id)
  def hit?(target, attacker)
    # Get target coordinates
    if target == 0
      x = $game_player.x
      y = $game_player.y
    else # Obtain the target events position
      x = $game_map.events[target].x
      y = $game_map.events[target].y
    end
    # Get attacker coordinates
    if attacker == 0
      sx = $game_player.x
      sy = $game_player.y
    else # Obtain the attacker events position
      sx = $game_map.events[attacker].x
      sy = $game_map.events[attacker].y
    end
    # Check if match
    match = (x == sx and y == sy)
    # Return match
    return match
  end
end

I am using this code to set up a projectile, which updates on every map update:
Code:
$game_map.projectiles[i] = fire_projectile(attack[2], attack[1],e,d)
Note that all values supplied work perfectly fine, and the event's details are properly set up. So the parameters here shouldn't be the problem.

Code:
  # * ==========================================================================
  # * Fire Projectile
  # * ==========================================================================
  # * Creates a projectile to fire.
  # * ==========================================================================
  def fire_projectile(projectile, range, event, dir)
    # Obtain x and y positions
    if event == 0
      x = $game_player.x
      y = $game_player.y
    else
      x = $game_map.events[event].x
      y = $game_map.events[event].y
    end
    # Make the new event page
    page = RPG::Event::Page.new
    page.condition = RPG::Event::Page::Condition.new
    page.graphic = RPG::Event::Page::Graphic.new
    page.graphic.character_name = projectile
    page.graphic.direction = dir
    page.move_speed = 5
    page.move_frequency = 6
    page.through = true
    # Make the new event
    p_event = RPG::Event.new(x, y)
    p_event.id = 9999 + event + range + dir
    p_event.name = "Projectile for " + event.to_s
    p_event.pages = [page]
    # Instance the projectile
    p = Projectile.new(p_event, range)
    # Return the projectile
    return p
  end

With this piece of code it won't show at all. Maybe this is pretty obvious, but I've never tried to create my own events primarily through scripting, so this is all new to me. Any ideas?

Thanks in advance!
 
You never add it to the spriteset, which is why. In the MACL, I have added several methods for adding events to the map. You might want to look into them. Here is a quick method I created.
Code:
#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Add Character
  #--------------------------------------------------------------------------
  def add_character(game_character)
    # Returns if Character already has sprite
    for sprite in @character_sprites
      return if sprite.character == game_character
    end
    # Adds New Sprite
    @character_sprites << Sprite_Character.new(@viewport1, game_character)
  end
end

So when you create your projectile, make sure you also add to the spriteset with
Code:
$scene.spriteset.add_character(your_projectile)

Make sure you also have this:
Code:
class Scene_Map
  attr_reader :spriteset
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