Fantasist's Tips for Eventers

Started by Fantasist, January 08, 2008, 01:18:30 pm

Previous topic - Next topic

Fantasist

January 08, 2008, 01:18:30 pm Last Edit: July 26, 2008, 12:53:33 am by Fantasist
Fantasist's Tips for Eventers

       Events are a way to control the default scripts, eventing IS scripting in a way. There are certain things you can't do directly with event commands, but you don't need to resort to large script systems for a solution. Sometimes, pieces of code can be very useful. I'll be gathering those tips here in this thread. I'll keep this post updated with any new ideas I have. Feel free to suggest/request/ask anything. If you feel events are not getting your job done and you need a little more, this is your place.

Player and Event Positions on the Map



The map is a grid of 32x32 pixel tiles. Each tile has an adress in terms of X and Y coordinates. For some reason, if you want to know the player's/event's position on the current map, these are the lines of code:
Player's position:
$game_player.x  # The player's X coordinate
$game_player.y  # The player's Y coordinate


An Event's position:
$game_map.events[ID].x  # X position of the event. ID is the ID of the event in the map
$game_map.events[ID].y  # Y position of the event. ID is the ID of the event in the map


These can be very useful for things like minimaps. There is also another potential use for which I actually dug these lines: ranged actions. You can compare the distance between two events/player and make something happen. For example, you can make a caterpillar system where the event 'Follows the Hero' if the distance is more that 1 tile. You can make pets too: follow the hero if the distance is more than, say 6 tiles and move around randomly otherwise. That way, your pet wanders around near you but will follow you if you're too far.

Power of variables - Storing Strings



You know that variables are used to store numbers, right? Fact is, they can store pretty much ANYTHING, like text and even your current party. But for storing these other things, you should the Call Script command and use this code:
$game_variables[ID] = (thing to store)

where ID is the ID of the variable you intend to use. (thing to store) can be anything, mostly
'text' or "text"

or other things like
$game_party


How is this useful? You know that \n[1] will be replaced by the name of the first actor in the party, but what if you wanted to display the name of the first actor in the database? Or actually, if you want to display a frequently used or changing text in a message, what would you do? You'd use variables to store the text.

Let's cover the name of the actor first. To store the name of the 4th actor in the database, you'll use:
$game_variables[ID] = $data_actors[4].name

$data_actors[4].name is the name of the 4th actor in the database.

Now here's another use. Say you have multiple possibilities in your game, where a message is different depending on a switch. So instead of doing this:
<>Conditional Branch: Switch [0036: Heaven's Blade Unlocked] == ON
  <>Message: Heaven's Blade is the strongest weapon in existance.
  Else Handler
  <>Message: Ultima Blade is the strongest weapon in existance.
  End


You can do this:
<>Conditional Branch: Switch [0036: Heaven's Blade Unlocked] == ON
  <>Script: $game_variables[1] = 'Heaven's Blade'
  Else Handler
  <>Script: $game_variables[1] = 'Ultima Blade'
  End
<>Message: \v[1] is the strongest weapon in existance.

And actually, you can simple use \v[1] whenever you want to refer to the strongest weapon in existance.

Range - distance between two points



Let's say there's two ppoints on the map and you want to find the distance between them. These two points can be anywhere, one below the other, vertically aligned, horizontally aligned, or diagonally placed at a distance. If you're familiar with the Pythogoran rule for the hypotenuse of a right angled triangle, this is exactly that, it gives the distance between two points:
Math.hypot(x2 - x1, y2 - y1)
where x1, x2, y1 and y2 are the coordinates of the points (x1, y1) and (x2, y2).
It's mostly cartesian geometry, nothing complex once you know the basics. This piece of code can be VERY WELL USED in conjunction with Player and Event Positions on the Map to make ranged systems, the same things discussed in Player and Event Positions on the Map.

Get All Items



Ever wanted to have ALL the items during debug? I for one find it irritating using lots of 'Add Item' event command. Now, paste the following code into a 'Call Script' event command and you have all the items:


itemdata = load_data('Data/Items.rxdata')
wpndata = load_data('Data/Weapons.rxdata')
armordata = load_data('Data/Armors.rxdata')
(1..itemdata.size).each {|id| $game_party.gain_item(id, 99)}
(1..wpndata.size).each {|id| $game_party.gain_weapon(id, 99)}
(1..armordata.size).each {|id| $game_party.gain_armor(id, 99)}
$game_party.gain_gold(999999999)


The last line makes you VERY rich, you can remove it if you want.

Shop Everything



Same as above, for shops. Paste this anywhere above 'Main' and below 'Window_ShopBuy'. You need to set the SHOP_EVERYTHING_ID to the ID an item you make in the database. When you call a shop with that item, it'll call a shop with ALL items, weapons and armors (no exceptions).


class Window_ShopBuy
 
  SHOP_EVERYTHING_ID = 1
 
  alias fant_shop_everything_win_shop_buy_init initialize
  def initialize(shop_goods)
    if shop_goods[0][0] == 0 && shop_goods[0][1] == SHOP_EVERYTHING_ID
      goods = []
      # Items
      (1..$data_items.size).each {|i| goods.push([0, i])}
      # Weapons
      (1..$data_weapons.size).each {|i| goods.push([1, i])}
      # Armors
      (1..$data_armors.size).each {|i| goods.push([2, i])}
    end
    fant_shop_everything_win_shop_buy_init(goods)
  end
 
end

Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Nortos

love that code
$game_player.x  # The player's X coordinate
$game_player.y  # The player's Y coordinate
it can be used for when passing through an area to trigger an autorun instead of lot's of player touches. Oh btw Fantasist would it possible for some code to say after 10 steps after some event you can make another event

Sally

yea acually u dont need a script for that one :P

wait a min ill show you :P

Sally

January 08, 2008, 07:48:57 pm #3 Last Edit: January 08, 2008, 07:49:54 pm by Susys
okay 2 things..

1 why do i have -1 energy :( :( :( :(

and 2:

hear u go nortos!

Even one place on map

<>Message: After 10 steps after this event there will be another
:              : event :)
<>Switch: [0001: Event-up] = ON
<>


Common event:
NAME: event Trigger: Parallell Process Trigget switch: 0001: Event-up

<>Variable: [0001: steps] = Steps
<>Conditional Branch Variable [0001: steps == 10
     <>Message: see? 10 steps after! :) no scripts
     :              :
     :              :             -Sally
     <>
:    End
<>

Nortos

oh ty must of overlooked variables...

Galatea

@Susy, i think someone defame/powerdown/minus your energy.
you've got to ask who did that, and why.
Its just my opinion, it might be wrong.  :-\

Nortos

that's only way I could think of she could get it unless a bug, oh and maybe put if want to continue this convo in feedback board, don't want to get too offtopic

Galatea


Sally


Calintz


Fantasist

ty Calintz :)

@Susys:
Quotewhy do i have -1 energy

I have the same problem at RMRevolution. Dunno what the problem is. I'll give you energy if it helps :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Justin

 Hey, I was wondering if someone can help me out with the player and event potition event. If its possible can someone explain to me how it works? So like how I can use it for other things like mini-maps and that dog thing. Im still n00b to this so help would be appretiated. ;D

Valcos

Quote from: Justin on February 12, 2008, 10:56:31 pm
Hey, I was wondering if someone can help me out with the player and event potition event. If its possible can someone explain to me how it works? So like how I can use it for other things like mini-maps and that dog thing. Im still n00b to this so help would be appretiated. ;D


^
|
|  My bad, thats me  ;D. Didnt realize I wasnt logged in.  :-\
"We are all in the gutter, but some of us are looking at the stars."
-Oscar De La Hoya

Nortos

basically the best use I've found for it is a conditional branch where the condition is them being more than say 1x and less than 5 x which would mean they are 1-5 tiles away from the event and I aint that sure about the mini map part but that's basic of it

Valcos

Oh. lol :P Not really sure what you meant exactly, but I guess I'll just fool around with it for a couple hours.
"We are all in the gutter, but some of us are looking at the stars."
-Oscar De La Hoya

Nortos

check my stealth event system uses it in there

Valcos

"We are all in the gutter, but some of us are looking at the stars."
-Oscar De La Hoya

legacyblade

These are useful, thanks for sharing!

Sally

QuoteRange - distance between two points


that could help me in makeing arrows in my event ABS mini game :) and spells

Fantasist

February 20, 2008, 08:51:32 am #19 Last Edit: July 26, 2008, 12:54:35 am by Fantasist
I said long back that i'll explain the function 'hypot', sigh, I've lost touch... maybe another time...

EDIT: Added "Get All Items".

PS: Do anyone even find this useful?

EDIT 2:

Added Shop Everything code.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews