diff --git a/gui.lua b/gui.lua index ac40c86..558004e 100644 --- a/gui.lua +++ b/gui.lua @@ -1,3 +1,10 @@ +minetest.after(1, function() + for f,v in pairs(was.functions) do + table.insert(was.function_list,f) + end + table.sort(was.function_list,function(a,b) return a < b end) +end) + was.gui_addnumbers=function(text) text=text.."\n" for i=1,text:len(),1 do @@ -39,7 +46,6 @@ was.gui=function(name,msg,other) was.user[name]=was.user[name] or { text=(other and other.text or ""), - funcs={}, inserttext="true", lines="off", bg="true", @@ -62,10 +68,9 @@ was.gui=function(name,msg,other) symbs=symbs .. f .."," end - for f,v in pairs(was.functions) do - if minetest.check_player_privs(name,was.privs[f]) then - funcs=funcs .. f .."," - table.insert(was.user[name].funcs,f) + for _,v in pairs(was.function_list) do + if minetest.check_player_privs(name,was.privs[v]) then + funcs=funcs .. v .."," end end @@ -127,8 +132,6 @@ minetest.register_on_player_receive_fields(function(user, form, pressed) return end - local funcs=was.user[name].funcs - was.user[name].funcs={} was.user[name].text=pressed.text if was.user[name].text:find("%[") or was.user[name].text:find("%]") then @@ -165,7 +168,7 @@ minetest.register_on_player_receive_fields(function(user, form, pressed) if pressed.list and pressed.list~="IMV" then local n=pressed.list:gsub("CHG:","") - local f=funcs[tonumber(n)] + local f=was.function_list[tonumber(n)] local info=was.info[f] or "" if was.privs[f] then info=info .. "| Privs: " ..minetest.privs_to_string(was.privs[f]) diff --git a/init.lua b/init.lua index 27ca1d5..82f181a 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,6 @@ was={ functions={}, + function_list={}, function_packed={}, info={}, privs={}, @@ -13,7 +14,6 @@ dofile(minetest.get_modpath("was") .. "/api.lua") dofile(minetest.get_modpath("was") .. "/register.lua") dofile(minetest.get_modpath("was") .. "/gui.lua") - --minetest.register_chatcommand("was", { -- description = "World action script gui", -- func = function(name, param) diff --git a/register.lua b/register.lua index b2efb8b..9f5d7ac 100644 --- a/register.lua +++ b/register.lua @@ -355,7 +355,7 @@ was.register_function("nodetimer.stop",{ end }) --[[ -================= PLAYER ================= +================= MESECONS ================= --]] if minetest.get_modpath("mesecons") then was.register_function("mesecon.on",{ @@ -440,6 +440,41 @@ was.register_function("player.get_pos",{ end }) +--[[ +================= ENTIY ================= +--]] + +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() + if not inv:contains_item("storage",name) then + return + end + inv:remove_item("storage",name) + minetest.add_item(pos,name) + end + local p=minetest.get_player_by_name(name) + end +}) + +was.register_function("entity.remove_item",{ + info="Remove item (pos)", + action=function(pos) + if was.is_pos(pos) and not was.protected(pos) then + 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) + en.object:remove() + end + end + end + end +}) + + --[[ ================= MISC ================= --]]