Bluefield revised this gist . Go to revision
2 files changed, 124 insertions
brick-spawner-client.lua(file created)
| @@ -0,0 +1,61 @@ | |||
| 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(file created)
| @@ -0,0 +1,63 @@ | |||
| 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 | |
Newer
Older