wip
parent
4e6629335c
commit
c56c0535c7
89
api.lua
89
api.lua
|
@ -13,6 +13,9 @@ respawn.load = function()
|
|||
respawn.reset_respawns()
|
||||
end
|
||||
|
||||
-- Per team respawn
|
||||
respawn.team_respawn_points = respawn.load_db( "team_respawn" ) or {}
|
||||
|
||||
-- Server global named places/fine points of view
|
||||
respawn.places = respawn.load_db( "places" ) or {}
|
||||
|
||||
|
@ -44,6 +47,26 @@ end
|
|||
|
||||
|
||||
|
||||
-- Remove all teams' respawns
|
||||
respawn.reset_team_respawns = function()
|
||||
respawn.team_respawns = {}
|
||||
respawn.save_db( "team_respawns" , respawn.team_respawns )
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
respawn.set_team_respawn = function( team_name , spawn_id , data )
|
||||
spawn_id = spawn_id or 1
|
||||
if not team_name or type( team_name ) ~= "string" or team_name == "" then return false end
|
||||
if not respawn.team_respawn_points[ team_name ] then respawn.team_respawn_points[ team_name ] = {} end
|
||||
respawn.team_respawn_points[ team_name ][ spawn_id ] = data
|
||||
respawn.save_db( "team_respawn" , respawn.team_respawn_points )
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
respawn.reset_places = function()
|
||||
respawn.places = {}
|
||||
respawn.save_db( "places" , respawn.places )
|
||||
|
@ -132,6 +155,30 @@ end
|
|||
|
||||
|
||||
|
||||
-- TODO: for instance it just counts how many there are
|
||||
respawn.output_team_respawn_points = function( player , team_name )
|
||||
if not player then return false end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
if player_name == "" then return false end
|
||||
|
||||
if not team_name then
|
||||
local meta = player:get_meta()
|
||||
team_name = meta:get_string( "team" )
|
||||
if not team_name or team_name == "" then
|
||||
minetest.chat_send_player( player_name , S("Team not found.") )
|
||||
end
|
||||
end
|
||||
|
||||
if not respawn.team_respawn_points[ team_name ] then
|
||||
minetest.chat_send_player( player_name , S("There are no team respawn points.") )
|
||||
else
|
||||
minetest.chat_send_player( player_name , S("There are @1 team respawn points." , #respawn.team_respawn_points[ team_name ]) )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
respawn.output_places = function( player )
|
||||
if not player then return false end
|
||||
|
||||
|
@ -219,6 +266,25 @@ end
|
|||
|
||||
|
||||
|
||||
respawn.teleport_to_team_respawn = function( player , spawn_id )
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
|
||||
if not team_name or team_name == "" or not respawn.team_respawn_points[ team_name ] then
|
||||
return false
|
||||
end
|
||||
|
||||
spawn_id = spawn_id or math.random( #respawn.team_respawn_points[ team_name ] )
|
||||
|
||||
local point = respawn.team_respawn_points[ team_name ][ spawn_id ]
|
||||
if not point then point = respawn.team_respawn_points[ team_name ][ 1 ] end
|
||||
|
||||
minetest.chat_send_all( S("zzzzboooo @1 @2 @3", point.pos.x, point.pos.y, point.pos.z) ) ;
|
||||
return respawn.teleport( player , point )
|
||||
end
|
||||
|
||||
|
||||
|
||||
respawn.teleport_to_place = function( player , place_name )
|
||||
local point = respawn.places[ place_name ]
|
||||
return respawn.teleport( player , point )
|
||||
|
@ -281,6 +347,8 @@ respawn.teleport_delay = function( player , type , id , delay )
|
|||
minetest.after( delay , function()
|
||||
if type == "respawn" then
|
||||
respawn.teleport_to_respawn( player , id )
|
||||
elseif type == "team_respawn" then
|
||||
respawn.teleport_to_team_respawn( player , id )
|
||||
elseif type == "place" then
|
||||
respawn.teleport_to_place( player , id )
|
||||
elseif type == "player_place" then
|
||||
|
@ -330,6 +398,18 @@ end
|
|||
|
||||
|
||||
|
||||
respawn.closest_team_respawn = function( player_name , pos , max_dist , max_squared_dist )
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
|
||||
if respawn.team_respawn_points[ team_name ] then
|
||||
return respawn.closest_thing( respawn.team_respawn_points[ team_name ] , pos , max_dist , max_squared_dist )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
respawn.closest_place = function( pos , max_dist , max_squared_dist )
|
||||
return respawn.closest_thing( respawn.places , pos , max_dist , max_squared_dist )
|
||||
end
|
||||
|
@ -369,6 +449,15 @@ respawn.respawn = function( player )
|
|||
-- We use a delay because returning true has no effect despite what the doc tells
|
||||
-- so we teleport after the regular spawn
|
||||
|
||||
if minetest.settings:get_bool("enable_team_respawn") then
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
if team_name and team_name ~= "" and respawn.team_respawn_points[ team_name ] and #respawn.team_respawn_points[ team_name ] > 0 then
|
||||
respawn.teleport_delay( player , "team_respawn" , math.random( #respawn.team_respawn_points[ team_name ] ) , 0 )
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.settings:get_bool("enable_home_respawn") then
|
||||
local player_name = player:get_player_name()
|
||||
if player_name and respawn.player_places[ player_name ] and respawn.player_places[ player_name ].home then
|
||||
|
|
100
commands.lua
100
commands.lua
|
@ -117,6 +117,82 @@ minetest.register_chatcommand( "set_respawn", {
|
|||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "list_team_respawns", {
|
||||
description = S("List all team respawn points."),
|
||||
params = S("[<team name>]"),
|
||||
func = function( player_name , param )
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local parts = string.split( param , " " )
|
||||
local team_name = parts[1] or nil
|
||||
|
||||
return respawn.output_team_respawn_points( player , team_name )
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "reset_team_respawns", {
|
||||
description = S("Reset team respawn points."),
|
||||
privs = { server = true },
|
||||
func = function( player_name , param )
|
||||
if respawn.reset_team_respawns() then
|
||||
return true, S("Team respawn points reset." )
|
||||
end
|
||||
|
||||
return false, S("Something went wrong...")
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "set_team_respawn", {
|
||||
description = S("Create a team respawn point on your current player position. Without argument it set the first respawn point, with 'new' it appends a new team respawn point."),
|
||||
params = S("<team name> [<spawn number>|new]"),
|
||||
privs = { server = true },
|
||||
func = function( player_name , param )
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local parts = string.split( param , " " )
|
||||
local team_name = parts[1] or nil
|
||||
|
||||
if not team_name then
|
||||
return false, S("Missing team name!")
|
||||
end
|
||||
|
||||
local spawn_id
|
||||
|
||||
if parts[2] == "new" then
|
||||
if respawn.team_respawn_points[ team_name ] then
|
||||
spawn_id = #respawn.team_respawn_points[ team_name ] + 1
|
||||
else
|
||||
spawn_id = 1
|
||||
end
|
||||
else
|
||||
spawn_id = tonumber( parts[2] ) or 1
|
||||
end
|
||||
|
||||
if respawn.set_team_respawn( team_name , spawn_id , {
|
||||
pos = player:get_pos() ,
|
||||
look = { h = player:get_look_horizontal() , v = player:get_look_vertical() }
|
||||
} ) then
|
||||
return true, S("Team @1 respawn point @2 set!", team_name , spawn_id)
|
||||
end
|
||||
|
||||
return false, S("Something went wrong...")
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "list_places", {
|
||||
description = S("List all global places."),
|
||||
func = function( player_name , param )
|
||||
|
@ -580,15 +656,24 @@ minetest.register_chatcommand( "list_deaths", {
|
|||
|
||||
|
||||
minetest.register_chatcommand( "set_team", {
|
||||
description = S("Set the team of a player. If the team name is omitted, display current player team"),
|
||||
params = S("<player name> [<team name>]"),
|
||||
description = S("Set the team of a player."),
|
||||
params = S("[<player name>] <team name>"),
|
||||
privs = { team = true },
|
||||
func = function( chat_player_name , param )
|
||||
local player_name , team_name
|
||||
local parts = string.split( param , " " )
|
||||
local player_name = parts[1] or nil
|
||||
|
||||
|
||||
if #parts == 0 then
|
||||
return false, S("Missing arguments!")
|
||||
elseif #parts == 1 then
|
||||
team_name = parts[1]
|
||||
else
|
||||
player_name = parts[1]
|
||||
team_name = parts[2]
|
||||
end
|
||||
|
||||
if not player_name then
|
||||
return false, S("Missing player argument!")
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
@ -597,7 +682,6 @@ minetest.register_chatcommand( "set_team", {
|
|||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local team_name = parts[2] or nil
|
||||
local meta = player:get_meta()
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
|
@ -614,14 +698,14 @@ minetest.register_chatcommand( "set_team", {
|
|||
|
||||
minetest.register_chatcommand( "get_team", {
|
||||
description = S("Get the team of a player."),
|
||||
params = S("<player name>"),
|
||||
params = S("[<player name>]"),
|
||||
privs = { team = true },
|
||||
func = function( chat_player_name , param )
|
||||
local parts = string.split( param , " " )
|
||||
local player_name = parts[1] or nil
|
||||
|
||||
if not player_name then
|
||||
return false, S("Missing player argument!")
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# When enabled, players use their team respawn if any
|
||||
enable_team_respawn (Enable team respawn) bool false
|
||||
|
||||
# When enabled, players can respawn in their home place, if they defined one
|
||||
# using the command: /set_own_place home
|
||||
enable_home_respawn (Enable home respawn) bool false
|
||||
|
|
Loading…
Reference in New Issue