mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
added new feature, player respawn in area if a spawn point is set
-- set /area_addspawn ID -- unset /area_delspawn ID
This commit is contained in:
parent
dfcb39216e
commit
8b2a291531
@ -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
|
||||
|
@ -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 = "<ID>",
|
||||
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 = "<ID>",
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user