Getting name or id of event at specific location (in current map)

Venima

Treasure experiences and sensations, not progress.
Veteran
Joined
Oct 8, 2013
Messages
128
Reaction score
48
First Language
English
Primarily Uses
N/A
I'm trying to build a combat-themed puzzle where you move different types of units (events) to battle positions. I intend on making 24 battle scenes like this, so to save myself endless conditional branches I decided to turn to scripting. There are only going to be so many types of enemy and so many types of unit, and I have a look-up table for success.

Now I can get the location of a specific event, but what I need is to get the name of another event based on specific x and y coordinates. From there I can use conditional branches to identify the matchup.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,349
Reaction score
11,940
First Language
English
Primarily Uses
RMMV
Using event commands, you can put the x and y values into variables, and use the Get Location Info, which will give you an event id at that location. If you must do it via script, look at Game Interpreter and see what it does behind the scenes when that command is run. It'll be a call to $game_map.event_at or something like that (don't have Ace open atm and in a bit of a hurry)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,645
Reaction score
5,292
First Language
Indonesian
Primarily Uses
RMVXA
It's
Code:
$game_map.events_xy(x,y)
The return value is an array, in case somehow your event is pilled up in a single grid.
So you need to add [0]
Code:
$game_map.events_xy(x,y)[0].name
or something
 

Venima

Treasure experiences and sensations, not progress.
Veteran
Joined
Oct 8, 2013
Messages
128
Reaction score
48
First Language
English
Primarily Uses
N/A
I got the puzzle working, thanks!

If you're interested:

strongholdbattle.png

By going on various quests you'll develop reputation with different types of units which allows you to hire them to defend your stronghold.

So far I have:

Guards (cheap to hire and good vs bandits)
Archers (good vs unarmoured or slow enemies)
Clerics (will join if you help them, good vs undead)
Paladins (will join after stage in main quest, expensive to hire but good vs most except fast enemies)
Pirates (will join if you help them, good vs fast enemies & ghosts)
Dwarves (will join if you help them, good vs enemies found underground)
and Sprites (will join if you help them, good vs enemies vulnerable to fire magic)

Each enemy requires at least 1 unit to fight them off. There can be up to 4 enemies attacking at once. If you match a unit with the wrong enemy, they lose a life (most have 2 lives before you have to hire replacements).

This is the script code that makes it all happen:

Code:
unitev = $game_variables[4]
unitid = unitev - 1

listenemy = ["Bat","Slime","Bandit","Wisp","Zombie","Giant Spider","Ghoul","Dryad","Golem","Wraith","Fergrul","Dragon"]
listbeat = [4, 1044, 600, 617, 295, 754, 4052] # bitwise &

x = $game_map.events[unitev].x
y = $game_map.events[unitev].y + 2
enemy = $game_map.events_xy(x, y)[0].name

return if listbeat[unitid] & (2 ** listenemy.find_index(enemy)) > 0 #successful match!

$game_variables[3] += 1 #counter for how many units you lost
$game_self_switches[[@map_id, unitev, 'B']] = true #show the unit's 'damage' sprite
$game_variables[61 + unitid] -= 1 #unit loses a life
That gets run for each unit in battle. The listbeat array contains numbers based on binary matches for the enemies they beat. So for example, the paladin is: 001010111111. Meaning they don't beat bats or slimes, but do beat bandits, etc. I convert this binary into an integer (4052) and then use a 'bitwise and' to match it against the enemy that I find opposite that unit. This is a neat trick I learned at college.

I don't know whether this battle puzzle is worth showing off as a tutorial somewhere but anyway, that's all I needed, thanks!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

This little brat (my nephew) just invent a new way of enjoying his orange juice by pouring it inside of used perfume bottle and sprayed it to his mouth...
Jamaica? No, Aunty. I said, I'm on RPG Maker :*/
Lunar New Year is over :( but it's time to get back to work!
I keep giving myself deadlines because I'm so excited to finish something but I notice areas where I'm rushing the story and that's what's gonna weaken my overall project, gotta stop that
My new level features a Jellyfish character who cannot love, because he electrocutes everything he touches.

Forum statistics

Threads
93,690
Messages
914,646
Members
123,287
Latest member
Jackosmiles
Top