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