Compare commits

...

5 Commits

Author SHA1 Message Date
Cédric Ronvel 9c1957c2ad mod.conf 2019-11-28 14:31:50 +01:00
Cédric Ronvel 8c6096c3e5 updated README 2019-11-26 13:58:05 +01:00
Cédric Ronvel a9e1afdf8d screenshot.png use contentDB format 2019-11-26 13:44:50 +01:00
Cédric Ronvel c36225665b Fixes and doc 2019-11-26 12:35:31 +01:00
Cédric Ronvel d8cb3884e4 New command /teleport_teams 2019-11-26 10:05:43 +01:00
6 changed files with 227 additions and 84 deletions

View File

@ -8,6 +8,7 @@
### Features
* Create/manage as many respawn points you want, to be used randomly (e.g. on player death or first connection)
* Create/manage as many team respawn points you want
* Create/manage global map place
* Each player can have its own personal places (stored and used separately from the global places)
* Each place and respawn retains not only the position, **but also a direction where to look**,
@ -17,11 +18,13 @@
* Powerful teleport command
* teleport self or teleport other (with different privileges)
* teleport to a respawn point, a global place, an own place, a coordinate, your last death place, or next to a player
* Every death are logged, with the reason and the place it happened (if closed to a known global place)
* teleport whole teams to their respective team respawn
* Assign any player to a team, list team members
* List any type of places
* List any player death
* Have a setting allowing player to respawn to their personal own place named "home" instead of using a regular respawn point
(disabled by default)
* Every death are displayed and logged, with the reason and the place it happened (if closed to a known global place)
* Have a setting allowing players to respawn to their team respawn instead of using a regular respawn point (disabled by default)
* Have a setting allowing player to respawn to their personal own place named "home" instead of using a regular respawn point (disabled by default)
@ -29,6 +32,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 +55,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 +70,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.

55
api.lua
View File

@ -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
@ -284,6 +318,27 @@ end
-- Argument "teams" is a hash of { team1 = true , ... }
respawn.teleport_teams_to_team_respawn = function( teams )
local meta , team_name , spawn_id , point
local players = minetest.get_connected_players()
for k, player in ipairs( players ) do
meta = player:get_meta()
team_name = meta:get_string( "team" )
if team_name and team_name ~= "" and ( not teams or teams[ team_name ] == true ) and respawn.team_respawn_points[ team_name ] then
spawn_id = math.random( #respawn.team_respawn_points[ team_name ] )
point = respawn.team_respawn_points[ team_name ][ spawn_id ]
respawn.teleport( player , point )
end
end
return true
end
respawn.teleport_to_place = function( player , place_name )
local point = respawn.places[ place_name ]
return respawn.teleport( player , point )

View File

@ -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) )
@ -636,6 +751,39 @@ minetest.register_chatcommand( "teleport_other", {
minetest.register_chatcommand( "teleport_teams", {
description = S("Teleport teams to their respective team respawn."),
params = S("[<team1> [<team2> [...]]"),
privs = { teleport = true , teleport_other = true },
func = function( performer_name , param )
local teams = string.split( param , " " )
local teams_hash
if #teams > 0 then
teams_hash = {}
for k, team_name in ipairs( teams ) do
teams_hash[ team_name ] = true
end
end
if respawn.teleport_teams_to_team_respawn( teams_hash ) then
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 respective respawn.", performer_name ) )
end
return true
end
return false, S("Respawn point or place not found!")
end
} )
minetest.register_chatcommand( "list_deaths", {
description = S("List all deaths of a player. Without argument it applies to the current player."),
params = S("[<player name>]"),
@ -653,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
} )

View File

@ -1,5 +1,5 @@
name = respawn
description = Manage respawn points, interesting places, teleportation and death records
release = 1
description = Manage respawn points, interesting places, teleportation, death records and more.
release = 3
author = cronvel
title = Respawn

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -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