added logging api + added /goto_place
This commit is contained in:
parent
259d804acc
commit
c901c32974
@ -1,18 +1,39 @@
|
||||
default.LIGHT_MAX = 14
|
||||
default.log = {}
|
||||
default.log.level = 0
|
||||
default.log.mods = {}
|
||||
|
||||
function default.log.log(mod, level, message)
|
||||
if level > default.log.level then
|
||||
local level_name = ({"[info]", "[warning]", "[ERROR]"})[level]
|
||||
print("[" .. mod .. "]" .. level_name .. " " .. message)
|
||||
if default.log.mods[mod] then
|
||||
local color = ({"#00FF00", "#FFFF00", "#FF0000"})[level]
|
||||
minetest.chat_send_all(core.colorize(color, "[" .. mod .. "]" .. level_name .. " " .. message))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function default.log.register_mod(name)
|
||||
default.log.mods[name] = true
|
||||
end
|
||||
|
||||
function default.drop_item(pos,stack)
|
||||
if not(stack:is_empty()) then
|
||||
local p = vector.new(pos.x + math.random(0,10)/10-0.5, pos.y, pos.z+math.random(0,10)/10-0.5)
|
||||
minetest.add_item(p,stack)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function default.drop_items(pos, oldnode, oldmetadata, digger)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stack = inv:get_stack("main", i)
|
||||
if not stack:is_empty() then
|
||||
local p = { x = pos.x + math.random(0, 5)/5 - 0.5,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random(0, 5)/5 - 0.5
|
||||
}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
default.drop_item(pos,inv:get_stack("main", i))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -207,36 +207,16 @@ minetest.register_node("default:box", {
|
||||
after_dig_node = default.drop_items,
|
||||
})
|
||||
|
||||
default.treasure_chest_items = {"money:coin", "money:silver_coin", "default:ruby"}
|
||||
default.treasure_chest_items = {"money:coin", "money:silver_coin"}
|
||||
minetest.register_node("default:treasure_chest", {
|
||||
description = "Treasure Chest",
|
||||
tiles = {"default_treasure_chest.png"},
|
||||
groups = {choppy = 3},
|
||||
drop = "default:box",
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
local items = default.treasure_chest_items
|
||||
local item = items[math.random(#items)]
|
||||
inv:add_item("main", {name = item, count = math.random(1,3)})
|
||||
local item = items[math.random(#items)]
|
||||
inv:add_item("main", {name = item, count = math.random(1,3)})
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:from_table(oldmetadata)
|
||||
local inv = meta:get_inventory()
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stack = inv:get_stack("main", i)
|
||||
if not stack:is_empty() then
|
||||
local p = { x = pos.x + math.random(0, 5)/5 - 0.5,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random(0, 5)/5 - 0.5
|
||||
}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
local items = default.treasure_chest_items
|
||||
minetest.add_item(pos, {name = items[math.random(#items)], count = math.random(1,3)})
|
||||
minetest.add_item(pos, {name = items[math.random(#items)], count = math.random(1,3)})
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -37,7 +37,7 @@ function mobs.register_mob(name, def)
|
||||
if self.object:get_hp() <= 0 then
|
||||
if player and player:is_player() then
|
||||
xp.add_xp(player, def.xp or xp.get_xp(def.lvl, 10))
|
||||
if math.random(0,20) == 10 then
|
||||
if math.random(0,10) == 5 then
|
||||
minetest.spawn_item(self.object:getpos(),"potions:upgrading")
|
||||
else
|
||||
if def.drops then
|
||||
|
1
mods/places/depends.txt
Normal file
1
mods/places/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
@ -2,6 +2,7 @@ places = {}
|
||||
places.pos = {}
|
||||
places.places_file = minetest.get_worldpath() .. "/places"
|
||||
places.show_places = false
|
||||
|
||||
function places.register_place(name, pos)
|
||||
places.pos[name] = pos
|
||||
end
|
||||
@ -11,16 +12,16 @@ function places.load_places()
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
print("[INFO] places string : " .. str)
|
||||
print("[info] places string : " .. str)
|
||||
if minetest.deserialize(str) then
|
||||
places.pos = minetest.deserialize(str)
|
||||
end
|
||||
else
|
||||
print("[WARNING] places file is empty")
|
||||
print("[warning] places file is empty")
|
||||
end
|
||||
io.close(input)
|
||||
else
|
||||
print("[error] couldnt find places file")
|
||||
print("[ERROR] couldnt find places file")
|
||||
end
|
||||
end
|
||||
|
||||
@ -33,23 +34,39 @@ function places.save_places()
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("setplace", {
|
||||
minetest.register_chatcommand("add_place", {
|
||||
params = "<name>",
|
||||
description = "Set a place",
|
||||
description = "Add a place",
|
||||
privs = {server=true},
|
||||
func = function(name, text)
|
||||
if places.pos[text] then
|
||||
return true, "There already is a place named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
local pos = player:getpos()
|
||||
pos = {x=math.floor(pos.x), y=math.floor(pos.y), z=math.floor(pos.z)}
|
||||
places.pos[text] = pos
|
||||
places.save_places()
|
||||
return true, "Added a place named " .. text
|
||||
if not(player) then
|
||||
return true, "Error couldnt find player " .. name
|
||||
end
|
||||
return true, "Error couldnt find player " .. name
|
||||
places.pos[text] = player:getpos()
|
||||
places.save_places()
|
||||
return true, "Added a place named " .. text
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("goto_place", {
|
||||
params = "<name>",
|
||||
description = "Goto a place",
|
||||
privs = {},
|
||||
func = function(name, text)
|
||||
if not(places.pos[text]) then
|
||||
return true, "There is no place named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not(player) then
|
||||
return true, "Error couldnt find player " .. name
|
||||
end
|
||||
player:setpos(places.pos[text])
|
||||
|
||||
return true, "Teleported to " .. text
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user