35 lines
No EOL
1.3 KiB
TypeScript
35 lines
No EOL
1.3 KiB
TypeScript
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")
|
|
|
|
for (const [_, character] of world.query(PlayerCharacter)) {
|
|
if (!character.equippedTool) continue
|
|
|
|
for (const [_, player, untypedHitPos] of useEvent(activateToolEvent, "OnServerEvent")) {
|
|
const hitPos = untypedHitPos as Vector3
|
|
|
|
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
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export = toolHandler |