[XP] Event Templates

Started by ThallionDarkshine, December 29, 2012, 04:22:45 pm

Previous topic - Next topic

ThallionDarkshine

December 29, 2012, 04:22:45 pm Last Edit: December 01, 2014, 08:36:59 am by ThallionDarkshine
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


  • 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.




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


  • ThallionDarkshine




Author's Notes

None

Zexion

December 29, 2012, 07:02:57 pm #1 Last Edit: December 29, 2012, 07:04:42 pm by Zexion
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

ThallionDarkshine

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!

LiTTleDRAgo

level up   :)
btw is the event created by this script saved in save game?

ThallionDarkshine

Yes, it's stored in Game_Map, which is Marshal.dumped in the save data.

Zexion

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?

ThallionDarkshine

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.

Zexion

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.

ThallionDarkshine

December 30, 2012, 10:19:48 pm #8 Last Edit: February 12, 2013, 08:11:05 am by ThallionDarkshine
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.

Zexion

:O you made me want to buy an sd card reader so i can install my rmxp again lol

cessern

December 01, 2014, 05:19:16 am #10 Last Edit: December 01, 2014, 05:21:03 am by cessern
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  :(

ThallionDarkshine

December 01, 2014, 06:36:05 am #11 Last Edit: December 01, 2014, 06:37:53 am by ThallionDarkshine
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.

cessern

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

ThallionDarkshine

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).

cessern

No more trouble, the script works now. Thanks  :)