Template Events
Authors: ThallionDarkshine
Version: 1.0
Type: Misc Add-on
Key Term: Misc Add-on
IntroductionYou ever want to create lots of one event dynamically during the game? Well, this script allows you to create template events, which allow you to create many identical events, and all from one event.
Features
- Easily create template events in the editor.
- Create as many template events as you want.
- Create events from templates at any position on the map.
ScreenshotsThey wouldn't really show much, just an event sitting on a map.
DemoIt's pretty easy to use, but I'll put up a demo if requested.
Script
# Instructions
# To create an event template, simply create an event with <template> in its
# name. What's left of the event's name is the name of the template. These
# template events will be automatically removed from the map when created.
# You can create an event from a template event with:
# create_event_from_template(NAME, X, Y[, SAVED])
# NAME - the name of the template
# X, Y - the x and y coordinates for the event, respectively
# SAVED - whether the event should be saved (default true)
class Game_Map
attr_accessor :saved_events
attr_reader :template_events
alias tdks_template_evnt_init initialize
def initialize
tdks_template_evnt_init
@template_events = {}
@saved_events = {}
end
alias tdks_template_evnt_setup setup
def setup(map_id)
tdks_template_evnt_setup(map_id)
@events.each { |key, ev|
unless ev.instance_variable_get(:@event).name.gsub!(/\<template\>/, '').nil?
@template_events[ev.instance_variable_get(:@event).name] = ev
@events.delete(key)
end
}
@saved_events[@map_id] ||= []
@saved_events[@map_id].each { |event|
nind = (1..@events.keys.max+1).detect{|i|!$game_map.events.keys.include?(i)}
@events[nind] = event
}
end
end
class Interpreter
def create_event_from_template(name, x, y, save=true)
ev = $game_map.template_events[name]
unless ev.nil?
ind = (1..$game_map.events.keys.max + 1).detect { |i| !$game_map.events.keys.include?(i) }
tmp = ev.clone
tmp.instance_variable_get(:@event).id = ind
tmp.instance_variable_set(:@id, ind)
tmp.moveto(x, y)
$game_map.events[ind] = tmp
if $scene.is_a?(Scene_Map)
spriteset = $scene.instance_variable_get(:@spriteset)
char_sprites = spriteset.instance_variable_get(:@character_sprites)
char_sprites.push(Sprite_Character.new(spriteset.instance_variable_get(:@viewport1), tmp))
spriteset.instance_variable_set(:@character_sprites, char_sprites)
end
if save
$game_map.saved_events[$game_map.map_id].push(tmp)
end
$game_map.need_refresh = true
end
end
end
InstructionsIn the script.
CompatibilityI don't think there will be any compatibility issues.
Credits and Thanks
Author's NotesNone
Well butter mah biscuits. It's as if you read my mind. This is the exact kind of script I need to make my tree system :). Definitely going to use and credit. LEVEL++
Also thanks to you, I can now make my game ABS independent seeing as how I won't need an even generator from BABS or Mr.Mo's. I find it useful that they include this in the abs, but I think it's kinda dumb for me to install an abs to a game that has no fighting in it :P
How did you know my secret talent? 8-O
You're thinking of... Nothing. And yeah, having an abs simply for the purpose of event creation is pretty pointless. Glad to be of help!
level up :)
btw is the event created by this script saved in save game?
Yes, it's stored in Game_Map, which is Marshal.dumped in the save data.
I haven't gotten a chance to try this out, so I was wondering... Say I generate the event on the map. Then that event triggers itself to change into another event. If I was to leave the map and come back would it restart the event, or would it just be like any other event?
Right now, generated events do not stay on after you have left the map. However, that is the next feature that I will add to the script.
Dang. Well I will be awaiting this update. Hope you end up doing it lol if not I am screwed-ish, but luckily I can put off the trees and flowers till the very end :D.
Don't worry, I will do it. Probably expect an update tomorrow, maybe the day after that at latest.
Edit - And tomorrow turns into a month from now. Update to v1.0. Now you can choose whether to save the event when you create it.
:O you made me want to buy an sd card reader so i can install my rmxp again lol
This didn't work for me. I've tried in both RPG maker XP 1.2 and 1.5, Under and above "Main".
Name of the event is: "<template>EV001". Script to call template is: "create_event_from_template(EV001,1,1)" Both times tested in a new project.
Under "Main" the error: "uninitialized constant Interpreter::EV001" When I use the script
Above "Main" the error: "undefined method 'event' for #<Game_Event:0x29335a0>" When I press "New Game"
This would be the perfect script for what I'm making now. Please help me.
Requesting a demo :(
You need to enclose the name of the event in quotation marks so the interpreter knows that it is a string rather than searching for a constant with that name. So you would call it like so:
create_event_from_template("EV001",1,1)
Edit - Oh, and it should go above main.
Ah sorry. My mistake.
I tried the script after adding " " around the name, and it still doesn't work. (Also put it above main)
The Error: "undefined method 'event' for #<Game_Event:0x29335a0>" comes up whenever I press new game.
I added this script to a whole new/clean project. Does this script need another script to work?
It says in the script that the template event will be automatically removed from the map when created, but nothing unordinary happens when I create those events. If you can't find my problem, then please create a demo. I've a much easier time finding errors with demos
Oops, I'm really sorry about that. I fixed the script, and if you have any more trouble with it I will upload a demo (I'm at school on a chrome book right now so i can't atm).
No more trouble, the script works now. Thanks :)
Hi, this might be a very weird question seeing as this script is more then 10-years old. I want to use this event to spawn events based on another event, but with their own original ID. When I run this command
[create_event_from_template("bob", 8, 8)/code] it gives me a nodefined method error voor "push" for nil:Nilclass
could someone help me?
Are you using a save game file or loading a new game? If the former, the script won't work.