canvas_printer/draw.lua
2023-05-20 00:00:14 -04:00

151 lines
3.7 KiB
Lua

#!/usr/bin/env hydra-dragonfire
local escapes = require("escapes")
local client = require("client")()
client:enable("pkts")
client.pkts:subscribe("chat_msg")
client:connect()
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
--returns name from the user joined server message
--or nil if it was not that type of message
local function get_userjoined(message)
local joinlen = ("*** joined the game."):len()
local off = ("*** "):len()
if string.match(message,"*** %w+ joined the game.") then
print("naeme is ",string.sub(message,off,-joinlen))
return string.sub(message,off,-joinlen)
end
end
local function get_admin(message)
local joinlen = ("*** joined the game."):len()
local off = ("*** "):len()
if string.match(message,"*** %w+ joined the game.") then
print("naeme is ",string.sub(message,off,-joinlen))
return string.sub(message,off,-joinlen)
end
end
local file = io.open("inst.txt","r")
if file == nil then return end
local wait = 0
local maxwait = 30
local pos = {
pos100={x=-4000,y=1,z=0},
vel100={x=0,y=0,z=0},
pitch100=90,
yaw100=90,
keys={place=true},
wanted_range=50,
fov80=80
}
local pointed={under={x=-5,y=0,z=0},above={x=-5,y=0,z=0}}
local function readline(client)
local cmd = file:read()
if cmd == "say" then
client:send("chat_msg", {msg = file:read()})
end
if cmd == "print" then
io.write("\r[script] "..file:read())
end
if cmd == "println" then
print("[script] "..file:read())
end
if cmd == "exit" then
wait = maxwait
client:close()
return
end
if cmd == "draw" then
local slot = tonumber(file:read())
local d_at = {x=tonumber(file:read()),y=0,z=-tonumber(file:read())}
--pos.pos100.x = d_at.x *1000
--pos.pos100.y = d_at.y+1 *1000
--pos.pos100.z = d_at.z *1000
pointed.under = d_at
pointed.above = d_at
client:send("interact", {
action = "dig",
item_slot=slot,
pos=pos,
pointed=pointed
},false)
client:send("interact", {
action = "dig",
item_slot=slot,
pos=pos,
pointed=pointed
},false)
client:send("interact", {
action = "dig",
item_slot=slot,
pos=pos,
pointed=pointed
},false)
--client:send("interact", {
-- action = "dug",
-- item_slot=slot,
-- pos=pos,
-- pointed=pointed
--},true)
end
if cmd == "move" then
local d_at = {
x=tonumber(file:read()),
y=tonumber(file:read()),
z=tonumber(file:read())
}
pos.pos100.x = d_at.x *1000
pos.pos100.y = d_at.y *1000
pos.pos100.z = d_at.z *1000
client:send("player_pos", {
pos=pos
},true)
end
if cmd == "inv_fields" then
local formname = file:read()
local fields = loadstring(file:read())
print("sending feilds",formname)
if fields == nil then return end
client:send("inv_fields", {
formname=formname,
fields=fields()
},true)
end
if cmd == "wait" then
wait = tonumber(file:read())
end
end
local adminname = ""
local joined = false
while true do
local evt = client:poll(0.1)
if not evt then
break
end
if not evt or evt.type == "interrupt" or evt.type == "disconnect" then
break
elseif evt.type == "pkt" then
print("[chat] "..escapes.strip_all(evt.pkt_data.text))
elseif evt.type == "timeout" then
while wait == 0 do
readline(client)
end
wait = wait-1
end
end
client:close()