diff --git a/mods/places/LICENSE.txt b/mods/places/LICENSE.txt new file mode 100644 index 0000000..dc44a2b --- /dev/null +++ b/mods/places/LICENSE.txt @@ -0,0 +1,11 @@ +License for Code +---------------- + +Copyright (C) 2016 cd2 (cdqwertz) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +http://www.gnu.org/licenses/lgpl-2.1.html diff --git a/mods/places/init.lua b/mods/places/init.lua new file mode 100644 index 0000000..f174867 --- /dev/null +++ b/mods/places/init.lua @@ -0,0 +1,69 @@ +places = {} +places.pos = {} +places.places_file = minetest.get_worldpath() .. "/places" +function places.register_place(name, pos) + places.pos[name] = pos +end + +function places.load_places() + local input = io.open(places.places_file, "r") + if input then + local str = input:read() + if str then + print("[INFO] places string : " .. str) + if minetest.deserialize(str) then + places.pos = minetest.deserialize(str) + end + else + print("[WARNING] places file is empty") + end + io.close(input) + else + print("[error] couldnt find places file") + end +end + +function places.save_places() + if places.pos then + local output = io.open(places.places_file, "w") + local str = minetest.serialize(places.pos) + output:write(str) + io.close(output) + end +end + +minetest.register_chatcommand("setplace", { + params = "", + description = "Set a place", + privs = {}, + 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 + end + return true, "Error couldnt find player " .. name + end, +}) + +minetest.register_on_joinplayer(function(player) + if places.pos then + for k, v in pairs(places.pos) do + player:hud_add({ + hud_elem_type = "waypoint", + name = k, + text = "", + number = 255, + world_pos = v + }) + end + end +end) + +places.load_places() diff --git a/mods/places/init.lua~ b/mods/places/init.lua~ new file mode 100644 index 0000000..f174867 --- /dev/null +++ b/mods/places/init.lua~ @@ -0,0 +1,69 @@ +places = {} +places.pos = {} +places.places_file = minetest.get_worldpath() .. "/places" +function places.register_place(name, pos) + places.pos[name] = pos +end + +function places.load_places() + local input = io.open(places.places_file, "r") + if input then + local str = input:read() + if str then + print("[INFO] places string : " .. str) + if minetest.deserialize(str) then + places.pos = minetest.deserialize(str) + end + else + print("[WARNING] places file is empty") + end + io.close(input) + else + print("[error] couldnt find places file") + end +end + +function places.save_places() + if places.pos then + local output = io.open(places.places_file, "w") + local str = minetest.serialize(places.pos) + output:write(str) + io.close(output) + end +end + +minetest.register_chatcommand("setplace", { + params = "", + description = "Set a place", + privs = {}, + 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 + end + return true, "Error couldnt find player " .. name + end, +}) + +minetest.register_on_joinplayer(function(player) + if places.pos then + for k, v in pairs(places.pos) do + player:hud_add({ + hud_elem_type = "waypoint", + name = k, + text = "", + number = 255, + world_pos = v + }) + end + end +end) + +places.load_places()