How should i do my boss movesets?

Hi, i am currently making a moveset system for npcs and bosses, currently is for bosses right now, and i was wondering if i am doing it correctly, for example, all the moves are managed in 1 script, but, i should instead make their respective oop module?, because what if i want the boss change movesets at certain health?, and more?, what should i stick to?

task.wait(.1)
local replicatedStorage = game:GetService("ReplicatedStorage")
local modulesfolder = replicatedStorage:WaitForChild("Modules")
local requireQueueModule = require(modulesfolder:WaitForChild("Queue"))

local key_ = "MovesetSystem"

local bossesfolder = workspace:WaitForChild("bosses")
local debris = game:GetService("Debris")
local movesetFolders = replicatedStorage:WaitForChild("movesets")

local works = workspace

local CurrentQueue = requireQueueModule.Fetch(key_) or requireQueueModule.New(key_)

print("initializing")

function SetupMovesets(model)
	if model then
		if model:FindFirstChild("Humanoid") or model:FindFirstChildWhichIsA("Humanoid") then
			local humano = model:WaitForChild("Humanoid") or model:FindFirstChildWhichIsA("Humanoid")
			if humano then
				task.wait()
				if model:HasTag("Boss") then
					if movesetFolders:FindFirstChild(tostring(model.Name)) then
						local MovesetFound = movesetFolders:WaitForChild(tostring(model.Name)) :: ModuleScript
						if MovesetFound then
							local require_moveset = require(MovesetFound)
							local key_new = model or model.Name

							local bossQueue_ = requireQueueModule.New(key_new) or requireQueueModule.Fetch(key_new)
							
							coroutine.wrap(function()
								while true do
									task.wait(.1)
									for _, moves in pairs(require_moveset["SkillLibrary"]["skills"]) do
										if type(moves) == "function" then
											bossQueue_:Add(function()
												moves()
											end, true, true)
										end
									end
								end
							end)()
						end
					end
				end				
			end
		end
	else
		warn("Doesn't exists")
	end
end

task.delay(0.1, function()
	for _, bosses in pairs(works:GetDescendants()) do
		if bosses then
			if bosses:HasTag("Boss") then
				print("setting".. bosses:GetFullName())
				SetupMovesets(bosses)
			end
		end
	end
end)

works.DescendantAdded:Connect(SetupMovesets)

Moveset for the npc :

local moveset = {}
moveset.Cache = {}
moveset.__index = moveset

moveset.SkillLibrary = {
	skills = {
		[1] = function()
			print("works?")
			task.wait(2)
		end,
		[2] = function()
			print("works 2 ?")
			task.wait(2)
		end,
	}
}

function moveset.New(model)
	assert(typeof(model) ~= nil, "Argument #1 of moveset.New cannot be nil.")
	
	local self = {
		model = model,
	}
	
	local Metatable = setmetatable(self, moveset)
	moveset.Cache[model] = Metatable
	
	return Metatable
end

type Function = (...any) -> any

return moveset

A different modulescript would be nice.

Additionally, if possible, I would make the boss hitreg and animations on the client-side.

Something a bit more advanced is to do with predicting if the boss will be staggered on the client side. These will provide the most accurate timing, as remotes are sent ordered.
(I.e, you attack on the clientside and boss instantly staggers, instead of waiting for server-feedback).

Replicate these to other clients with a remote, verify using timestamps.

2 Likes

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