Select item manually and give it to a npc

I can‘t find a solution without plugin for my problem.

My idea:

I find a chocolate on a table, take it into my inventar. ( that works fine)

Then

I go to a npc nearby and want give him the chocolate item. That should only be possible, if I stand before him and select the chocolate item in the inventar manually.
My intention ist, that the players must have the right idea to use the chocolate with this npc. If they use it with other npc it should not work.

I would appreciate a help very much!
Things like these seem pretty "standard" and obvious given a lot of games use this system, the thing is you need to code/event it, you have to specify what you want to happen, where, when and under what conditions so even an easy functionality as this can become a big task (as you'll need to repeat/check for every instance of use the item to get a reaction)

Assuming your item-reciever npc doesnt move around:
Put a common event on the item use
on the common event:
>check for map ID ->save to variable 1
>check player X coordinate ->save to variable 2
>check player Y coordinate -> save to variable 3
>check if Var1= your desired map
>check if var 2&3= your desired player spot (next to npc that will get the item)
then do the proper "item interaction"
if not then do a "not to be used here" message

and now the hard part:
repeat for every item you want to be used this way
Assuming your item-reciever npc doesnt move around:
If it does, you can still do it.

Put a common event on the item use
on the common event:
>check for map ID ->save to variable 1
>check player X coordinate ->save to variable 2
Conditional Branch -> Character -> Facing Right
- Control Variable -> variable 2 +1
Conditional Branch -> Character -> Facing Left
- Control Variable -> variable 2 -1
>check player Y coordinate -> save to variable 3
Conditional Branch -> Character -> Facing Down
- Control Variable -> variable 3 +1
Conditional Branch -> Character -> Facing Up
- Control Variable -> variable 3 -1
>check if Var1= your desired map
>check if var 2&3= your desired player spot (next to npc that will get the item)
Instead, Get Location Info (you can reuse variable 1), Info Type Event ID, Designation with variables.

Then do a Conditional Branch for that event ID to equal the ID of the NPC you want to be able to give it to.

then do the proper "item interaction"
if not then do a "not to be used here" message
Don't forget you'll have to do something to allow the item to be used, as simply having a common event won't do anything. The typical method is to put in its effects to Add State and immediately Remove State again.
and you're all thinking too complex. It is much simpler than that.

Have the NPC be on action button.
show text "what do you want to give the person"
select item (item given)
if variable (item given) = ID of chocolate item then do whatever.

If you never use the chocolate ID anywhere else, it can't have an effect anywhere else.
and you're all thinking too complex. It is much simpler than that.

Have the NPC be on action button.
show text "what do you want to give the person"
select item (item given)
if variable (item given) = ID of chocolate item then do whatever.

If you never use the chocolate ID anywhere else, it can't have an effect anywhere else.
I was going to suggest this but going by the OP I'm assuming they don't even want the "hint" that there's an item that *can* be used on the NPC. They want the player to use it from the menu, rather than selecting it from the select item list. I could be wrong though!
and you're all thinking too complex. It is much simpler than that.

Have the NPC be on action button...
Yes, but this:

My intention ist, that the players must have the right idea to use the chocolate with this npc.
If you talk to the NPC and it gives you a prompt to give him something, that's giving a hint - not the players must have the right idea on their own. I agree it makes it more complex, but we're just going off the OP's description, as Trihan said.
Thank you all, yes I need a solution, which the players must find this way for themselves.

@ATT_Turan
Are your suggestions a replacement of the first suggestions or an addition, that this all works?
Are your suggestions a replacement of the first suggestions or an addition, that this all works?
They are exactly as written. You follow the instructions that BK-tdm wrote with my additions where I placed them, and the one part that's crossed out and I replaced it.
This two steps are too fast for me. Can you explain it a bit more „step by step“, like the first part. Its not clear for me, if I have to put this together in one „if“ or one after the other.

„Instead, Get Location Info (you can reuse variable 1), Info Type Event ID, Designation with variables.

Then do a Conditional Branch for that event ID to equal the ID of the NPC you want to be able to give it to.“
those are the settings needed in the event command get location info:
one variable to store the result, and two with the coordinates where to check.
the command will return the event ID if there is an event there, or zero if not.

and then you check if the event id you get is the one of the NPC or not

EDIT: in the german translation, get location info was given a very bad translation.
the command is about map location but it was translated as if it was a file location that would be questioned:
those are the settings needed in the event command get location info:
one variable to store the result, and two with the coordinates where to check.
the command will return the event ID if there is an event there, or zero if not.

and then you check if the event id you get is the one of the NPC or not

EDIT: in the german translation, get location info was given a very bad translation.
the command is about map location but it was translated as if it was a file location that would be questioned:
Thank you. Now I understand it better and you're right, one problem was, that these is a bad translation of this command.

Do I have the conditional branch also in the common event at the end of all. And for me it's not clear how I check the event id of the player is the same like the NPC. Do I have to save the npc event in a variable?

I assume, that the reaction of giving the item (chocolate) to the npc, I have to insert in the npc event, but with the condition of the common event, right?
1678190005707.png

That's the common event till now...
1678190088186.png

That's the item setting.
Do I have the conditional branch also in the common event at the end of all.
Yes, where else could you put it?

And for me it's not clear how I check the event id of the player is the same like the NPC.
I don't know what this means - your player isn't an event, it doesn't have an event ID. How could it be the same as an NPC? You are looking to see whether there is an event in the space in front of the player that has the ID of the NPC you want to give the chocolate to.

So if the NPC is event ID 17, you use Get Location Info to get the Event ID at those coordinates into variable 1, then use Conditional Branch to ask if variable 1 is equal to 17.

Note: When I quickly typed this yesterday, I reversed X and Y. Looking up/down should change what Y you're looking at, and left/right changes the X. I've corrected my original instructions.

That's the item setting.
I know you're not done with the event yet, but don't forget what I said at the end of my first post. You need to add an Add/Remove state to the Effects (it doesn't matter what state, so long as it doesn't do anything obvious to the character. You could make a blank one).

Otherwise when you try to use the item you'll get an error buzzer because it doesn't change anything on the target.
Wow, now it works and I hope I have understand the most oft all. 😉

Now, my common event looks like this:
1678217138098.png


The common event: Use chocolate bar is for use items.

It looks like this:

1678217187255.png


And with this it works.

I get the chocolate, walk to the npc and open the item menu, select chocolate bar and the item menu opens again below and I select the chocolate again. After that, the text of the npc appear and the item disappear in the item menu.
A better solution would be, that I don't must select the chocolate twice to use it. (one time in the menu and after that a second time on the screen below.
A better solution would be, that I don't must select the chocolate twice to use it.
Well...why did you write that, then? 😉

I don't see the reason to have two common events for this. Just select the Change Items and Show Text, cut them out, paste them into your "check for map ID" event at the bottom where it currently says Common Event: use chocolate bar.

It's a good general practice any time you find yourself calling a common event from a common event to stop and ask, "Does it make sense to do this?"
Here I summarise, how I understand this tutorial. For me it's important, that I understand what I do. I want learn how it works. I don't want copy all. Thank you very much, that you help me in this learning process.


Put a common event on the item use
on the common event:

I connect the common event with an item. This common event works with every item, which I added this common event as a effect.

>check for map ID ->save to variable 1

This command checks on which map I am and save it to variable 1 of this common event.

>check player X coordinate ->save to variable 2
This command checks on which vertical map coordinate I am and save it to variable 2 of this common event.

Conditional Branch -> Character -> Facing right
- Control Variable -> variable 2 +1

If the character looks right on the map, it adds 1 to the variable 2. This is the next space in front (right looking) of the character.

Conditional Branch -> Character -> Facing left
- Control Variable -> variable 2 -1
If the character looks left on the map, it sub 1 to the variable 2. This is the next space in front (left looking) of the character.

>check player Y coordinate -> save to variable 3
This command checks on which horizontally map coordinate I am and save it to variable 3 of this common event.

Conditional Branch -> Character -> Facing down
- Control Variable -> variable 3 +1
If the character looks down on the map, it adds 1 to the variable 3. This is the next space in front (down looking) of the character.

Conditional Branch -> Character -> up
- Control Variable -> variable 3 -1
If the character looks up on the map, it sub 1 to the variable 3. This is the next space in front (up looking) of the character.

>check if Var1= your desired map
This command checks if the saved map ID at the beginning of this common event ist the same like the desired map I am on.


Get Location Info (you can reuse variable 1), Info Type Event ID, Designation with variables.
This command get the location info about the current position of the character in front of him.

Then do a Conditional Branch for that event ID to equal the ID of the NPC you want to be able to give it to.

The conditional branch checks with the event ID of the NPC, if the location info is the same like the position of the NPC.
Well...why did you write that, then? 😉

I don't see the reason to have two common events for this. Just select the Change Items and Show Text, cut them out, paste them into your "check for map ID" event at the bottom where it currently says Common Event: use chocolate bar.

It's a good general practice any time you find yourself calling a common event from a common event to stop and ask, "Does it make sense to do this?"

I understand, I don't need a second common event. It works fine, how you described! Thank you very much. You all are very kind!
That was for me a very good lesson and I can use this not only once.
one additional mistake, althoughj it should not matter:

the check for map ID = 9 is useless, because the same will happen on any map - because the commands to handle the chokolate bar are not inside the conditional branch but after branch end.

Original thread: https://forums.rpgmakerweb.com/threads/select-item-manually-and-give-it-to-a-npc.155582/