Set Event Location Randomly
#1
Set Event Location Randomly (without using global variables)
by xackery
May 8 2009

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


You'll notice inside the Event Commands, you have Set Event Location... but your only options are direct appointment, or appoint with variables.
Now it's possible to set a variable to a random value, then use Set Event location to set the random location, however, this isn't really needed and you're wasting 2 variables just to do a simple relocation.
So here's what I did:

Steps you need to do:
First:
Figure out the event ID you want to randomly relocate. That's as simple as editing the event and noting the # on the top left, e.g. ID: 024 means that it's event 24.
Second:
Figure out where you want it to randomly relocate to. In the example, I'm using the range of 14,13 to 21,29 (top left X/Y of box and bottom right X/Y of possible locations) This means the event can move randomly to these locations.
Third:
Figure out your random equation for X. Use this formula: (<min>+rand(<difference of max-min>)). The minimum of X is 14, and maximum of X is 21. The difference of the numbers is 7 (21-14 = 7), so your random range is (14+rand(7)).
Do the same for Y. min is 13, max is 29, so (13+rand(16)).

Now it's time to implement the code.
Insert an event command, and use the 3rd tab to find Custom Script. in there type this:
Code:
@tmpevent = get_character(24)
@tmpevent.moveto(14+rand(7),13+rand(16))

What all this does is, you're setting the variable @tmpevent (you can rename this to something else if you want) to a local instance of the event ID 24, and then telling it to move to the x/y coord that's randomly set by the range you specified. Whenever this custom script is executed, it should pick a location for it randomly each time. A pretty simple add to give a useful feature to RMXP (At least, I can see some cool stuff done with it).

(To experts: I'm not extremely familiar with ruby scopes, but I think @ is the best way to handle this variable, may be better to set it as tmpevent?, and there's also no unset command (I guess setting it to nil can dump it properly? Let me know)

Thanks for your time and I hope you found this educational.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  New Event Location System Ánemus 0 2,630 08-29-2008, 01:00 PM
Last Post: Ánemus
  A Sprite That Follows The Player Or An Event Near Fantastica 0 2,350 02-04-2005, 01:00 PM
Last Post: Near Fantastica
  Memorize Location Script - Release 2 Dubealex 0 2,262 11-10-2004, 01:00 PM
Last Post: Dubealex



Users browsing this thread: 2 Guest(s)