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.