Please help me solve

guys can someone help me find a solution?
I have a group of enemies and each of them has been assigned a danger value.
example:
enemy 1 - value 1
enemy2 - value 2
enemy3 - value 3
I would like the enemies to be created by calculating the danger value that increases with each wave.
example:
if the danger value is equal to 5 - create 2 enemy2 and 1 enemy1 or 1 enemy3 and 1 enemy2

if the danger value is 10 - create 5 enemy2 or 2 enemy3 1enemy2 2enemy1

I hope I was clear on what I want

I attach screens of current events and folder with current project.

please, can anyone help me?

I remember watching a tutorial video about variables in GD and came across this vid. He uses waves as an example to explain variables similar to you on your creation.

I do remember him explaining and showing how to add enemies in waves using variables.

Hope it could help.

The key is the picking of the enemy. This is rough and might need tweaking.

Variables.
Level =0
Max =1
Remaining =0
EnemyNumber=0

(let’s say the enemies were enemy1, enemy2 and so on and in a group named EnemyGroup)

Example start of wave
Level +1
RemainingEnemies=level (or some other formula)
MaxEnemy = min(MaxEnemy+1, highest enemy number)
Start spawn timer

FYI, min() takes the minimal number.
min(3,10) would return 3
min(3,1) would return 1

Using min() here prevents the MaxMaxEnemy from being higher the maximum enemy.

You could either create a wave list using an array or pick an enemy each time the timer elapses

Timer >3
RemainingEnemies > 0
Resart timer

Set enemyNumber = RandomInRange(min(trunc (MaxEnemy) , RemainingEnemies ))
Add object by name from EnemyGroup
The enemy name would be
“Enemy” + ToString(number)

Remaining - enemyNumber

Using MaxEnemy would allow you to gradually increase the maximum enemy. It’s up to you.

Either after the last enemy is killed (number in scene is 0 and remaining is 0) or a time limit then the next wave would begin.

My concept choose a number between 1 and either the max enemy or the number of enemies left in the wave.

1 Like

hi keith,
i’m using arrays but it’s still very challenging and repetitive to create hundreds of waves of enemies.
if the player is so good that he survives all the waves I create he would find himself without enemies.
for this reason I would need to create an infinite automatic system.
what i would like to achieve is to create a difficulty index and assign a degree of danger to each enemy.
every time the enemies are defeated increase the number of the wave and therefore increase the difficulty value to then create enemies in relation to that value
example:
enemy1 danger =1
enemy2 danger =2
enemy3 danger =3

wave 1 - difficulty =5
create 3 enemy1 and 1 enemy2 or 1 enemy3 and 1 enemy2

wave2 -difficulty =10
create 2 enemies2 -3 enemies1-1 enemy3 or 2 enemies3-1 enemy2 -2 enemies1

please help me i really need it

What type of game is it? Is an enemy spawned every X seconds? You said you’re using an array. Do you want to do the math as the enemies are being spawned or create an array of enemies at the beginning of the wave and then use that array to spean the enemies?

Did you try to build something with what I suggested in my previous reply? Does any of the ideas seem useful?

1 Like

the game is a topdown Survivor shooter similar to vampire Survivor. yes I’m currently writing the enemies to be created on an Array but I would like them to be created randomly starting from a low difficulty level and going up


this is what i’m using but i’m not satisfied because i have to create the waves by writing which and how many enemies to create

Here’s a test project that I made based on a simplified version of my original post.

3 variables.

Wave starts a 0, it’s the wave
Remaining starts at 0 and is the remaining count
Rand starts at 0 and is the Random enemy between 1 and 3.

Here are the events.

I used a button to start each wave and a text object to display the wave and the random enemies.

This is the output. It seems to work. The enemy values always total up to equal the level.

Variables

For testing, I added a force to the spawned enemy and then deleted it when it collided with the button.

Min(3,Remaining ) is used with RandomInRange() so it picks a number from 1 to the smaller number, either 3 or the remaining number.

1 Like

oooh thank you so much keith that looks awesome! one last question why did you set that .5 in the spawn timer? if i remove the . it works.
how can i create waves when enemies are defeated without having to repress the button to respawn them

I used.5 for testing. I wanted to run the waves as quick as possible instead of waiting.

As far as starting a wave, that’s up to you. You could start a new wave when the remaining variable is zero. You could also check if the enemies are all dead or use a timer or wait.

Remaining is 0
Count of enemies in scene is zero
Start a new wave

Or

Remaining is zero
Start a timer

If remaining is zero
Time elapsed > 5
Delete timer
Start next wave

It all depends in how you want to do it.

1 Like

where am I going wrong?
I would like that when the timer is exceeded and the enemies are eliminated you start a new wave


last thing for the creation of enemies do you think it is possible to set a danger value instead of the number of enemies?
if it is possible to modify this good otherwise I will find a way to manage it in this other way

You merged both features, the spawn and the next wave. They need to be seperate.

One event to spawn and one event to start a wave.

Whats a danger value?

assign a certain danger value to the enemies
for example, enemy 1,2 and 3 have a value of 1 while enemy 4,5,6 have a value of 2
so create the enemies in relation to that value and not to the number
I hope I explained myself correctly.
if it were possible I would have wanted this to happen otherwise I will find a way to manage the waves with the number as it is now.

also forgive my ignorance but I can’t set the events

I don’t have the time today for anything too in depth. The current method could be used to pick the level and then you could pick an object in that level using another random number.

There are so many different ways to do that. Most would involve picking a random item from a array based on the Rand value. You could use a different event for each level or use an array of arrays. The arrays would contain the object names arranged by level.

Another method would to be to build the enemy name to be used with create object by name.

Again, I don’t have the time to expand on either concept. Maybe, tomorrow if you’re still stuck.

1 Like

yes I’ve been looking for a solution for a long time.

I seem to have lost my test project. I might not have saved it. Anyways, my concept uses the last version. It uses the value in Rand for the enemy level and then creates another random number to pick an object name of that level.

I created an array of arrays. It’s also called a 2-dimensional array in some languages.

Here’s s the variable.


The first element or child is the level and the array within each element is a list of object names.

Meaning Waves[0][0] thru Waves[0][2] are level 0 enemy object names. I added fewer enemies to each array to test the concept. The object name arrays can be of any size. My event uses the size of the the choose array to choose a random object name from the list. Since the original events for Rand picks a number between 1 and 3, you could either add a dummy index 0 and just use indexes 1 thru 3 or you could subtract 1 from Rand for the first index.

Something like

The trouble with using 0 to 2 for Rand is that you can’t use it to reduce the remaining count since remaining minus 0 wouldn’t do anything.

1 Like

hello sorry for my absence but this period I am very busy with work. I did as described above but how do I create the enemies then?
I attach the project if you can take a look I would be grateful

I don’t have time to look at your project. I’ll reread this later if I get the chance.

In my example the array of arrays would have the object names that would be in a group.

So, the object name would come from the array using the first random number for the first index and the 2nd random number for the 2nd index.

Create object by name waves[Rand][RandomEnemy] from groupName

For simplicity, I used the object names of a, b, c followed by a number but the object could be named anything as long as they were in the array.

1 Like

OK, thanks a lot @Keith_1357

1 Like

hello sorry if I come back to this post again can you help me with the distribution of events
I would like to use a reset timer for enemy creation