Page 1 of 1
How would I create a quest that records how many items you have given an NPC?
Posted: Mon Jul 08, 2019 2:43 pm
by lostmushroom
Hey guys, I'm stuck trying to figure something out. Not sure if you can do these things in Dialogue System but I figured I'd ask before attempting custom code
I'm making a quest where you can find a certain kind of item scattered all around the world, and you can collect them and take them back to an NPC. Think something like the grubs in Hollow Knight.
How would I go about adding a variable to the NPC that records how many of these items you have given them? Let's say I want to have the player get a special reward when they have given 10 items, then 20, then 30 - the NPC would need to 'remember' how many they'd gotten previously.
Also, is there a way to have the NPC give you a reward that's proportional to how many items you give them? For example, each item is worth 25 coins, so if you bring them 5 items, you should get 5x25 coins.
Thanks!
Re: How would I create a quest that records how many items you have given an NPC?
Posted: Mon Jul 08, 2019 4:32 pm
by Tony Li
Hi,
lostmushroom wrote: ↑Mon Jul 08, 2019 2:43 pmHow would I go about adding a variable to the NPC that records how many of these items you have given them?
You can use a variable, quest field, or actor field. In this case, it seems most intuitive to add a custom field to the NPC's actor in the dialogue database. On the Actors tab, inspect the actor. Expand the All Fields section. Click "+" to add a new field. Change the type to Number. Set the name (for example "grubsReceived").
When the player gives the NPC a grub, use the Script field's "..." to increment grubsReceived. Set the dropdowns to Actor > grubsReceived > Add 1. When you click Apply, the Script field will be set to:
Code: Select all
Actor["Bob"].grubsReceived = Actor["Bob"].grubsReceived + 1
assuming the actor is named Bob.
If you want the player to be able to give more than one at a time, here are some ideas:
- Add different responses, such as "here's one grub", "here's 5 grubs", and "here's 10 grubs".
- Use a TextInput() sequencer command to input the amount of grubs.
TextInput() stores the player's input in a string variable. To treat it as a number, you'll need to use the tonumber() Lua function.
- Or write a custom sequencer command that shows a special input field, maybe with a slider or "+"/"-" buttons, that limits the input to the amount of grubs the player has.
lostmushroom wrote: ↑Mon Jul 08, 2019 2:43 pmAlso, is there a way to have the NPC give you a reward that's proportional to how many items you give them? For example, each item is worth 25 coins, so if you bring them 5 items, you should get 5x25 coins.
Sure. If you use the first idea above (different responses for different numbers of grubs), you can do the math ahead of time:
- Dialogue Text: "Thanks for the grub. Here are 5 coins."
- Conditions:
Code: Select all
mmGetQuantity("PlayerInventory", "Grub") >= 1
- Script:
Code: Select all
Actor["Bob"].grubsReceived = Actor["Bob"].grubsReceived + 1
mmRemoveItem("PlayerInventory", "Grub", 1)
mmAddItem("PlayerInventory", "Coin", 5)
---
- Dialogue Text: "Thanks for the 5 grubs. Here are 25 coins."
- Conditions:
Code: Select all
mmGetQuantity("PlayerInventory", "Grub") >= 5
- Script:
Code: Select all
Actor["Bob"].grubsReceived = Actor["Bob"].grubsReceived + 5
mmRemoveItem("PlayerInventory", "Grub", 5)
mmAddItem("PlayerInventory", "Coin", 25)
The example above uses the
Inventory Engine integration's Lua functions but the same concept applies for whatever inventory system you're using.
Re: How would I create a quest that records how many items you have given an NPC?
Posted: Mon Jul 08, 2019 6:29 pm
by lostmushroom
Awesome, thanks for all the advice! Gonna try setting this up asap.