The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: Wrinkle on October 28, 2014, 05:07:25 PM

Title: Event Spawn [XP]
Post by: Wrinkle on October 28, 2014, 05:07:25 PM
Event Spawn for XP
By: Wrinkle


Description
A lot of people told me this script could not be made compatible with RPGXP. So... here it is. This script was originally made for VX Ace, I tried to convert it for my own purposes, ran into a few errors on the way, got help, fixed it, and now it works on XP. This script allows you to change event locations via events, and also to call events from other maps to the player's current map.

Features

Notes
This script was made in January 2014
Events can be spawned using either of these formulas;
spawn_event_location(x, y, event_id)
spawn_event_location(x, y, event_id, map_id)
If no map ID is included it will call the event from the map in which the player is located. If map ID is included it will spawn the event from that map, and the event will appear on the current map. You can spawn multiples of the same event on the map at once. This script could come in handy for action based or adventure games. You can spawn monsters, items, or even attacks such as arrows and other projectiles. The spawn to region function was removed from the script to accommodate RPG Maker XP.

Credit
Yanfly for making the original VX Ace script
Wrinkle for converting the script to XP
Modern Algebra for fixing the graphic refresh bug

Script
To install this script, copy and paste it above Main.
Spoiler for:
Code: [Select]
#==============================================================================
#
# ▼ Yanfly Engine Ace - Spawn Event v1.00
# -- Last Updated: 2012.02.08
# -- Level: Normal, Hard
# -- Requires: n/a
#
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.02.08 - Started Script and Finished.
# Edited for RPG Maker XP by Wrinkle
# Credit to Modern Algebra for fixing the graphic refresh bug
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# For those who would like to spawn pre-made events from the current map or
# even other maps, this script allows you to do so. With the option of spawning
# the events at specific locations or a random spot marked by a certain region,
# you can have events spawn using simple script calls. The events remain until
# a map change.
#
# -----------------------------------------------------------------------------
# Script Calls - These commands are used with script calls.
# -----------------------------------------------------------------------------
# spawn_event_location(x, y, event_id)
# spawn_event_location(x, y, event_id, map_id)
# This causes a new event to be created at location x,y on the current map with
# the data from the corresponding event and map ID.
# The map_id is where the event will be called from according to event_id.
# If no map_id is included it will call the event from your current map.
#
#==============================================================================

#==============================================================================
# ■ Game_Map
#==============================================================================

class Game_Map
 
  #--------------------------------------------------------------------------
  # new method: spawn_event
  #--------------------------------------------------------------------------
  def spawn_event(dx, dy, event_id, map_id)
    map_id = @map_id if map_id == 0
    map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    event = generated_event(map, event_id)
    return if event.nil?
    key_id = @events.keys.max + 1
    @events[key_id] = Game_Event.new(@map_id, event)
    @events[key_id].moveto(dx, dy)
    $scene.spriteset.wrinkle_refresh_event(@events[key_id])
  end
 
  #--------------------------------------------------------------------------
  # new method: generated_event
  #--------------------------------------------------------------------------
  def generated_event(map, event_id)
    for key in map.events
      event = key[1]
      next if event.nil?
      return event if event.id == event_id
    end
    return nil
  end
 
end # Game_Map

#==============================================================================
# ■ Game_Interpreter
#==============================================================================

class Interpreter
 
  #--------------------------------------------------------------------------
  # new method: spawn_event_location
  #--------------------------------------------------------------------------
  def spawn_event_location(dx, dy, event_id, map_id = 0)
    $game_map.spawn_event(dx, dy, event_id, map_id)
  end

end # Game_Interpreter

#==============================================================================
# ■ Scene_Map
#==============================================================================

class Scene_Map
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :spriteset
 
end # Scene_Map

class Spriteset_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Refresh Event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def wrinkle_refresh_event(event)
    # Refresh new region event
    index = @character_sprites.size - 1
    @character_sprites.insert(index, Sprite_Character.new(@viewport1, event))
  end
end

#==============================================================================
#
# ▼ End of File
#
#==============================================================================


No screenshots or demo available

I hope someone finds use for this script, if anyone still uses RPG Maker XP that is. I know it has proved useful for me. Thanks again to Modern Algebra for being an active part of this forum, and for being smart with scripting. If anyone wants to use this script, I don't care if you credit me or not, because Yanfly and Modern Algebra are the real miracle workers here. Good day everyone.