I want to use an event comment or an event name to call a block in the database, but I've no idea how to do it specifically. Can someone walk me through this? It'll save me a ton of lines if I didn't have to waste variables($game_variables not @variables) noobing my way through this.
Can you be more specific? What's "a block in the database"? What's an event comment?
Sorry, I'm essentially illiterate when it comes to this sort of speak.
Uh, lets see... in Blizz's ABS you're able to type \e[1] in the event name category and that allows you to register it as an enemy. In other systems if you type <e> in comments or whatever it does the same thing. I've seen many systems use either Game_Event or the Interpreter section to accomplish this... some in less than 60 lines of code, but I've no idea how it works generally, because I am not a natural coder, but an eventer that transitioned into rgss.
I've sat through a bunch of tutorials and seminars on Ruby, but I'm still preschool, so I don't know what's what besides the essential basics. I can look under the hood and understand pieces in a vacuum, but when I turn it on it looks like .. um... moon runes I guess.
As it stands I -can- make an ABS, but the amount of redundancy I use can be shortened if I knew how to forgo in-engine variables [$game_variables] to assign enemies [$game_map.events[]] and could just assign it as <enemy>.
In the mean time I'm trying my damndest to reverse engineer scripts until it makes sense.
You're going to have to have an understanding of Regular Expressions to make the most out of this. I can't remember if we ever went over that.
First is looping through your map events when the map is loaded.
class Game_Map
alias setup_special_events setup
def setup(map_id)
setup_special_events(map_id)
@map.events.each_value do |event|
# placeholder for code
end
end
end
For event names, you might have come across something like this when studying BlizzABS's code:
if event.name.clone.gsub!(/\\[Ee]\[(\d+)\]/) {"#[$1]"}
# temporary variable for ID
id = $1.to_i
I personally believe this is a better solution:
if event.name.match(/\\e\[(\d+)\]/i)
id = $1.to_i
As for comments, I'm only going to assume the first page of the event.
event.pages[0].list.each do |command|
if command.code == 108 || command.code == 408
command.parameters.each do |comment|
if comment.match(/<e>/i)
print "I found an <e> tag!"
end
end
end
end
You just plug those into the aliased Game_Map#setup method as indicated. So putting that all together you get something like this:
class Game_Map
alias setup_special_events setup
def setup(map_id)
setup_special_events(map_id)
@map.events.each_value do |event|
if event.name.match(/\\e\[(\d+)\]/i)
p "Event ID #{event.id} is an enemy of ID #{$1}"
end
event.pages[0].list.each do |command|
if command.code == 108 || command.code == 408
command.parameters.each do |comment|
if comment.match(/<e>/i)
p "Event ID #{event.id} has an <e> tag"
end
end
end
end
end
end
end
Granted this is very basic. If you're going to get more complex with it, then by all means separate the different
match blocks as their own methods, i.e.
@map.events.each_value do |event|
check_for_enemy_in_name # def check_for_enemy_in_name
check_for_enemy_tag # def check_for_enemy_tag
end
KK you're absolutely beautiful.