Godot Version
4.3
Question
Hello! I’m very new, and I haven’t seen any tutorials on how to do this but I wanna ask two questions:
-
How can I make it so the player can obtain a key through dialogue from an npc?
-
How can I have a chest open only when the player has all the keys
I’m really sorry if this is a lot, thank you so much in advance to anyone willing to answer
Do you already have an interaction system for diaolgue and chest opening?
Do you have a key-scene/resource?
For the chest, if tried to open, you can just assert that the player has all the necessary keys, needed for opening with an if statement or for loop.
For the npc you can just add the key when they talk with each other by adding it to an array or inventory, depending on your current system:
class_name NPC
var key
func interacted(player):
if key not in player.keys:
player.keys.append(key)
class_name Chest
var needed_keys: Array[Key] = [key1, key2]
func interacted(player):
for key in needed_keys:
if not key in player.keys:
return
open()
func open()
# code for opening
Note that this is just a general idea and the actual code depends on your current implementation
Thank you so much for the help! I haven’t actually set most of the stuff up, but I wanted to get the general idea of what I needed to do before I actually got to it. But really, thank you so much
1 Like
If you still have questions on the path of programming this just ask!