Last active 1785727679

brick-spawner-client.lua Raw
1--!strict
2
3local ui = require("@rave/ui")
4local net = require("@rave/net")
5local state = require("@rave/state")
6local schema = require("@rave/schema")
7
8local enabled = state.watch("brick-rain/enabled")
9
10local set_enabled = net.event(
11 "brick-rain/set-enabled",
12 schema.boolean()
13)
14
15ui.mount(function()
16 return ui.panel {
17 align = "top-left",
18 width = 220,
19 padding = 12,
20 gap = 8,
21 color = "#101827E8",
22
23 children = {
24 ui.text {
25 text = "BRICK RAIN",
26 font_size = 20,
27 color = "#FFFFFF",
28 },
29
30 ui.text {
31 text = function()
32 return enabled()
33 and "Status: Spawning 20/sec"
34 or "Status: Stopped"
35 end,
36 color = function()
37 return enabled() and "#58E58C" or "#FF6B6B"
38 end,
39 },
40
41 ui.button {
42 text = function()
43 return enabled()
44 and "Stop spawning"
45 or "Start spawning"
46 end,
47 color = function()
48 return enabled() and "#B83E4B" or "#278C55"
49 end,
50 selected = function()
51 return enabled()
52 end,
53 accessibility_label = "Toggle brick spawning",
54
55 pressed = function()
56 set_enabled:send(not enabled())
57 end,
58 },
59 },
60 }
61end)
brick-spawner-server.lua Raw
1--!strict
2
3local world = require("@rave/world")
4local math3d = require("@rave/math")
5local task = require("@rave/task")
6local net = require("@rave/net")
7local state = require("@rave/state")
8local schema = require("@rave/schema")
9
10local matches = world.query {
11 kind = "part",
12 name = "Part0",
13}
14
15local source = assert(matches[1], "Could not find a brick named Part0")
16
17local RATE = 20
18local LIFETIME = 20
19
20local enabled = state.create(
21 "brick-rain/enabled",
22 true,
23 schema.boolean()
24)
25
26local set_enabled = net.event(
27 "brick-rain/set-enabled",
28 schema.boolean()
29)
30
31set_enabled:connect(function(_player, value)
32 enabled:set(value)
33end)
34
35while true do
36 if enabled:get() then
37 local brick = world.spawn {
38 kind = "block",
39 name = "BrickRain",
40 position = source.position + math3d.vector3.new(
41 math.random(-50, 50) / 10,
42 -(source.size.y / 2 + 2),
43 math.random(-50, 50) / 10
44 ),
45 size = math3d.vector3.new(
46 math.random(5, 15) / 10,
47 math.random(5, 15) / 10,
48 math.random(5, 15) / 10
49 ),
50 physics = {
51 enabled = true,
52 bounciness = 0.4,
53 },
54 }
55
56 task.spawn(function()
57 task.sleep(LIFETIME)
58 brick:destroy()
59 end)
60 end
61
62 task.sleep(1 / RATE)
63end