From a8b217d45e6b5c21cd524d94d15f38802b375588 Mon Sep 17 00:00:00 2001 From: reidlab Date: Sat, 12 Aug 2023 02:21:43 -0700 Subject: [PATCH] fix resetting, add comments --- readme.md | 1 - .../ecs/systems/client/customReset.ts | 18 +++++++++++++++ .../ecs/systems/server/customReset.ts | 23 +++++++++++++++++++ .../ecs/systems/server/healthRegenerates.ts | 2 +- .../server/playersArePlayerCharacters.ts | 2 +- .../systems/server/playersRagdollOnDeath.ts | 4 +++- 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/ReplicatedStorage/ecs/systems/client/customReset.ts create mode 100644 src/ServerScriptService/ecs/systems/server/customReset.ts diff --git a/readme.md b/readme.md index 7907ef1..6d48048 100644 --- a/readme.md +++ b/readme.md @@ -26,6 +26,5 @@ An in-dev game that I plan to make a shooter game out of. # Fixes ### High Priority -* Currently, when resetting, sometimes your health goes back up. This is due to the reconciliation of health. Simply put, your health is not being set to zero inside of our entity component system, due to us not having the reset event currently like that. See it here: [StarterGui.SetCore](https://create.roblox.com/docs/reference/engine/classes/StarterGui#SetCore) It uses BindableEvents. #### Medium priority ##### Low priority \ No newline at end of file diff --git a/src/ReplicatedStorage/ecs/systems/client/customReset.ts b/src/ReplicatedStorage/ecs/systems/client/customReset.ts new file mode 100644 index 0000000..e4dcaeb --- /dev/null +++ b/src/ReplicatedStorage/ecs/systems/client/customReset.ts @@ -0,0 +1,18 @@ +import { World, useEvent } from "@rbxts/matter" +import { StarterGui } from "@rbxts/services" +import { clientState } from "ReplicatedStorage/ecs/state" +import { getEvent } from "ReplicatedStorage/remotes" + +const resetButtonCallback = new Instance("BindableEvent") +StarterGui.SetCore("ResetButtonCallback", resetButtonCallback) + +getEvent("resetButton") + +function customReset(_: World, _client: clientState): void { + const resetButtonEvent = getEvent("resetButton") + for (const [,] of useEvent(resetButtonCallback, "Event")) { + resetButtonEvent.FireServer() + } +} + +export = customReset \ No newline at end of file diff --git a/src/ServerScriptService/ecs/systems/server/customReset.ts b/src/ServerScriptService/ecs/systems/server/customReset.ts new file mode 100644 index 0000000..ad8546a --- /dev/null +++ b/src/ServerScriptService/ecs/systems/server/customReset.ts @@ -0,0 +1,23 @@ +import { World, useEvent } from "@rbxts/matter" +import { Health, Model, PlayerCharacter } from "ReplicatedStorage/ecs/components" +import { getEvent } from "ReplicatedStorage/remotes" + +getEvent("resetButton") + +function customReset(world: World): void { + const resetButtonEvent = getEvent("resetButton") + for (const [, player] of useEvent(resetButtonEvent, "OnServerEvent")) { + for (const [id, playerCharacter, _model, health] of world.query(PlayerCharacter, Model, Health)) { + if (playerCharacter.player !== player) continue + world.insert( + id, + health.patch({ + health: 0, + regeneration: 0 + }) + ) + } + } +} + +export = customReset \ No newline at end of file diff --git a/src/ServerScriptService/ecs/systems/server/healthRegenerates.ts b/src/ServerScriptService/ecs/systems/server/healthRegenerates.ts index d941ac0..047371d 100644 --- a/src/ServerScriptService/ecs/systems/server/healthRegenerates.ts +++ b/src/ServerScriptService/ecs/systems/server/healthRegenerates.ts @@ -2,7 +2,7 @@ import { useThrottle, World } from "@rbxts/matter" import { Health } from "ReplicatedStorage/ecs/components" /** - * @todo + * Health components regenerate health based on the regeneration value. */ function healthRegenerates(world: World): void { for (const [id, health] of world.query(Health)) { diff --git a/src/ServerScriptService/ecs/systems/server/playersArePlayerCharacters.ts b/src/ServerScriptService/ecs/systems/server/playersArePlayerCharacters.ts index 58c6fbd..8e3a5c2 100644 --- a/src/ServerScriptService/ecs/systems/server/playersArePlayerCharacters.ts +++ b/src/ServerScriptService/ecs/systems/server/playersArePlayerCharacters.ts @@ -4,7 +4,7 @@ import { Health, Model, PlayerCharacter } from "ReplicatedStorage/ecs/components import { CharacterRigR6 } from "@rbxts/character-promise" /** - * @todo + * Player characters are marked with the "PlayerCharacter" component, "Health" component, and "Model" component. */ function playersArePlayerCharacters(world: World): void { Players.GetPlayers().forEach((player, _) => { diff --git a/src/ServerScriptService/ecs/systems/server/playersRagdollOnDeath.ts b/src/ServerScriptService/ecs/systems/server/playersRagdollOnDeath.ts index a6df6e0..87df53f 100644 --- a/src/ServerScriptService/ecs/systems/server/playersRagdollOnDeath.ts +++ b/src/ServerScriptService/ecs/systems/server/playersRagdollOnDeath.ts @@ -2,7 +2,9 @@ import { World, useEvent } from "@rbxts/matter" import { Model, PlayerCharacter } from "ReplicatedStorage/ecs/components" /** - * @todo + * When players die, disconnect all Motor6D instances. + * + * The Motor6D instances are replaced with BallSocketContraints. */ function playersRagdollOnDeath(world: World): void { for (const [_, playerCharacter, model] of world.query(PlayerCharacter, Model)) {