Fixes and doc
parent
d8cb3884e4
commit
c36225665b
|
@ -29,6 +29,9 @@
|
|||
|
||||
For the complete syntax, see the in-game help.
|
||||
|
||||
* /list_teams: list all teams with their members
|
||||
* /get_team: display the team of a player
|
||||
* /set_team: set a team to a player
|
||||
* /list_respawns: List all respawn points.
|
||||
* /reset_respawns: Reset respawn points. Require the "server" privilege.
|
||||
* /set_respawn: Create a respawn point on your current player position. Require the "server" privilege.
|
||||
|
@ -49,6 +52,7 @@ For the complete syntax, see the in-game help.
|
|||
or a player. Require the "teleport" privilege.
|
||||
* /teleport_other: teleport anyone to a respawn point, a global place, one of your personal own place (not their),
|
||||
their last death place, a coordinate, close to you or any player. Require the "teleport" and "teleport_other" privileges.
|
||||
* /teleport_teams: teleport teams to their respective team respawn.
|
||||
* /list_deaths: list your or any player deaths with the cause and the place it occurs.
|
||||
|
||||
|
||||
|
@ -63,11 +67,15 @@ For the complete syntax, see the in-game help.
|
|||
* place: Can use /set_place, /remove_place, /reset_places and /reset_all_player_places to manage global places.
|
||||
* locate: Can use advanced /where command to locate other player and output coordinate, extend /teleport and /teleport_other
|
||||
to support xyz coordinates and teleporting close to another player.
|
||||
* team: Can use /set_team to assign a player to a team.
|
||||
|
||||
|
||||
|
||||
### Settings
|
||||
|
||||
* enable_team_respawn: If enabled (default: disabled), players use their respective team respawn (if any).
|
||||
Note: This have greater priority than home respawn (if set).
|
||||
|
||||
* enable_home_respawn: if enabled (default: disabled), the player can respawn at their home instead of a regular respawn point.
|
||||
Note: should not be confused with the *sethome* mod's home, the player should have typed the command `set_own_place home`
|
||||
for this to work.
|
||||
|
|
34
api.lua
34
api.lua
|
@ -143,6 +143,40 @@ end
|
|||
|
||||
|
||||
|
||||
respawn.output_teams = function( chat_player )
|
||||
if not chat_player then return false end
|
||||
|
||||
local chat_player_name = chat_player:get_player_name()
|
||||
if chat_player_name == "" then return false end
|
||||
|
||||
local str = S("List of teams:")
|
||||
local teams = {}
|
||||
local players = minetest.get_connected_players()
|
||||
|
||||
for k, player in ipairs( players ) do
|
||||
local player_name = player:get_player_name()
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
if not teams[ team_name ] then teams[ team_name ] = {} end
|
||||
table.insert( teams[ team_name ] , player_name )
|
||||
end
|
||||
end
|
||||
|
||||
for team_name, members in pairs( teams ) do
|
||||
str = str .. "\n " .. team_name .. ":"
|
||||
|
||||
for k2, player_name in ipairs( members ) do
|
||||
str = str .. " " .. player_name
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player( chat_player_name , str )
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- TODO: for instance it just counts how many there are
|
||||
respawn.output_respawn_points = function( player )
|
||||
if not player then return false end
|
||||
|
|
207
commands.lua
207
commands.lua
|
@ -32,29 +32,126 @@ minetest.register_privilege( "locate", {
|
|||
|
||||
|
||||
minetest.register_privilege( "team", {
|
||||
description = S("Can use /set_team.") ,
|
||||
description = S("Can use /set_team to assign a player to a team.") ,
|
||||
give_to_singleplayer = false
|
||||
} )
|
||||
|
||||
|
||||
|
||||
-- Join an array of string
|
||||
function join( tab , delimiter , first , last )
|
||||
function join( tab , delimiter , last_delimiter , first , last )
|
||||
if not delimiter then delimiter = "" end
|
||||
|
||||
if type( last_delimiter ) ~= "string" then
|
||||
last = first
|
||||
first = last_delimiter
|
||||
last_delimiter = delimiter
|
||||
end
|
||||
|
||||
if not first then first = 1 end
|
||||
if not last then last = #tab end
|
||||
|
||||
local str = tab[ first ] or ""
|
||||
|
||||
for i = first + 1, last , 1 do
|
||||
for i = first + 1, last - 1 , 1 do
|
||||
str = str .. delimiter .. tab[ i ]
|
||||
end
|
||||
|
||||
if #tab > 1 then
|
||||
str = str .. last_delimiter .. tab[ #tab ]
|
||||
end
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "list_teams", {
|
||||
description = S("List all teams with their members."),
|
||||
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
|
||||
|
||||
return respawn.output_teams( player )
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "get_team", {
|
||||
description = S("Display the team of a player."),
|
||||
params = S("[<player name>]"),
|
||||
func = function( chat_player_name , param )
|
||||
local parts = string.split( param , " " )
|
||||
local player_name = parts[1] or nil
|
||||
|
||||
if not player_name then
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
return true, S("@1 is in team @2.", player_name , team_name)
|
||||
else
|
||||
return true, S("@1 is not in any team.", player_name)
|
||||
end
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "set_team", {
|
||||
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 , " " )
|
||||
|
||||
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
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local meta = player:get_meta()
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
meta:set_string( "team" , team_name )
|
||||
return true, S("Now @1 is in team @2.", player_name, team_name)
|
||||
else
|
||||
meta:set_string( "team" , "" )
|
||||
return true, S("Now @1 is removed from any team.", player_name)
|
||||
end
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "list_respawns", {
|
||||
description = S("List all respawn points."),
|
||||
func = function( player_name , param )
|
||||
|
@ -430,7 +527,7 @@ minetest.register_chatcommand( "where", {
|
|||
|
||||
|
||||
minetest.register_chatcommand( "teleport", {
|
||||
description = S("Teleport to a map respawn point, a place or more. First argument can be respawn/spawn, place/global, own_place/own/home, death (for last death place), xyz (for coordinates), player (teleport close to another player), if omitted it searches for own place first, then for global place. Last argument can be avoided: for respawn it would move to a random respawn point, for own place it would go to the home."),
|
||||
description = S("Teleport to a map respawn point, a place or more. First argument can be respawn/spawn, team/team_respawn (for the respawn of the team of the player), place/global, own_place/own/home, death (for last death place), xyz (for coordinates), player (teleport close to another player), if omitted it searches for own place first, then for global place. Last argument can be avoided: for respawn it would move to a random respawn point, for own place it would go to the home."),
|
||||
params = S("<type> [<ID>] | xyz <x> <y> <z>"),
|
||||
privs = { teleport = true },
|
||||
func = function( player_name , param )
|
||||
|
@ -457,6 +554,14 @@ minetest.register_chatcommand( "teleport", {
|
|||
return true, S("Teleported to a random respawn point.")
|
||||
end
|
||||
end
|
||||
elseif type == "team_respawn" or type =="team" then
|
||||
if respawn.teleport_to_team_respawn( player , tonumber( id ) , true ) then
|
||||
if id then
|
||||
return true, S("Teleported to the team respawn n°@1.", id)
|
||||
else
|
||||
return true, S("Teleported to a random team respawn point.")
|
||||
end
|
||||
end
|
||||
elseif type == "place" or type == "global" then
|
||||
if respawn.teleport_to_place( player , id ) then
|
||||
return true, S("Teleported to @1.", respawn.places[ id ].full_name or id)
|
||||
|
@ -521,7 +626,7 @@ minetest.register_chatcommand( "teleport", {
|
|||
|
||||
-- Mostly a copy/paste of /teleport command
|
||||
minetest.register_chatcommand( "teleport_other", {
|
||||
description = S("Teleport another player to a map respawn point, a place or more. First argument is the player name, second argument can be respawn/spawn, place/global, death (for last death place), xyz (for coordinates), player (teleport close to another player), here (teleport close to you), if omitted it will search for global place. Last argument can be avoided: for respawn it would move to a random respawn point."),
|
||||
description = S("Teleport another player to a map respawn point, a place or more. First argument is the player name, second argument can be respawn/spawn, team/team_respawn (for the respawn of the team of the player), place/global, own_place/own, death (for last death place), xyz (for coordinates), player (teleport close to another player), here (teleport close to you), if omitted it will search for global place. Last argument can be avoided: for respawn it would move to a random respawn point."),
|
||||
params = S("<player> [<type>] [<ID>] | <player> xyz <x> <y> <z>"),
|
||||
privs = { teleport = true , teleport_other = true },
|
||||
func = function( performer_name , param )
|
||||
|
@ -554,6 +659,16 @@ minetest.register_chatcommand( "teleport_other", {
|
|||
return true
|
||||
end
|
||||
end
|
||||
elseif type == "team_respawn" or type =="team" then
|
||||
if respawn.teleport_to_team_respawn( player , tonumber( id ) , true ) then
|
||||
if id then
|
||||
minetest.chat_send_all( S("@1 teleported @2 to the team respawn n°@3.", performer_name , player_name , id) )
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_all( S("@1 teleported @2 to a random team respawn point.", performer_name , player_name) )
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif type == "place" or type == "global" then
|
||||
if respawn.teleport_to_place( player , id ) then
|
||||
minetest.chat_send_all( S("@1 teleported @2 to @3.", performer_name , player_name , respawn.places[ id ].full_name or id) )
|
||||
|
@ -637,7 +752,7 @@ minetest.register_chatcommand( "teleport_other", {
|
|||
|
||||
|
||||
minetest.register_chatcommand( "teleport_teams", {
|
||||
description = S("Teleport teams to their respawn."),
|
||||
description = S("Teleport teams to their respective team respawn."),
|
||||
params = S("[<team1> [<team2> [...]]"),
|
||||
privs = { teleport = true , teleport_other = true },
|
||||
func = function( performer_name , param )
|
||||
|
@ -653,10 +768,12 @@ minetest.register_chatcommand( "teleport_teams", {
|
|||
end
|
||||
|
||||
if respawn.teleport_teams_to_team_respawn( teams_hash ) then
|
||||
if teams_hash then
|
||||
minetest.chat_send_all( S("@1 teleported teams @2 to their respawn.", performer_name , param ) )
|
||||
if #teams >= 2 then
|
||||
minetest.chat_send_all( S("@1 teleported @2 teams to their respawn.", performer_name , join( teams , S(", ") , S( " and " ) ) ) )
|
||||
elseif #teams >= 1 then
|
||||
minetest.chat_send_all( S("@1 teleported @2 team to its respawn.", performer_name , teams[1] ) )
|
||||
else
|
||||
minetest.chat_send_all( S("@1 teleported all teams to their respawn.", performer_name ) )
|
||||
minetest.chat_send_all( S("@1 teleported all teams to their respective respawn.", performer_name ) )
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
@ -684,75 +801,3 @@ minetest.register_chatcommand( "list_deaths", {
|
|||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "set_team", {
|
||||
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 , " " )
|
||||
|
||||
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
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local meta = player:get_meta()
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
meta:set_string( "team" , team_name )
|
||||
return true, S("Now @1 is in team @2.", player_name, team_name)
|
||||
else
|
||||
meta:set_string( "team" , "" )
|
||||
return true, S("Now @1 is removed from any team.", player_name)
|
||||
end
|
||||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand( "get_team", {
|
||||
description = S("Get the team of a player."),
|
||||
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
|
||||
player_name = chat_player_name
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
|
||||
local meta = player:get_meta()
|
||||
local team_name = meta:get_string( "team" )
|
||||
|
||||
if team_name and team_name ~= "" then
|
||||
return true, S("@1 is in team @2.", player_name , team_name)
|
||||
else
|
||||
return true, S("@1 is not in any team.", player_name)
|
||||
end
|
||||
end
|
||||
} )
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# When enabled, players use their team respawn if any
|
||||
# When enabled, players use their respective team respawn (if any)
|
||||
# This have greater priority than home respawn (if set).
|
||||
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
|
||||
# using the command: /set_own_place home.
|
||||
enable_home_respawn (Enable home respawn) bool false
|
||||
|
|
Loading…
Reference in New Issue