JENNA'S PROFILE

Search

[Script] Kal Event Spawner help

Hi I am making a game on RPG Maker VX Ace using XAS ABS scripts and I wanted to have an event spawner for boss fights that spawn enemies, well Kal's script is the only one that would work out, the only problem is it uses event name rather than event id. Which will error the game because the enemy events have to have EX: <Enemy10>

If I use the script as is it errors cause the <> in the name of the events. XAS needs the events to be named <Enemy#>.

So I come to you guys for help. Can anyone take this script:

# EventSpawn 1.0.2

# by Kal (github.com/kl)

#

# --- Changelog ----

#

# 1.0.2 - Improved error messages

# 1.0.1 - Fix a bug where <spawn-max> would spawn one less than specified.

# 1.0 - Initial release

#

# --- How To Use ----

#

# First create an event on the map that will act as the spawner event.

# Now you can add various spawn tags to this event (using the Comment function)

# to let the script know what you want it to do.

#

# The spawn tag comments can be added to any event page.

#

# The following commands are available (note do not put in the )

#

# <spawn-event >

# <spawn-timer >

# <spawn-pos >

# <spawn-type >

# <spawn-switch >

# <spawn-max >

# <spawn-life >

# <spawn-on-passable >

#

# <spawn-event> takes the name of the event to spawn (the name can be found

# in the upper left corner of the event box)

#

# <spawn-timer> takes the number of frames between each spawn (60 frames = 1 sec)

#

# <spawn-pos> takes a string that defines where to spawn the events. It can take

# either a relative or an absolute position. To specify a relative position,

# use up, down, left and right. Then the event will be spawned relative to

# the spawner on tile in that direction.

# To use an absolute position you can give the map coordinate like this

# x,y for example 13,49.

# You can also set the events to spawn a random distance from the spawner

# event. To do that use the tag like this: <spawn-pos random:>

# The number after the colon is the max distance from the spawner that

# events should be able to spawn. If you omit this number the max distance

# is set to 1.

# If you do not set the spawn-pos, the event will be spawned on the same

# tile as the spawner is on.

#

# <spawn-type> takes the type of spawner to use. Currently this script supports

# the normal type (which you get if you don't use this tag) and the

# "loop" type which will keep track of the events that have been spawned,

# and if any of them dies it will be able to spawn again (if it is using

# the spawn-max tag that is)

#

# <spawn-switch> takes the ID of a switch and the spawner will only spawn if

# this switch is on.

#

# <spawn-max> takes the maximum number of events the spawner should spawn.

# Once this number has been reached the spawner will stop spawning.

#

# <spawn-life> takes the number of frames a spawned event should exist.

# After the time is up, the spawned event will be automatically

# despawned (erased). If you don't set this options the spawned

# events will not be despawned at all.

#

# <spawn-on-passable> takes true or false and determines whether the spawner

# should be able to spawn events on unpassable tiles or not (note if you use

# absolute positioning this attribute does nothing). The default is true.

# So if you set spawn-pos to 'up' and the tile above the spawner event is

# unpassable, the event will spawn on an adjecent passable tile.

# If no adjecent tile is passable, it will spawn on the same tile as

# the spawner event.

#

# All the above tags are optional, except for spawn-event and spawn-timer.

#

# --- Example ---

#

# Here is what an example event comment for a spawner could look like:

#

# <spawn-event EV004>

# <spawn-timer 120>

# <spawn-switch 1>

# <spawn-pos random:4>

# <spawn-max 3>

# <spawn-life 400>

# <spawn-type loop>

# <spawn-on-passable false>

#



module Kal

module EventSpawn

module CONFIG

# You can set this constant to a map id and then the script will look

# for events to spawn on that map. That way you can put all your spawn

# events on one map, and they don't need to present on the map they

# are spawned on.

SPAWN_MAP_ID = nil

end

# <<< END CONFIGURATION >>>

class SpawnError < StandardError; end

#

# The Factory module is used to parse the spawn tags and create the

# spawner events.

#

module Factory

module_function

#

# Creates and returns a spawner given a Game_Event (which is the event

# that the spawner will spawn) and an RPG::Event (which is the RPG::Event

# for the spawner event and it holds things such as event comments).

#

# This method is called for every event on the map inside Game_Event's

# constructor. If the event it is called for is not a spawner event

# then this method returns nil.

#

def make_spawner(game_event, rpg_event)

spawn_tags = get_spawn_tags(rpg_event)

return nil if spawn_tags.empty?

options = make_options_hash(spawn_tags.join)



check_requirements(options, game_event.id)

select_spawner_object(game_event, options)

end

# ***** HELPER METHODS *****

#

# Takes an RPG::Event object and returns an array with all the spawn

# tag comments (e.g. <spawn-timer 120>) for the event.

#

def get_spawn_tags(rpg_event)

# Returns an array with all comments on all pages.

comments = rpg_event.pages.each_with_object() do |page, array|

array << page.list.select do |cmd|

cmd.code == 108 || cmd.code == 408

end

end

# Selects the comments that are spawn comments and return them.

spawns = comments.flatten.select { |c| c.parameters.first =~ /^<spawn-/ }

spawns.map { |c| c.parameters.first }

end

#

# Parses a spawn string (all spawn comments as one string) and returns

# an options hash.

#

def make_options_hash(spawn_string)

timer = spawn_string

event_name = spawn_string[/<spawn-event\s+(+)>/i, 1]

max = spawn_string

switch = spawn_string

life = spawn_string

not_passable = spawn_string

type = spawn_string

pos = spawn_string[/<spawn-pos\s+(+?)>/, 1]

options = {}

options = timer.to_i if timer

options = event_name

options = switch.to_i if switch

options = max.to_i if max

options = life.to_i if life

options = false if not_passable

options = type

if match = pos && pos.match(/(\d+),(\d+)/)

options = :absolute

options = match

options = match

else

options = :relative

case pos

when "up"

options = -1

when "down"

options = 1

when "left"

options = -1

when "right"

options = 1

when /random/

distance = pos || 1

options = distance.to_i

end

end

options

end

#

# Checks to see if the user set the <spawn-event> and <spawn-timer>

# tags. If not raise exceptions.

#

def check_requirements(options, event_id)

event_msg = "not set for EVENT:" + "%03d" % event_id

if !options

raise ArgumentError.new("<spawn-event> #{event_msg}")

elsif !options

raise ArgumentError.new("<spawn-timer> #{event_msg}")

end

end

#

# Selects the Spawner type to use.

#

def select_spawner_object(game_event, options)

case options

when "loop"

LoopSpawner.new(game_event, options)

else # when no type was selected

Spawner.new(game_event, options)

end

end

end

#

# Spawner is the class that keeps track of what event should be spawned,

# when it should be spawned and where it should be spawned.

# Each Game_Event that is a spawner will have it's own reference to a

# Spawner object.

#

class Spawner

include Kal::EventSpawn::CONFIG



#

# Sets initial values. game_event is the event that will be spawned.

#

def initialize(game_event, options_hash)

@game_event = game_event

@options = {x_adjust: 0, y_adjust: 0, passable: true} # default options

@options.merge!(options_hash)

@timer = @options

@spawn_count = 0

@spawn_map_events = load_spawn_map_events

end

#

# Updates a the spawner event's timer (if it should spawn or not).

#

def update

return if @options && !$game_switches[@options]

@timer -= 1

if @timer <= 0

@should_spawn = true

@timer = @options

end

end

#

# Spawns a new event.

#

def spawn

set_spawn_pos # set the position the spawned event will have.

event = event_from_name(@options)

cloned_event = clone_event(event)

cloned_event.life_es_kal = @options

cloned_event.moveto(@x, @y) # move the spawned event to it's position.

# Add the spawned event to the Game_Map and the current Spriteset:

$game_map.events = cloned_event

spriteset = SceneManager.scene.instance_eval { @spriteset }

spriteset.instance_eval do

@character_sprites << Sprite_Character.new(@viewport1, cloned_event)

end



@spawn_count += 1

@should_spawn = false

end

#

# Checks if it is time for the Spawner to spawn or not.

#

def should_spawn?

max = @options

max ? @spawn_count < max && @should_spawn : @should_spawn

end

# ***** HELPER METHODS *****

private

#

# Sets the position that will be used for the next event that

# should be spawned.

#

def set_spawn_pos

set_absolute_position if @options == :absolute

set_relative_position if @options == :relative

end

#

# Sets an absolute position.

#

def set_absolute_position

@x = options

@y = options

end

#

# Shortcut method to set the @x and @y position variables.

#

def set_pos(x, y)

@x = x

@y = y

end

#

# Sets a relative position. The position can be relative to the

# position of the spawner (up, down etc) or a random position.

#

def set_relative_position

event_x = @game_event.x

event_y = @game_event.y

x = event_x + @options

y = event_y + @options

if @options

set_random_position(event_x, event_y)

else

if @options && !passable?(x, y)

set_passable_position(event_x, event_y)

else

set_pos(x, y)

end

end

end

#

# Sets @x and @y to passable tile in a one-tile distance from x,y.

# If no passable tile exists, sets @x and @y to x,y.

#

def set_passable_position(x, y)

[, , , ].each do |coord|

if passable?(coord, coord)

@x = coord

@y = coord

return

end

end

@x, @y = x, y

end

#

# Sets the position to a random coordinate given a start x

# and a start y.

#

def set_random_position(start_x, start_y)

distance = @options

coords = get_possible_coords(start_x, start_y, distance).shuffle

if @options

pass = coords.find { |c| passable?(c, c) }

pass ? set_pos(pass, pass) : set_pos(start_x, start_y)

else

x, y = coords.first

set_pos(x, y)

end

end

#

# Returns an array of all the coords within distance tiles

# of x,y excluding x,y itself.

#

def get_possible_coords(start_x, start_y, distance)

coords =

left_most = start_x - distance

right_most = start_x + distance

up_most = start_y - distance

down_most = start_y + distance

(left_most..right_most).each do |x|

(up_most..down_most).each do |y|

coords << unless x == start_x && y == start_y

end

end

coords

end

#

# Check if a tile is passable on the map.

#

def passable?(x, y)

$game_map.passable?(x, y, 2)

end

#

# Does a deep clone of the given Game_Event object and sets

# it's spawn event IDs.

#

def clone_event(event)

id = generate_valid_id

cloned_event = Marshal.load(Marshal.dump(event))

cloned_event.set_ids_es_kal(id)

cloned_event.set_spawn_name_es_kal(@game_event, id)

cloned_event

end

#

# Finds a Game_Event object given an event name.

# Raises an exception if the event could not be found.

#

def event_from_name(name)

error_msg = "Event '#{name}' could not be found on the current map " +

"(ID = #{$game_map.map_id})" +

(SPAWN_MAP_ID ? ", or on the spawn map (ID = #{SPAWN_MAP_ID})." : ".")

events = $game_map.events.values + (@spawn_map_events || )

event = events.find { |e| e.event.name == name }

event || raise(SpawnError, error_msg)

end

#

# Generates a valid id based on the number of events already on the map.

#

def generate_valid_id

$game_map.events.keys.max + 1

end

#

# Returns an array with all the Game_Events located on the spawn map.

#

def load_spawn_map_events

id = SPAWN_MAP_ID

if id.is_a?(Numeric) && id > 0

begin

map = load_data(sprintf("Data/Map%03d.rvdata2", id))

rescue Errno::ENOENT => e

raise LoadError, "ERROR: Could not find a map with ID #{id}\n" +

"(SPAWN_EVENT_ID = #{id})"

end

this_map_id = $game_map.map_id

map.events.values.map { |event| Game_Event.new(this_map_id, event) }

end

end

end

#

# LoopSpawner is a spawner that will check if any of the events it

# spawned are erased, and if so it will decrement the @spawn_count

# variable for that event.

#

class LoopSpawner < Spawner

def update

super

check_dead_events

end

def check_dead_events

alive = $game_map.events.values.select do |game_event|

game_event.event.name =~ /spawn:#{@game_event.event.id}/ &&

!game_event.erased

end

@spawn_count = alive.size

end

end

end # end EventSpawn

end # end Kal





class Game_Event

attr_accessor :spawner_es_kal, :life_es_kal

attr_reader :event, :erased, :spawned_info_es_kal

#

# Overrides initialize to create a Spawner instance for this event

# (or nil if it is not a spawner event).

#

alias_method :initialize_es_kal, :initialize

def initialize(*args)

initialize_es_kal(*args)

@spawner_es_kal = Kal::EventSpawn::Factory.make_spawner(self, @event)

end

#

# Updates the Spawner and the spawned event's life (if applicable).

#

alias_method :update_es_kal, :update

def update

update_es_kal

@spawner_es_kal.update if @spawner_es_kal

update_life_es_kal

end

#

# Checks the spawned event's life and erases it if life becomes zero.

#

def update_life_es_kal

if @life_es_kal

@life_es_kal -= 1

erase if @life_es_kal <= 0

end

end

#

# Sets IDs.

#

def set_ids_es_kal(id)

@event.id = id

@id = id

end

#

# Sets the event's name.

#

def set_spawn_name_es_kal(game_event, id)

@event.name = "#{@event.name} spawn:#{game_event.event.id}:#{id}"

end

end

class Game_Map

attr_reader :map_id

#

# Gets all Spawner events on the map that should spawn and spawn them.

#

alias_method :update_events_es_kal, :update_events

def update_events

need_to_spawn = @events.values.select do |event|

event.spawner_es_kal && event.spawner_es_kal.should_spawn?

end

need_to_spawn.each { |event| event.spawner_es_kal.spawn }

update_events_es_kal

end

end


And make it into event_id rather than event_name somehow? This is my only chance for this to work cause I suck at scripting this stuff.

[request]A jounrey's End assistance needed

I am currently making another new game, but using XAS ABS scripts to help me out, but I come to a small bump in the way. Puzzles...Puzzles are a must in my game project A Journey's End, but I am not very good at making my own home made puzzles.

The project also needs help with spriters and tileset artists for rtp edits.

This is a free project and any help would be greatly appreciated.

For the puzzle making, I want them to be challenging and well thought out, so if you can come up with killer puzzles and want to help please reply.

For spriters, I need average spriters that can mimic my style graphics I did so far, but making every NPC and Chara etc is something that needs help.


I use RTP heads that are slightly lightened and the body I did on my own.

I could also use tileset makers, they can be rtp edits or similar to rtp since I have already had a few rtp edits used and want to stick with the style.

Rm2k3 CBS Freezes

Well here I am again seems no matter what I do or look over everything looks fine and at one point worked fine too, now somehow when ever I have the hero attack the enemy, she moves in for the hit then the common event code stops running, surrounding map events do continue to run though...So what am I missing, what would cause a common event to stop running mid way? I checked over and over its not the wait commands or PP events... I am at a loss now...

RM2k3 CBS Targeting Help

ok so I have been having issues with my targeting system for my CBS I am making. I personally have no idea what I am doing lol yet I do...

I want it simple just scroll between a max of 4 monsters. It uses a variable Monster Count that is made before the battle actually starts that determines how many monsters show up on the field, this number does not change when the monsters die though so its set to 1-4.

So The first scrolling I did went through fine but glitched when monsters died, so I made switches for each monsters death...Then my mind goes blank...

So I have variables and switches and common events for this and yet I am stumped how to actually make this work out.

Can anyone help me make this targeting system?

Variables made:
-Target Cursor Controls (for movement)
-Target Cursor (for what monster it is on)
-Monster Count (How many monsters are on the field at a time 1-4)

Switches made:
-E1 Dead
-E2 Dead
-E3 Dead
-E4 Dead
-Targeting (used for the common event Targeting since it is a Para Process)

I have it set to auto target Monster 1 at the start of the system, but from there I am so confused my head hurts... plz assist any way you can thnx

Lands of Lunori Intro Song - Assist

I recently uploaded my Intro to youtube and got a comment about the starting music. After hearing him/her out I starting understanding what he meant, maybe the starting song isnt right for my game.

You can view the Intro here: http://rpgmaker.net/games/500/lunori_videos/

The assistance I need from RMN is what does everyone think about the Intro's starting theme?

Is it too much for my game, does it not fit, should I use non-vocal music instead?

I thank you for helping me with this issue.

Game Profile Lost Lastest Update..?

I changed my screenshot for my games main picture to show, but now the recent updates section in the center of my games home page is now gone.

Not sure where it went, but it must have something to do with modifing my games previous display picture in screenshots.

I hope its something simple I can fix myself, maybe renaming the image or something, I guess it depends on why the latest updates for my game vanished in the first place.

Here is the link to my games profile main page. http://www.rpgmaker.net/games/500/
Pages: 1