add /set_team and /get_team
parent
cd84243965
commit
4e6629335c
71
commands.lua
71
commands.lua
|
@ -31,6 +31,13 @@ minetest.register_privilege( "locate", {
|
|||
|
||||
|
||||
|
||||
minetest.register_privilege( "team", {
|
||||
description = S("Can use /set_team.") ,
|
||||
give_to_singleplayer = false
|
||||
} )
|
||||
|
||||
|
||||
|
||||
-- Join an array of string
|
||||
function join( tab , delimiter , first , last )
|
||||
if not delimiter then delimiter = "" end
|
||||
|
@ -570,3 +577,67 @@ minetest.register_chatcommand( "list_deaths", {
|
|||
end
|
||||
} )
|
||||
|
||||
|
||||
|
||||
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>]"),
|
||||
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!")
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name( player_name )
|
||||
|
||||
if not player then
|
||||
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
|
||||
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
|
||||
return false, S("Missing player argument!")
|
||||
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
|
||||
} )
|
||||
|
||||
|
|
Loading…
Reference in New Issue