Using items from inventory with events in RPG Maker MZ

My goal is to create a system whereby the player accesses the inventory via the menu and chooses to use an item whilst facing an event. If it is the correct combination of item/event then it will use the item and move on , if not then it will say nothing happens. If you stand facing the door and use the key, it will open the door etc. but will not prompt you to use the key if you engage with the door.

As far as I can tell from reading around, this isn't exactly possible - instead, you do things like check the location of the player and see if they are standing in a particular square (for instance, the square adjacent to the event you would use the item on) or perhaps use regions?

Currently, I have worked out how to make it so that the item works only on the correct map using mapID, but not only on the correct space within that map. I suspect I need to check against X and Y coordinates of the player, but I can't work out how to do that.


Any suggestions? Thanks.
I don't know if it's the best way, but just doing a quick test, it might work... I made an item that was not consumable so that it wouldn't be used up if the player was not on the right spot. I then made it set to run a common event. I made the common event look like this:

1613919728897.png


The text was just to test if it made it to that part of the event. You could put here the door opening sequence of whatever you wanted to happen. If it's a key or other item you want to reuse, you don't need the Change Item command.

There may be better, easier ways to do it, this is just what I came up with off the top of my head. I might need more coffee though, so if there are flaws with it, my apologies.
It can be done the way you want, but that would be tedious.
basically have the item call a common event, that event uses the player position and facing to determine the coordinates of the space in front of the player. then get location info to check if there is an event and which one and on from that.

however it is much easier if you skip using the menu.
have the map event be triggered by action button, then select item to ask which item in inventory to use and work from there, no need for coordinate calculations that way.
This looks like what I'm going for, so thank you. I've had a little play around with it and it runs, but doesn't seem to work. I'm new with this software so please excuse me if these are obvious questions.

The three control variables commands at the top - I have used the Map ID one but I had to create the others in script, I just pasted what you had there to script to create this:

Capture.JPG


Do I need to be setting those variables someway outside of the event and on the map? In other words, do I need to tell the map to record those variables before this event runs and if so how would I do that?

When running what I have, I get the "not here" else result even if I am standing in the correct coordinates (15,6).
I have used the Map ID one but I had to create the others in script,
wrong choice, you need to change the entry in game data from map ID to Player X instead. Just click on the "map ID" line to do that.

Do I need to be setting those variables someway outside of the event and on the map?
no, you need to set them inside this event, exactly like the screenshot in post#2 shows.
doing it any other way will cause either lag or problems

but because you need to specify every use of the item in the entire game within the common event that is called by the item, this code will get longer and longer the more uses an item has.
That is why I suggested going the other route.

EDIT: here is a screenshot of the option you need to use, and it needs to be done with the three control variable commands inside the common event:
mapxplayer.png
Ah! Thank you both so much for your help - this is exactly what I needed and is working just how I wanted.

Appreciate it!

Original thread: https://forums.rpgmakerweb.com/threads/using-items-from-inventory-with-events-in-rpg-maker-mz.133659/