improve basic tool system
This commit is contained in:
parent
3458a6e29b
commit
abfeb2982c
2 changed files with 22 additions and 13 deletions
|
@ -1,21 +1,33 @@
|
|||
import Make from "@rbxts/make"
|
||||
import { World, useEvent } from "@rbxts/matter"
|
||||
import { Workspace } from "@rbxts/services"
|
||||
import { PlayerCharacter } from "ReplicatedStorage/ecs/components"
|
||||
import { ServerState } from "ReplicatedStorage/ecs/state"
|
||||
import { getEvent } from "ReplicatedStorage/remotes"
|
||||
|
||||
function toolHandler(world: World, state: ServerState): void {
|
||||
const activateToolEvent = getEvent("activateToolEvent")
|
||||
const equipToolEvent = getEvent("equipToolEvent")
|
||||
|
||||
for (const [_, character] of world.query(PlayerCharacter)) {
|
||||
for (const [_, player] of useEvent(activateToolEvent, "OnServerEvent")) {
|
||||
state.logger.Info("{@player} activated the tool {@tool}", player, character.equippedTool)
|
||||
if (character.player !== player) continue
|
||||
}
|
||||
if (!character.equippedTool) continue
|
||||
|
||||
for (const [_, player, untypedHitPos] of useEvent(activateToolEvent, "OnServerEvent")) {
|
||||
const hitPos = untypedHitPos as Vector3
|
||||
|
||||
for (const [_, player] of useEvent(equipToolEvent, "OnServerEvent")) {
|
||||
state.logger.Info("{@player} equipped the tool {@tool}", player, character.equippedTool)
|
||||
if (character.player !== player) continue
|
||||
state.logger.Info("{@player} activated the tool {@tool}", player, character.equippedTool)
|
||||
|
||||
// TODO: Fix this logic!
|
||||
// We don't want a bunch of if statements...
|
||||
|
||||
// example tool - spawns a part at cursor pos
|
||||
if (character.equippedTool.Name === "example tool") {
|
||||
Make("Part", {
|
||||
Position: hitPos,
|
||||
Anchored: false,
|
||||
Parent: Workspace
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue