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
or other things like
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