]> git.lizzy.rs Git - coronaserver.git/blob - chest_control.lua
Add event-manager role
[coronaserver.git] / chest_control.lua
1 coronaserver.savedata.suspect_items = coronaserver.savedata.suspect_items or {}
2 minetest.register_lbm({
3         name = "coronaserver:chest_control",
4         nodenames = {"default:chest", "default:chest_locked", "currency:safe", "protector:chest"},
5         run_at_every_load = true,
6         action = function(pos)
7                 local meta = minetest.get_meta(pos)
8                 if not meta then return end
9                 local inv = meta:get_inventory()
10                 if not inv then return end
11                 for _, sitem in pairs(coronaserver.savedata.suspect_items) do
12                         if inv:contains_item("main", sitem) then
13                                 coronaserver.teamchat_message(nil, "Verdächtige Kiste bei Position " .. minetest.pos_to_string(pos))
14                         end
15                 end
16         end
17 }) 
18 minetest.register_chatcommand("add_suspect_item", {
19         description = "Mark an item as suspect",
20         param = "<itemstring>",
21         privs = {server = true},
22         func = function(name, param)
23                 if not param then return false, "Invalid Usage" end
24                 table.insert(coronaserver.savedata.suspect_items, param)
25                 return true, param .. " added to suspect items"
26         end
27 })
28 minetest.register_chatcommand("print_suspect_items", {
29         description = "Print all items that are marked as suspect",
30         param = "",
31         privs = {server = true},
32         func = function(name, param)
33                 return true, "Suspect items: " .. table.concat(coronaserver.savedata.suspect_items, ", ")
34         end
35 })
36 minetest.register_chatcommand("remove_suspect_item", {
37         description = "Remove the suspect Mark from an item",
38         param = "",
39         privs = {server = true},
40         func = function(name, param)
41                 local function f()
42                         for i, item in pairs(coronaserver.savedata.suspect_items) do
43                                 if item == param then
44                                         table.remove(coronaserver.savedata.suspect_items, i)
45                                         return 1 + f()
46                                 end
47                         end
48                         return 0
49                 end
50                 return true, "Removed " .. tostring(f()) .. " from list"
51         end
52 })