From 539144f05b6dd92c5c1bc869a7ef8ae9f1b4b600 Mon Sep 17 00:00:00 2001 From: rnd Date: Sun, 13 Jan 2019 21:25:13 +0100 Subject: [PATCH] drop fix craft: several crafts at once --- commands.lua | 13 ++++++++----- init.lua | 8 ++++---- scripts/http/webcommands/webcommands.lua | 14 +++++++++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/commands.lua b/commands.lua index e485bb4..36c777a 100644 --- a/commands.lua +++ b/commands.lua @@ -488,11 +488,11 @@ basic_robot.give_drops = function(nodename, inv) -- gives apropriate drops when local i = 0; for k,v in pairs(drop.items) do if i > max_items then break end; i=i+1; - local rare = v.rarity or 0; + local rare = v.rarity or 1; if rare>0 and math.random(1, rare)==1 then dropname = v.items[math.random(1,#v.items)]; -- pick item randomly from list inv:add_item("main",dropname); - + break end end else @@ -756,8 +756,11 @@ basic_robot.commands.keyboard = { basic_robot.commands.craftcache = {}; -basic_robot.commands.craft = function(item, mode, idx, name) +basic_robot.commands.craft = function(item, mode, idx,amount, name) + amount = amount and tonumber(amount) or 1; + if amount<0 then amount = 1 end if not item then return false end + local cache = basic_robot.commands.craftcache[name]; if not cache then basic_robot.commands.craftcache[name] = {}; cache = basic_robot.commands.craftcache[name] end @@ -820,12 +823,12 @@ basic_robot.commands.craft = function(item, mode, idx, name) local inv = minetest.get_meta(pos):get_inventory(); for item,quantity in pairs(itemlist) do - local stack = ItemStack(item .. " " .. quantity); + local stack = ItemStack(item .. " " .. quantity*amount); if not inv:contains_item("main",stack) then return false end end for item,quantity in pairs(itemlist) do - local stack = ItemStack(item .. " " .. quantity); + local stack = ItemStack(item .. " " .. quantity*amount); inv:remove_item("main",stack); end diff --git a/init.lua b/init.lua index 8418458..72f1e43 100644 --- a/init.lua +++ b/init.lua @@ -25,7 +25,7 @@ basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes invento basic_robot.http_api = minetest.request_http_api(); -basic_robot.version = "2018/12/24a"; +basic_robot.version = "2019/01/13a"; basic_robot.gui = {}; local robogui = basic_robot.gui -- gui management basic_robot.data = {}; -- stores all robot related data @@ -86,8 +86,8 @@ function getSandboxEnv (name) return commands.pickup(r, name); end, - craft = function(item, idx,mode) - return commands.craft(item, mode, idx, name) + craft = function(item, idx,mode, amount) + return commands.craft(item, mode, idx, amount, name) end, pause = function() -- pause coroutine @@ -808,7 +808,7 @@ end local function setupid(owner) local privs = minetest.get_player_privs(owner); if not privs then return end local maxid = basic_robot.entry_count; - if privs.robot then maxid = basic_robot.advanced_count end -- max id's per user + if privs.robot or privs.puzzle then maxid = basic_robot.advanced_count end -- max id's per user basic_robot.ids[owner] = {id = 1, maxid = maxid}; --active id for remove control end diff --git a/scripts/http/webcommands/webcommands.lua b/scripts/http/webcommands/webcommands.lua index fe067ad..2916306 100644 --- a/scripts/http/webcommands/webcommands.lua +++ b/scripts/http/webcommands/webcommands.lua @@ -25,8 +25,18 @@ if not fetch then self.label(os.date("%X") ..', cmd : ' .. req) local i = string.find(req," !") if i then - run_commmand(string.sub(req,i+2)) + local cmd = string.sub(req,i+2) + if cmd == "players" then + local players = minetest.get_connected_players(); + out = {}; + for i = 1,#players do out[i] = players[i]:get_player_name() end + MT2web("online players : " .. table.concat(out,", ")) + else + run_commmand(cmd) + end end + + end end @@ -49,6 +59,8 @@ if not fetch then fetch({url = "http://".. address .. "/mtmsg/"..message, timeout = 5}, result) end MT2web("minetest robot started and listening.") + + self.listen(1) end