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,280
Reaction score
11,868
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,628
Reaction score
5,263
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 Posts

Latest Profile Posts

I cannot get the Benny Hill Theme out of my head
A wave of cold air has hit Canada... I know it's "always cold", but this one is especially cold... I'm freezing to death lol.
Have fun with English: a "fire grenade" is not portable napalm but a fire extinguisher tool.
2 days ago someone tried to convert me to Islam. Today youtube tried to convert me to Catholicism. The only thing left would be to meet sone Jehova's witnesses.
I just successfully tested changing music by region, and changing it between continents on the world map after getting on/off the airship. I had to override the default audio transitions with eventing to make it change smoothly but it worked.

Forum statistics

Threads
93,420
Messages
912,213
Members
122,929
Latest member
Emarald04
Top