Skip to content

Instantly share code, notes, and snippets.

View maeriil's full-sized avatar

maeriil maeriil

View GitHub Profile
@maeriil
maeriil / run-ecs.ts
Created September 24, 2025 16:00
Schedular
import jabby from "@rbxts/jabby";
import { component, Entity, meta, Name, pair, tag, World } from "@rbxts/jecs";
import { ContextActionService, RunService } from "@rbxts/services";
import { SystemFunction } from "./definitions/types";
jabby.set_check_function(() => true);
const scheduler = jabby.scheduler.create();
const System = component<{
fn: (dt: number) => void;
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clientstore = require(ReplicatedStorage.client.clientstore)
local types = require(ReplicatedStorage.common.definitions.types)
local c = require(ReplicatedStorage.common.components)
local jecs = require(ReplicatedStorage.pkg.jecs)
return function(world: types.World)
local pair = jecs.pair
local sources = clientstore.Sources
type PlantEntries = { types.PlantConfig }
type PlantList = deque.Deque<{
plant: enums.Plant,
weight: number,
}>
local spawn_plants = {} :: { types.Tag }
local list = deque.new() :: PlantList
local spawner_folder, ENTRIES, spawner_part = setup_spawner(world)
local despawner_id = setup_despawner(world)
@maeriil
maeriil / roll_a_die.luau
Created August 16, 2025 08:09
selecting a random out of a bag
local function roll_a_die<T>(items: { Item<T> }, random: Random): T
if #items == 0 then
error("Items cannot be empty. This is a serious bug")
end
local weight_maps: { [number]: { types.Tag } } = {}
local sorted = table.clone(items)
table.sort(sorted, function(a, b)
return a.rarity < b.rarity
@maeriil
maeriil / mark_nearest_entity.luau
Last active August 16, 2025 05:53
An example of how I highlight a nearest entity to a player
return function(world: types.World)
local pair = jecs.pair
local sources = clientstore.Sources
return function()
local hrp = world:get(c.Client, c.BasePart)
if not hrp then
return
end
local interactable = sources.interactable
local function get_players_who_has_not_setup_houses()
local players_who_have_not_setup_house = {} :: { Player }
for i, player in Players:GetPlayers() do
local player_config = playersetupconfig[player]
local playerdata = playerdatastore[player]
if not player_config or not playerdata then
-- This means that player's data hasn't fully loaded yet. In this case, we simply ignore
-- and skip them until their data is ready
continue
@maeriil
maeriil / Scheduler.d.ts
Created December 9, 2024 02:56
Jecs Scheduler demo TS
import { Entity, World } from "@rbxts/jecs";
type System = {
callback: (world: World) => void;
id: number;
};
type Systems = Array<System>;
type Events = {
RenderStepped: Systems;
Heartbeat: Systems;
@maeriil
maeriil / index.d.ts
Created December 8, 2024 04:24
Planck TS types
type VoidCallback<T extends unknown[]> = (...args: T) => void;
type UnknownCallback<T extends unknown[]> = (...args: T) => unknown;
type SystemFn<T extends unknown[]> = VoidCallback<T> | UnknownCallback<T>;
type SystemTable<T extends unknown[]> = {
system: SystemFn<T>;
phase: unknown;
};
type System<T extends unknown[]> = SystemFn<T> | SystemTable<T>;
type EventLike =