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
39,424
Reaction score
12,951
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
5,305
Reaction score
6,062
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

I noticed random Japanese dialogue in the FF7 remake while playing in English. More than once. Just now I saved a vid where Tifa spoke Japanese after a battle. We all make mistakes lol, this is kinda funny though
I wonder if the new RPG Maker will have a built-in ABS for maps or a light effect system plugin out of the box.
Not having false expectations, but if it has both, then wow. I am gonna party all night. Nah I lie. I will party all night anyway, just searching for a good excuse. :stickytongue:
And BAM!, the moment you do understand Python setters by studying JS prototypes. That's called SERENDIPITY, coming with something when you was searching for something else. From "The three Princes of Serendib", a persian novel.
The sinking feeling when you realize your grandmother probably isn't long for this world, and the frustration when you know that this pandemic will take her away...not because she has Covid, but because no doctor is willing to see a patient to even run simple diagnostics anymore if one of her symptoms happens to be a recurring fever, even if her primary care physician gives her the test and it comes back negative.
Will be revealing my project to the forum soon.

Forum statistics

Threads
99,615
Messages
967,315
Members
131,291
Latest member
Lucafont
Top