How would I be able to make this wave system better?

Heya There!

I’m working on a wave-based, PVE game and I’m trying to format a wave system. I have a somewhat solid system, but it can be improved since I’ve encountered a few issues with it. One of them being that I don’t know how would I be able to add more variables to the system.

In the system, there is a dictionary named “WaveList” that, as you might’ve guessed, contains every single wave format. As of now, it only has two values being the enemy name and how many of the enemy is going to spawn. The issue is that I want to add more values to the dictionary. An example would be something like a 0.5 second delay per enemy spawn (And when I mean by that, I mean something like a basic enemy having 5 clones of itself that spawn every 0.5 seconds).

Of course, there are other issues with the system and some I might’ve not encountered yet. Here’s the two scripts and see what I can improve upon.

GameHandler

--[[MODULE REQUIRING]]--
local RoundHandler = require(script:WaitForChild("RoundHandler"))

--[[GAME]]--
--//Wave list & current waves
local CurrentWave = 1
local WaveList = { --//TBA
	[1] = {
		["Brickbattler"] = 5
	},
	[2] = {
		["Brickbattler"] = 15,
		["Rioter"] = 10
	},
	[3] = {
		["Test"] = 1
	}
}

--//Game Loop
task.wait(5)
CurrentWave = 3
RoundHandler:StartNewWave(WaveList,CurrentWave)

RoundHandler

--[[SERVICES]]--
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")

--[[REQUIRING]]--
local EntityHandler = require(ServerScriptService.Modules.EntityHandler)

--[[VARIABLES]]--
local BaseIntermissionTime = 25
local BaseWaveTime = 180
local EnemiesAlive = 0

--[[MODULE]]--
local RoundHandlerModule = {}


function RoundHandlerModule:PreperationTime()
	--//TBA
end

function RoundHandlerModule:IntermissionBreak()
	--//TBA
end

function RoundHandlerModule:StartNewWave(WaveList, CurrentWave)
	for EnemyName, AmountofEnemies in WaveList[CurrentWave] do
		EntityHandler:SpawnEntity(EnemyName,AmountofEnemies)
	end
end

return RoundHandlerModule

(Maybe move to Code Review ?)

What’s wrong with just putting a table (or OOP class even) for every enemy that contains information about the second delay per enemy spawn and how many clones it can spawn?

For any of those other issues, you could simply write one question per issue and explain each issue, citing the relevant code as necessary. You don’t want to make big questions with many issues, it’s very hard for most people to want to answer those. One thing at a time.

Thanks for clarifying, I’ll try to choose one problem at a time. Anyway, I’ve actually never considered using a table or OOP classes for such. I’m still fairly new to OOP and tables, so giving me an example would be nice.

I’m sure you know what I mean by “tables” because it’s just tables in tables. Nothing more than that (you showed me you can make a table in the code you gave). Let’s say your ["Brickbattler"] = 5 line of code is saying I want to spawn 5 brick battlers. Okay, fair.

Just write a table that says:

["Brickbattler"] = {
    secondDelayPerEnemySpawn = 0.5,
    clones = 5
}

The names don’t have to be exactly as it is above, change it however you want (but make sure they’re easy for you to read).

For OOP, try looking at resources and tutorials, then attempt to basically do conceptually the above example table I wrote and try to read from the object (OOP = Object Oriented Programming). When I mean “try to read”, literally make a test script. Just test your code, see that it prints out what you expect.

1 Like

Thanks for the help, I appreciate it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.