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:
I am using this code to set up a projectile, which updates on every map update:
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.
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!
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)
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!