Add more
This commit is contained in:
parent
f7bb6c8137
commit
5769eca2f2
5 changed files with 194 additions and 57 deletions
1
00_mbs.lua
Normal file
1
00_mbs.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
assert(loadfile("rom/programs/mbs.lua", _ENV))('startup', "rom/programs/mbs.lua")
|
||||||
19
31_startup.lua
Normal file
19
31_startup.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
-- apioframe ni
|
||||||
|
-- sponsored by XNL
|
||||||
|
|
||||||
|
local modules = {
|
||||||
|
"track/client.lua",
|
||||||
|
"minit.lua",
|
||||||
|
-- "shrekFly.lua",
|
||||||
|
"carrotpay/carrotpay.lua"
|
||||||
|
}
|
||||||
|
|
||||||
|
local functions = {}
|
||||||
|
|
||||||
|
for k, v in pairs(modules) do
|
||||||
|
local f = loadstring("shell.run('" .. v .. "'); return 0")
|
||||||
|
setfenv(f, _ENV)
|
||||||
|
table.insert(functions, f)
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel.waitForAll(table.unpack(functions))
|
||||||
126
client.lua
126
client.lua
|
|
@ -1,68 +1,88 @@
|
||||||
local modules = {}
|
local common = require("common")
|
||||||
|
local mods = peripheral.wrap("back")
|
||||||
local function getIndex(tab, val)
|
assert(mods, "Must be used on a Neural Interface")
|
||||||
local index = nil
|
assert(mods.canvas3d, "Overlay Glasses required")
|
||||||
for i, v in ipairs (tab) do
|
local canvas = mods.canvas3d()
|
||||||
if (v == val) then
|
|
||||||
index = i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return index
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local kinetic = peripheral.wrap("back")
|
|
||||||
local canvas = peripheral.wrap("back").canvas()
|
|
||||||
|
|
||||||
timer = os.startTimer(0.5)
|
|
||||||
canvas.clear()
|
canvas.clear()
|
||||||
|
local bc = canvas.create()
|
||||||
|
|
||||||
local group = canvas.addGroup({ 0, 0 })
|
local modem = (function()
|
||||||
local text = group.addText({ 5, 5 }, "")
|
local ms = {peripheral.find("modem")}
|
||||||
|
for i = 1, #ms do
|
||||||
|
if ms[i].isWireless() then
|
||||||
|
return ms[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)()
|
||||||
|
assert(modem, "Wireless Modem required")
|
||||||
|
modem.open(1080)
|
||||||
|
|
||||||
text.setText("this is NOT a client")
|
local blocks = {}
|
||||||
|
|
||||||
local moduleText = group.addText({ 5, 15 }, table.concat(modules, "\n"))
|
local function place(sx, sy, sz, name)
|
||||||
moduleText.setScale(0.5)
|
local box = bc.addBox(sx, sy, sz)
|
||||||
local function enableModule(module)
|
-- We're gonna wait for SwitchCraftCC/Plethora-Fabric#17
|
||||||
table.insert(modules, module)
|
--[[local frame = bc.addFrame({sx-1, sy-1, sz-1})
|
||||||
moduleText.setText(table.concat(modules, "\n"))
|
local text = frame.addText({0,0}, name)
|
||||||
|
local textobj = {
|
||||||
|
setPosition = frame.setPosition,
|
||||||
|
setRotation = text.setRotation,
|
||||||
|
setScale = text.setScale,
|
||||||
|
setText = text.setText,
|
||||||
|
}]]
|
||||||
|
|
||||||
|
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
|
||||||
|
local c = r*(16^6)+g*(16^4)+b*(16^2)+255
|
||||||
|
box.setColor(c)
|
||||||
|
box.setDepthTested(false)
|
||||||
|
--frame.setDepthTested(false)
|
||||||
|
return box, textobj
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disableModule(module)
|
local function mscan()
|
||||||
local idx = getIndex(modules, module)
|
|
||||||
table.remove(modules, idx)
|
|
||||||
moduleText.setText(table.concat(modules, "\n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function isModuleEnabled(module)
|
|
||||||
local idx = getIndex(modules, module)
|
|
||||||
return idx ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function checkKey()
|
|
||||||
while true do
|
while true do
|
||||||
local event, key, is_held = os.pullEvent("key")
|
local e, _, channel, _, data = os.pullEventRaw()
|
||||||
if keys.getName(key) == "g" then
|
if e == "modem_message" and channel == 1080 and type(data) == "table" and data.from == 1751 and data.to == os.getComputerID() then
|
||||||
if isModuleEnabled("flight") then
|
if data.type == "block" then
|
||||||
disableModule("flight")
|
local pass, x, y, z = common.checkBounds(data.x, data.y, data.z)
|
||||||
else
|
if pass then
|
||||||
enableModule("flight")
|
blocks[#blocks+1] = {
|
||||||
timer = os.startTimer(0.5)
|
x = x,
|
||||||
|
y = y,
|
||||||
|
z = z,
|
||||||
|
name = data.name,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elseif data.type == "clear" then
|
||||||
|
blocks = {}
|
||||||
|
bc.clear()
|
||||||
|
end
|
||||||
|
elseif e == "terminate" then
|
||||||
|
bc.clear()
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
local function recenter()
|
||||||
end
|
|
||||||
|
|
||||||
function flyEvent()
|
|
||||||
while true do
|
while true do
|
||||||
local _, tid = os.pullEvent("timer")
|
local x, y, z = gps.locate()
|
||||||
if tid == timer and isModuleEnabled("flight") then
|
if x then
|
||||||
timer = os.startTimer(0.5)
|
bc.recenter(x-math.floor(x+0.5), y-math.floor(y+0.5), z-math.floor(z+0.5))
|
||||||
kinetic.launch(0, -90, 4);
|
table.foreachi(blocks, function(_, block)
|
||||||
|
if not block.box then
|
||||||
|
block.box, block.text = place(block.x-x, block.y-y, block.z-z, block.name)
|
||||||
end
|
end
|
||||||
|
local bx, by, bz = block.x-x, block.y-y, block.z-z
|
||||||
|
block.box.setPosition(bx, by, bz)
|
||||||
|
local dist = math.sqrt(bx^2+by^2+bz^2)
|
||||||
|
block.box.setSize(dist/8, dist/8, dist/8)
|
||||||
|
--block.text.setPosition(bx, by, bz)
|
||||||
|
--block.text.setScale(math.sqrt(bx^2, by^2, bz^2)*2)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
sleep(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parallel.waitForAll(checkKey, flyEvent)
|
parallel.waitForAny(mscan, recenter)
|
||||||
29
common.lua
Normal file
29
common.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
local api = {}
|
||||||
|
|
||||||
|
local function xzbounds(num)
|
||||||
|
return num > -10001 and num < 10001
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ybounds(num)
|
||||||
|
return num > -65 and num < 321
|
||||||
|
end
|
||||||
|
|
||||||
|
api.checkBounds = function(x, y, z)
|
||||||
|
x, y, z = tonumber(x), tonumber(y), tonumber(z)
|
||||||
|
if not x then
|
||||||
|
return false, "Value x is not a number."
|
||||||
|
elseif not y then
|
||||||
|
return false, "Value y is not a number."
|
||||||
|
elseif not z then
|
||||||
|
return false, "Value z is not a number."
|
||||||
|
elseif not xzbounds(x) then
|
||||||
|
return false, "Value x = "..x.." is out of bounds."
|
||||||
|
elseif not ybounds(y) then
|
||||||
|
return false, "Value y = "..y.." is out of bounds."
|
||||||
|
elseif not xzbounds(z) then
|
||||||
|
return false, "Value z = "..z.." is out of bounds."
|
||||||
|
end
|
||||||
|
return true, x, y, z
|
||||||
|
end
|
||||||
|
|
||||||
|
return api
|
||||||
68
espeak.lua
Normal file
68
espeak.lua
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
-- ESpeak module for Minit
|
||||||
|
-- Copyright (C) 2023 AlexDevs
|
||||||
|
-- This software is licensed under the MIT license.
|
||||||
|
|
||||||
|
-- This code is based on CCSpeaks by SquidDev
|
||||||
|
-- https://github.com/SquidDev-CC/CCSpeaks
|
||||||
|
|
||||||
|
-- This module is made for SwitchCraft 3
|
||||||
|
-- A Chatbox license is required to use this module
|
||||||
|
-- Or use "guest" license
|
||||||
|
|
||||||
|
local module = {
|
||||||
|
name = "espeak",
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.define("espeak.volume", {
|
||||||
|
description = "The volume for ESpeak TTS",
|
||||||
|
default = 100,
|
||||||
|
type = "number"
|
||||||
|
})
|
||||||
|
|
||||||
|
local username
|
||||||
|
local function speak(message)
|
||||||
|
local voice = ""
|
||||||
|
local gender = math.random(1,2)
|
||||||
|
if gender == 1 then
|
||||||
|
voice = "m"..math.random(1,7)
|
||||||
|
elseif gender == 2 then
|
||||||
|
voice = "f"..math.random(1,5)
|
||||||
|
end
|
||||||
|
|
||||||
|
local url = "https://music.madefor.cc/tts?text=" .. textutils.urlEncode(message).."&voice=en-us%2B"..voice
|
||||||
|
local response, err = http.get { url = url, binary = true }
|
||||||
|
if not response then error(err, 0) end
|
||||||
|
|
||||||
|
local speaker = peripheral.find("speaker")
|
||||||
|
local decoder = require("cc.audio.dfpwm").make_decoder()
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local chunk = response.read(16 * 1024)
|
||||||
|
if not chunk then break end
|
||||||
|
|
||||||
|
local buffer = decoder(chunk)
|
||||||
|
while not speaker.playAudio(buffer, settings.get("espeak.volume")) do
|
||||||
|
os.pullEvent("speaker_audio_empty")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function run()
|
||||||
|
while true do
|
||||||
|
local _, user, msg = os.pullEvent("chat_ingame")
|
||||||
|
if user == username then
|
||||||
|
speak(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.init(init)
|
||||||
|
init.addTask(run)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.setup(neural)
|
||||||
|
local meta = neural.getMetaOwner()
|
||||||
|
username = meta.name
|
||||||
|
end
|
||||||
|
|
||||||
|
return module
|
||||||
Loading…
Add table
Add a link
Reference in a new issue