I have a simple 'use key to unlock door' scenario for my game. But I can't figure out how to get the event to work the way I want.
Basically, if the player interacts with the door if they have the key or not, text will appear saying "The door is locked." What I need is the player to open their inventory and use the item from the item menu while standing in-front of (and looking at) the door to unlock it. I can't figure out how to get it to work though. I've looked around for tutorials or examples but I can't find anything.
I know I need the item to have a common event attached to it, but I have no idea how to call other events from the items common event, along with getting the players position and looking direction to make sure it is correct.
Use an item from inventory to trigger event?
● ARCHIVED · READ-ONLY
-
-
The easiest way to handle a situation like this is bypass using the item and just put a conditional branch in the event to check if the player has a key and then if they do the door unlocks, or if you want add the choice asking the player if they want to use the key.
*edited*
If you're determined to make the player use an item from the menu then give the item a common event and in that common event change variables for the following information:
Player x
Player y
Player direction
map id
Then set conditional branches asking if the player is on the right map, position, and direction. If all true turn a switch on. On door event have conditional branch that asks if the earlier switch is on and if true door is unlocked, otherwise locked. -
@Princess Bananabelle You need a 4th variable for the map id, else you could unlock the door on any map.
@big-maker I personally think it's more practical to use the 'select item' event command, so the player is prompted to select an item from their inventory when interacting with the door. Selecting the right key would then unlock the door. -
@Jules98 Thank you for noticing that, I made the necessary corrections so it should work. Also, I never knew that select item thing existed! That actually helps me out with a problem I've been troubled with for the past few days.
-
The easiest way to handle a situation like this is bypass using the item and just put a conditional branch in the event to check if the player has a key and then if they do the door unlocks, or if you want add the choice asking the player if they want to use the key.
*edited*
If you're determined to make the player use an item from the menu then give the item a common event and in that common event change variables for the following information:
Player x
Player y
Player direction
map id
Then set conditional branches asking if the player is on the right map, position, and direction. If all true turn a switch on. On door event have conditional branch that asks if the earlier switch is on and if true door is unlocked, otherwise locked.
@Princess Bananabelle So my common event for my key has 3 control variables that contains the players x,y, and facing direction. Currently my event contents is laid out like:
And this works perfectly; but it's clunky. I want all three if statements on a single line for clarity along with making an else statement for 'can't use key here' easier. How can I get all three if's on one line? -
@big-maker I don't think there's a way to put all three conditionals in one line, so you'll have to copy the cant use key here message in all three elses (supposed to be four now that I've made a correction, unless it's impossible to use that key in another map). Or place a label at the end of the event and under it put the used key message and above it cant use key message. Then in the all true conditional put a jump to label to the earlier label. Though cleaner, it's probably more work.
-
@big-maker I don't think there's a way to put all three conditionals in one line, so you'll have to copy the cant use key here message in all three elses (supposed to be four now that I've made a correction, unless it's impossible to use that key in another map). Or place a label at the end of the event and under it put the used key message and above it cant use key message. Then in the all true conditional put a jump to label to the earlier label. Though cleaner, it's probably more work.
@Princess Bananabelle I'm thinking script will be the better option. I've got the player x and y script down just fine, but I can't figure out how to get the facing direction or the map id.
$gamePlayer.x == 9 && $gamePlayer.y == 6
For some reason $gamePlayer.direction == 6 does not work. And i'm not sure how to get the map ID with script. -
Never mind, I got it.
$gamePlayer.x == 9 && $gamePlayer.y == 6 && $gamePlayer._direction == 6 && $gameMap._mapId == 2 -
thankgoodness one of those is a 9 and they aren't all 6's or this post would be satanic XD!@Princess Bananabelle So my common event for my key has 3 control variables that contains the players x,y, and facing direction. Currently my event contents is laid out like:

And this works perfectly; but it's clunky. I want all three if statements on a single line for clarity along with making an else statement for 'can't use key here' easier. How can I get all three if's on one line?