Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: ThallionDarkshine on December 29, 2012, 04:22:45 pm

Title: [XP] Event Templates
Post by: ThallionDarkshine on December 29, 2012, 04:22:45 pm
Template Events
Authors: ThallionDarkshine
Version: 1.0
Type: Misc Add-on
Key Term: Misc Add-on



Introduction

You 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




Screenshots

They wouldn't really show much, just an event sitting on a map.


Demo

It's pretty easy to use, but I'll put up a demo if requested.


Script

Spoiler: ShowHide

# 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



Instructions

In the script.


Compatibility

I don't think there will be any compatibility issues.


Credits and Thanks




Author's Notes

None
Title: Re: [XP] Event Templates
Post by: Zexion on December 29, 2012, 07:02:57 pm
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
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 29, 2012, 07:09:57 pm
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!
Title: Re: [XP] Event Templates
Post by: LiTTleDRAgo on December 29, 2012, 08:38:09 pm
level up   :)
btw is the event created by this script saved in save game?
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 29, 2012, 09:49:55 pm
Yes, it's stored in Game_Map, which is Marshal.dumped in the save data.
Title: Re: [XP] Event Templates
Post by: Zexion on December 30, 2012, 03:38:57 pm
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?
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 30, 2012, 04:15:05 pm
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.
Title: Re: [XP] Event Templates
Post by: Zexion on December 30, 2012, 08:32:46 pm
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.
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 30, 2012, 10:19:48 pm
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.
Title: Re: [XP] Event Templates
Post by: Zexion on February 12, 2013, 01:40:08 pm
:O you made me want to buy an sd card reader so i can install my rmxp again lol
Title: Re: [XP] Event Templates
Post by: cessern on December 01, 2014, 05:19:16 am
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  :(
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 01, 2014, 06:36:05 am
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:
Code: rgss
create_event_from_template("EV001",1,1)


Edit - Oh, and it should go above main.
Title: Re: [XP] Event Templates
Post by: cessern on December 01, 2014, 06:51:50 am
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
Title: Re: [XP] Event Templates
Post by: ThallionDarkshine on December 01, 2014, 08:37:57 am
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).
Title: Re: [XP] Event Templates
Post by: cessern on December 01, 2014, 08:50:42 am
No more trouble, the script works now. Thanks  :)
Title: Re: [XP] Event Templates
Post by: NerdiusMaximus on June 20, 2023, 08:34:47 am
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?
Title: Re: [XP] Event Templates
Post by: KK20 on June 21, 2023, 02:41:58 pm
Are you using a save game file or loading a new game? If the former, the script won't work.