Add files via upload
parent
ddf2e3580d
commit
ded928d205
28
api.lua
28
api.lua
|
@ -10,15 +10,20 @@ was.register_symbol=function(symbol,f,info)
|
|||
was.info[symbol]=info
|
||||
end
|
||||
|
||||
was.new_user=function(name,def)
|
||||
was.user[name]=was.user[name] or {}
|
||||
was.user[name].nodepos=def.nodepos
|
||||
was.user[name].show_print=def.show_print
|
||||
was.user[name].global=was.user[name].global or {}
|
||||
was.user[name].delete_on_exit=def.delete_on_exit
|
||||
end
|
||||
|
||||
was.protected=function(pos)
|
||||
if was.is_pos(pos) then
|
||||
return minetest.is_protected(pos,was.userdata.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
was.chr=function(t)
|
||||
local a=string.byte(t)
|
||||
return (a>=65 and a<=90) or (a>=97 and a<=122) or t=="." or t=="_"
|
||||
|
@ -46,6 +51,10 @@ was.is_table=function(t)
|
|||
return type(t)=="table"
|
||||
end
|
||||
|
||||
was.nodepos=function()
|
||||
return was.user[was.userdata.name] and was.user[was.userdata.name].nodepos
|
||||
end
|
||||
|
||||
was.ilastuserdata=function()
|
||||
for i=was.userdata.index,#was.userdata.data,1 do
|
||||
if not was.userdata.data[i+1] or was.userdata.data[i].type=="bracket end" then
|
||||
|
@ -68,7 +77,7 @@ was.iuserdata=function(i)
|
|||
end
|
||||
|
||||
was.compiler=function(input_text,user)
|
||||
if type(input_text)~="string" or input_text:len()<2 then
|
||||
if type(input_text)~="string" or input_text:len()<2 or type(user)~="string" then
|
||||
return
|
||||
end
|
||||
input_text=input_text .."\n"
|
||||
|
@ -242,12 +251,11 @@ was.compiler=function(input_text,user)
|
|||
return 'ERROR: Missing ' .. nexts .. ' for "next"'
|
||||
end
|
||||
|
||||
|
||||
user=user or ":server:"
|
||||
was.user[user]=was.user[user] or {}
|
||||
was.user[user].global=was.user[user].global or {}
|
||||
|
||||
return was.run(output_data2,user)
|
||||
local msg=was.run(output_data2,user)
|
||||
if was.user[user].delete_on_exit then
|
||||
was.user[user]=nil
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
was.run_function=function(func_name,data,VAR,i,ii)
|
||||
|
|
16
gui.lua
16
gui.lua
|
@ -42,17 +42,13 @@ was.gui_delnumbers=function(text)
|
|||
return t
|
||||
end
|
||||
|
||||
was.gui=function(name,msg,other)
|
||||
was.gui=function(name,msg)
|
||||
|
||||
was.user[name]=was.user[name] or {
|
||||
text=(other and other.text or ""),
|
||||
inserttext="true",
|
||||
lines="off",
|
||||
bg="true",
|
||||
console="false",
|
||||
}
|
||||
was.user[name].inserttext= was.user[name].inserttext or "true"
|
||||
was.user[name].lines= was.user[name].lines or "off"
|
||||
was.user[name].bg= was.user[name].bg or "true"
|
||||
was.user[name].console= was.user[name].console or "false"
|
||||
|
||||
local text=(other and other.text) or was.user[name].text or ""
|
||||
local funcs=""
|
||||
local symbs="SYMBOLS,"
|
||||
local tx=17
|
||||
|
@ -82,7 +78,7 @@ was.gui=function(name,msg,other)
|
|||
|
||||
.. console
|
||||
|
||||
.."textarea[0,1.3;" ..tx ..",13;text;;" .. text .. "]"
|
||||
.."textarea[0,1.3;" ..tx ..",13;text;;" .. (was.user[name].text or "") .. "]"
|
||||
.."label[0,0.6;".. minetest.colorize("#00FF00",(msg or "")) .."]"
|
||||
.."button[-0.2,-0.2;1.3,1;run;Run]"
|
||||
.."button[0.8,-0.2;1.3,1;save;Save]"
|
||||
|
|
61
init.lua
61
init.lua
|
@ -28,14 +28,64 @@ minetest.register_privilege("was", {
|
|||
})
|
||||
|
||||
|
||||
minetest.register_node("was:computer_closed", {
|
||||
description = "Computer",
|
||||
tiles = {
|
||||
"was_pc_outside.png",
|
||||
},
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2="facedir",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.3, 0.5, -0.43, 0.5},
|
||||
}
|
||||
},
|
||||
groups = {oddly_breakable_by_hand = 3,was_component=1},
|
||||
on_punch = function(pos, node, player, pointed_thing)
|
||||
local name=player:get_player_name() or ""
|
||||
if minetest.get_meta(pos):get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true}) then
|
||||
minetest.swap_node(pos,{name="was:computer"})
|
||||
end
|
||||
end,
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||
minetest.registered_nodes["was:computer"].on_rightclick(pos, node, player, itemstack, pointed_thing)
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
return minetest.registered_nodes["was:computer"].can_dig(pos, player)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("was:computer", {
|
||||
description = "Computer",
|
||||
tiles = {"default_steel_block.png"},
|
||||
tiles = {
|
||||
"was_pc_board.png",
|
||||
"was_pc_outside.png",
|
||||
"was_pc_screen.png",
|
||||
"was_pc_outside.png",
|
||||
"was_pc_outside.png",
|
||||
"was_pc_screen.png",
|
||||
},
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2="facedir",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.3, 0.5, -0.43, 0.5},
|
||||
{-0.5, -0.5, 0.48, 0.5, 0.3, 0.5},
|
||||
}
|
||||
},
|
||||
groups = {oddly_breakable_by_hand = 3,was_component=1},
|
||||
on_punch = function(pos, node, player, pointed_thing)
|
||||
minetest.swap_node(pos,{name="was:computer_closed"})
|
||||
end,
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name() or "")
|
||||
meta:get_inventory():set_size("storage", 50)
|
||||
minetest.swap_node(pos,"was:computer_closed")
|
||||
end,
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||
local meta=minetest.get_meta(pos)
|
||||
|
@ -44,11 +94,10 @@ minetest.register_node("was:computer", {
|
|||
if meta:get_string("owner")=="" then
|
||||
return
|
||||
end
|
||||
local text=minetest.deserialize(meta:get_string("text"))
|
||||
was.gui(name,"",{text=text})
|
||||
if was.user[name] and not was.user[name].nodepos then
|
||||
was.user[name].nodepos=pos
|
||||
end
|
||||
minetest.swap_node(pos,{name="was:computer"})
|
||||
was.new_user(name,{nodepos=pos,show_print=true})
|
||||
was.user[name].text=minetest.deserialize(meta:get_string("text"))
|
||||
was.gui(name)
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
|
|
43
register.lua
43
register.lua
|
@ -235,8 +235,8 @@ was.register_function("node.add",{
|
|||
if n and n.buildable_to==false then
|
||||
return
|
||||
end
|
||||
if was.user[was.userdata.name].nodepos then
|
||||
local inv=minetest.get_meta(was.user[was.userdata.name].nodepos):get_inventory()
|
||||
if was.nodepos then
|
||||
local inv=minetest.get_meta(was.nodepos):get_inventory()
|
||||
if not inv:contains_item("storage",name) then
|
||||
return
|
||||
end
|
||||
|
@ -251,13 +251,13 @@ was.register_function("node.remove",{
|
|||
info="remove node (pos)",
|
||||
action=function(pos)
|
||||
if was.is_pos(pos) and not minetest.is_protected(pos,was.userdata.name) then
|
||||
if was.user[was.userdata.name].nodepos then
|
||||
if was.nodepos then
|
||||
local n=minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local player=minetest.get_player_by_name(was.userdata.name)
|
||||
if n and ((n.can_dig and player and n.can_dig(pos, player)==false) or (n.pointable==false) or n.drop=="") then
|
||||
return
|
||||
end
|
||||
minetest.get_meta(was.user[was.userdata.name].nodepos):get_inventory():add_item("storage",minetest.get_node(pos).name)
|
||||
minetest.get_meta(was.nodepos):get_inventory():add_item("storage",minetest.get_node(pos).name)
|
||||
end
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
|
@ -328,11 +328,10 @@ was.register_function("nodetimer.start",{
|
|||
privs={was=true},
|
||||
info="Start node timer (<time> <nothing or pos>) to start on another node requires was privilege ",
|
||||
action=function(n,pos)
|
||||
local u=was.user[was.userdata.name]
|
||||
if was.protected(pos) then
|
||||
return
|
||||
elseif not pos and n and u and u.nodepos and was.is_number(n) then
|
||||
minetest.get_node_timer(u.nodepos):start(n)
|
||||
elseif not pos and was.nodepos and was.is_number(n) then
|
||||
minetest.get_node_timer(was.nodepos):start(n)
|
||||
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_number(n) and was.is_pos(pos) then
|
||||
minetest.get_node_timer(pos):start(n)
|
||||
end
|
||||
|
@ -344,11 +343,10 @@ was.register_function("nodetimer.stop",{
|
|||
privs={was=true},
|
||||
info="Stop node timer (nothing or pos) to stop on another node requires was privilege ",
|
||||
action=function(pos)
|
||||
local u=was.user[was.userdata.name]
|
||||
if was.protected(pos) then
|
||||
return
|
||||
elseif not pos and n and u and u.nodepos then
|
||||
minetest.get_node_timer(u.nodepos):stop()
|
||||
elseif not pos and was.nodepos then
|
||||
minetest.get_node_timer(was.nodepos):stop()
|
||||
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
|
@ -362,11 +360,11 @@ was.register_function("mesecon.on",{
|
|||
privs={was=true},
|
||||
info="Set mesecon on (nothing or pos) to effect another node requires was privilege ",
|
||||
action=function(pos)
|
||||
local u=was.user[was.userdata.name]
|
||||
|
||||
if was.protected(pos) then
|
||||
return
|
||||
elseif not pos and n and u and u.nodepos then
|
||||
mesecon.receptor_on(u.nodepos)
|
||||
elseif not pos and was.nodepos then
|
||||
mesecon.receptor_on(was.nodepos)
|
||||
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
|
||||
mesecon.receptor_on(pos)
|
||||
end
|
||||
|
@ -377,11 +375,11 @@ was.register_function("mesecon.off",{
|
|||
privs={was=true},
|
||||
info="Set mesecon off (nothing or pos) to effect another node requires was privilege ",
|
||||
action=function(pos)
|
||||
local u=was.user[was.userdata.name]
|
||||
|
||||
if was.protected(pos) then
|
||||
return
|
||||
elseif not pos and n and u and u.nodepos then
|
||||
mesecon.receptor_off(u.nodepos)
|
||||
elseif not pos and was.nodepos then
|
||||
mesecon.receptor_off(was.nodepos)
|
||||
elseif pos and minetest.check_player_privs(was.userdata.name,{was=true}) and was.is_pos(pos) then
|
||||
mesecon.receptor_off(pos)
|
||||
end
|
||||
|
@ -392,12 +390,10 @@ was.register_function("mesecon.send",{
|
|||
privs={was=true},
|
||||
info="Send a mesecon signal (nothing or pos) to effect another node requires was privilege ",
|
||||
action=function(pos)
|
||||
local u=was.user[was.userdata.name]
|
||||
|
||||
if was.protected(pos) then
|
||||
return
|
||||
elseif not pos and n and u and u.nodepos then
|
||||
local p=u.nodepos
|
||||
elseif not pos and was.nodepos then
|
||||
local p=was.nodepos
|
||||
mesecon.receptor_on(p)
|
||||
minetest.after(1, function(p)
|
||||
mesecon.receptor_off(p)
|
||||
|
@ -448,7 +444,7 @@ was.register_function("entity.spawn_item",{
|
|||
info="Spawn item (pos name)",
|
||||
action=function(pos,name)
|
||||
if was.is_pos(pos) and was.is_string(name) and minetest.registered_items[name] then
|
||||
local inv=minetest.get_meta(was.user[was.userdata.name].nodepos):get_inventory()
|
||||
local inv=minetest.get_meta(was.nodepos):get_inventory()
|
||||
if not inv:contains_item("storage",name) then
|
||||
return
|
||||
end
|
||||
|
@ -466,7 +462,7 @@ was.register_function("entity.remove_item",{
|
|||
for _, ob in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
||||
local en=ob:get_luaentity()
|
||||
if en and en.name=="__builtin:item" then
|
||||
minetest.get_meta(was.user[was.userdata.name].nodepos):get_inventory():add_item("storage",en.itemstring)
|
||||
minetest.get_meta(was.nodepos):get_inventory():add_item("storage",en.itemstring)
|
||||
en.object:remove()
|
||||
end
|
||||
end
|
||||
|
@ -578,7 +574,8 @@ was.register_function("if",{
|
|||
was.register_function("print",{
|
||||
packed=true,
|
||||
action=function(a)
|
||||
if was.user[was.userdata.name] then
|
||||
if not was.user[was.userdata.name].show_print then
|
||||
elseif was.user[was.userdata.name] then
|
||||
local ud=was.user[was.userdata.name]
|
||||
local s=""
|
||||
for i,v in ipairs(a) do
|
||||
|
|
Loading…
Reference in New Issue