Need Help with giving npc specific items

Status
Not open for further replies.

Fangzarie

Veteran
Veteran
Joined
Apr 5, 2018
Messages
57
Reaction score
7
First Language
English
Primarily Uses
RMMV
I've seen this topic floating around in the Vx/ace forums but it's never really what I'm needing help with. I'm trying to set up a situation in which an injured npc needs multiple potions/ healing items to recover before they are healed for a quest. Over on the vx/ace forums one of the common solutions for something similar to this is, making the item a Key Item and using the Select Key Item command to put the item id into a variable. I have that part down but I don't know how to tell the script how to check for the number of times the npc has been given said item or if that is even possible at all? I think I am complicating things by having the item also consumable by the player character, like a basic potion but it can also be given to this particular npc?

Here is what my script looks like so far. I think I might need to control the event by starting a new page each time the player has successfully given the item? The other problem is, as of right now the script is literally accepting ANY item I hand the npc from the regular items menu. I'm wondering if there is a way to set the event to just accept the quest item and nothing more?


If anyone can point me in the right direction I would appreciate the help.

Thanks in Advance.
 

Attachments

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
I would not do it with key items. I would have a variable to count how many items you've given him, and a switch for each item you give him.

Let's say you have a cake-baking NPC, who needs flour, milk and two eggs. I'd do it something like this:

Code:
Page 1 of the event:
Text: I want to make a cake, but I don't have the ingredients.  If you bring me flour, milk and two eggs, I'll give you a slice of it when it's done.
Turn on self switch A.

Page 2 of the event (conditioned by self switch A):
Text: I'm making a cake, but I don't have all the ingredients.  I need flour, milk, and two eggs.
Control Variables [Ingredients Given] = 0
If Switch [Gave Flour] is ON
  Control Variables [Ingredients Given] += 1
Else 
  If [Flour] is in inventory
    Text: Here, you can have this flour
    Change Items: [Flour] - 1
    Control Switches [Gave Flour] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Switch [Gave Milk] is ON
  Control Variables [Ingredients Given] += 1
Else
  If [Milk] is in inventory
    Text: Here, you can have this milk
    Change Items: [Milk] -= 1
    Control Switches [Gave Milk] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Switch [Gave Eggs] is ON
  Control Variables [Ingredients Given] += 1
Else
  Control Variables [Eggs Held] = number of [Eggs] in inventory
  If Variable [Eggs Held] >= 2
    Text: Here, you can have these eggs
    Change Items: [Eggs] -= 2
    Control Switches [Gave Eggs] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Variable [Ingredients Given] = 3
  Text (NPC): Thanks - Come back a bit later and I'll give you a slice of cake
  Turn on self switch B
End


Page 3 of the event (conditioned by self switch B)
Text: Here's your cake!
So once the NPC has asked for the items, they will wait until you've given all of them. Doesn't matter what order you give them in - it keeps track of what you've given and what you haven't. As soon as you give everything, it moves to the next stage.
 

Fangzarie

Veteran
Veteran
Joined
Apr 5, 2018
Messages
57
Reaction score
7
First Language
English
Primarily Uses
RMMV
I would not do it with key items. I would have a variable to count how many items you've given him, and a switch for each item you give him.

Let's say you have a cake-baking NPC, who needs flour, milk and two eggs. I'd do it something like this:

Code:
Page 1 of the event:
Text: I want to make a cake, but I don't have the ingredients.  If you bring me flour, milk and two eggs, I'll give you a slice of it when it's done.
Turn on self switch A.

Page 2 of the event (conditioned by self switch A):
Text: I'm making a cake, but I don't have all the ingredients.  I need flour, milk, and two eggs.
Control Variables [Ingredients Given] = 0
If Switch [Gave Flour] is ON
  Control Variables [Ingredients Given] += 1
Else
  If [Flour] is in inventory
    Text: Here, you can have this flour
    Change Items: [Flour] - 1
    Control Switches [Gave Flour] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Switch [Gave Milk] is ON
  Control Variables [Ingredients Given] += 1
Else
  If [Milk] is in inventory
    Text: Here, you can have this milk
    Change Items: [Milk] -= 1
    Control Switches [Gave Milk] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Switch [Gave Eggs] is ON
  Control Variables [Ingredients Given] += 1
Else
  Control Variables [Eggs Held] = number of [Eggs] in inventory
  If Variable [Eggs Held] >= 2
    Text: Here, you can have these eggs
    Change Items: [Eggs] -= 2
    Control Switches [Gave Eggs] = ON
    Control Variables [Ingredients Given] += 1
  End
End

If Variable [Ingredients Given] = 3
  Text (NPC): Thanks - Come back a bit later and I'll give you a slice of cake
  Turn on self switch B
End


Page 3 of the event (conditioned by self switch B)
Text: Here's your cake!
So once the NPC has asked for the items, they will wait until you've given all of them. Doesn't matter what order you give them in - it keeps track of what you've given and what you haven't. As soon as you give everything, it moves to the next stage.
I tested a short version of this with two items and it seems to work just fine. The npc only recognizes the specified item and the script ends each time to check for each new item. Thanks so much. I think the problem I was having was, I wasn't specifying where the item was coming from. I was just storing a blank value. Scripting hasn't always been my strong suit but this worked wonders! I'm guessing I could add a timer or anything after turning self switch B back off.

The only thing I'm worried about is if map changes effect how the switch works?
I've had problems in the past with self switches turning back on with autorun events?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
This is not scripting. It is eventing.

Why would you want to turn off self switch B? That is deliberately turned on to indicate you have given everything the NPC needed. To turn it back off again, they're just going to ask for the stuff you've already given them, and turn it right back on.

Switches are global. Self switches are local to the event, but they are saved. If you leave the map and return, they will be exactly the same as they were before.

If you've had self switches turning on, it's because you had something that made them turn on. The events only do what you tell them to do, via event commands or scripts/plugins. They don't do things randomly, no matter how much it might seem like it.
 

Fangzarie

Veteran
Veteran
Joined
Apr 5, 2018
Messages
57
Reaction score
7
First Language
English
Primarily Uses
RMMV
This is not scripting. It is eventing.

Why would you want to turn off self switch B? That is deliberately turned on to indicate you have given everything the NPC needed. To turn it back off again, they're just going to ask for the stuff you've already given them, and turn it right back on.

Switches are global. Self switches are local to the event, but they are saved. If you leave the map and return, they will be exactly the same as they were before.

If you've had self switches turning on, it's because you had something that made them turn on. The events only do what you tell them to do, via event commands or scripts/plugins. They don't do things randomly, no matter how much it might seem like it.
I suppose that would make sense. A lot of switches in my game are turned on when the player has a certain item in their inventory. I've never really thought to tell them what to do if they player gets these items again, like if they were to buy a shield needed for a quest or something.

Either way the event you've given me works wonders! I'll probably need to go back an look at some of my others events to make sure their switches don't conflict. Either way thanks again!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
You don't need to turn on switches just to indicate that the player's received an item. You use switches to make OTHER events behave differently once that event has been run. If you have a need to see if the player has an item, you can just use the conditional branch (if item is in inventory) or control variables (if you want to know how many you have).
 

Fangzarie

Veteran
Veteran
Joined
Apr 5, 2018
Messages
57
Reaction score
7
First Language
English
Primarily Uses
RMMV
You don't need to turn on switches just to indicate that the player's received an item. You use switches to make OTHER events behave differently once that event has been run. If you have a need to see if the player has an item, you can just use the conditional branch (if item is in inventory) or control variables (if you want to know how many you have).
Oh! So if i need an npc to check for an item I would set up an event a bit like the one above to say, check for the shield then move the event out of the way. I then have that event erase itself and turn on self switch B to make sure it doesn't come back. I have another event to pose as if that was the guard that had moved out of the way?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
not both - either, depending on what you want.
erase event is temporary until the player leaves and reloads the map, then the check will be done again.
self-switch or switch to a different event page is permanent even after reloading the map.

as for the position, you either need a different event on the new position or one of the plugins that allows you to save the new event position.
 

Fangzarie

Veteran
Veteran
Joined
Apr 5, 2018
Messages
57
Reaction score
7
First Language
English
Primarily Uses
RMMV
not both - either, depending on what you want.
erase event is temporary until the player leaves and reloads the map, then the check will be done again.
self-switch or switch to a different event page is permanent even after reloading the map.

as for the position, you either need a different event on the new position or one of the plugins that allows you to save the new event position.
So I should only need the self switch and not the erase event command? When the event checks it will always prioritize the blank page with self switch B.

I did some googling and I found a Yanfly plugin that apparently saves event locations! I think it will really help me tidy up a lot of events.

Thanks for all the advice. As far as my earlier question for starting this thread has been answered as the event is doing exactly what I need.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

"You can thank my later", "But you haven't done anything", "Well, that's why ..."
Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

Forum statistics

Threads
105,884
Messages
1,017,243
Members
137,609
Latest member
shododdydoddy
Top