diff --git a/mods/areas/api.lua b/mods/areas/api.lua index 83a8c9ac..131ffb1a 100755 --- a/mods/areas/api.lua +++ b/mods/areas/api.lua @@ -119,3 +119,33 @@ function areas:canInteractInArea(pos1, pos2, name, allow_open) return true end + + +--MFF DEBUT crabman(17/09/2015 ) respawn player in special area(event) if a spawn is set. +local dead_players = {} +minetest.register_on_dieplayer(function(player) + local player_name = player:get_player_name() + if not player_name then return end + local pos = player:getpos() + if pos then + dead_players[player_name] = pos + end +end) + + +minetest.register_on_respawnplayer(function(player) + local player_name = player:get_player_name() + if not player_name or not dead_players[player_name] then return false end + local pos = dead_players[player_name] + dead_players[player_name] = nil + if pos then + for _, area in pairs(areas:getAreasAtPos(pos)) do + if area.spawn then + player:setpos(area.spawn) + return true + end + end + end + return false +end) +--FIN diff --git a/mods/areas/chatcommands.lua b/mods/areas/chatcommands.lua index 7c1c4730..bf5ea433 100755 --- a/mods/areas/chatcommands.lua +++ b/mods/areas/chatcommands.lua @@ -424,3 +424,63 @@ minetest.register_chatcommand("area_info", { end, }) + +--MFF DEBUT crabman(17/09/2015 ) respawn player at in special area(event) if a spawn is set. +minetest.register_chatcommand("area_addspawn", { + params = "", + privs = areas.adminPrivs, + description = "Define special spawn for area", + func = function(name, param) + local id = param:match("^(%d+)") + if not id then + return false, "Invalid usage, see /help area_addspawn." + end + + id = tonumber(id) + if not id then + return false, "Error, Param id must be int." + end + + local player = minetest.get_player_by_name(name) + if not player then + return false, "Error, there is not player" + end + local pos = player:getpos() + if not pos then + return false, "Error, there is not pos." + end + + if not areas.areas[id] then + return false, "Area ".. id .." does not exist." + end + areas.areas[id].spawn = pos + areas:save() + return true, "spawn of area ".. id .." defined." + end +}) + +minetest.register_chatcommand("area_delspawn", { + params = "", + privs = areas.adminPrivs, + description = "Delete special spawn of area", + func = function(name, param) + local id = param:match("^(%d+)") + if not id then + return false, "Invalid usage, see /help area_delspawn." + end + + id = tonumber(id) + if not id then + return false, "Error, Param id must be int." + end + + if not areas.areas[id] then + return false, "Area ".. id .." does not exist." + end + areas.areas[id].spawn = nil + areas:save() + return true, "spawn of area ".. id .." deleted." + end +}) +-- FIN +