0 votes

I have a pretty basic RPG system, and I have my enemies/items in the first area scene - the problem is players can just walk in and out of the scene over and over to get an infinite supply of the items.

Godot version 3.2.3 Stable
in Engine by (12 points)

It sounds like you just need to ensure the code that spawns the enemies/items only runs once. That could be as simple as checking some boolean variable prior to the spawn and then only spawning when its value is false. Then, after the initial spawn, set its value to true.

Bottom line, there's probably a straight forward way to fix the issue, but the details will depend on how/where the spawning is being done. Can you share the relevant code?

2 Answers

0 votes

A simple idea is that You can use a varible to check if it has the specific item or not.
For example var has_sword : bool.
P.S. If you have lots of items then use array or dictionary.
When player enter the scene, check the value of has_sword. If has_sword is false, then queue_free the sword.

by (526 points)
0 votes

create an autoload script.
for example called "gamedata"

on that script create a variable called for example

var uniqueenemylist = [ ]

or

var uniqueitemslist = []

then on your enemy sript,
create hima variable "numberID"
go to the ready function, and check if that ID is in the
gamedata.uniqueenemylist, if it's there, queue.free()
otherwise, it will be spawned as normal.
and write :

export var numberID = 0 # being an export variable, so you can make multiple of these enemies and only change this variable on the editor.

func ready():

if gamedata.uniqueenemylist.has(numberID ):
queue.free()

no need for else statement.

and once you killed that enemy or caught that item go and add it to that list.

gamedata.uniqueenemylist.append(numberID)

so the next that you load the scene, it will check in the ready function and it will queue free instead of spawning.

:) what do you think?

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.