2017-10-10 20:59:51 +08:00
party = { }
mod_storage = minetest.get_mod_storage ( )
2017-10-13 00:55:16 +08:00
-- =======================
-- === CUSTOM SETTINGS ===
-- =======================
PARTY_TAG_COLOUR = " lightgrey " -- default colour of party tags
PARTY_PARTY_NAME_LENGTH = 8 -- max length for party name/ tag
PARTY_PARTY_JOIN_MODE = " " -- default join mode for parties <<< empty(open)/ active / request / private >>>
PARTY_SQUAD_NAME_LENGTH = 8 -- max length for squad name/ tag
PARTY_SQUAD_JOIN_MODE = " " -- default join mode for squads <<< empty(open) / private >>>
2017-10-06 10:27:11 +08:00
2017-10-13 01:23:21 +08:00
PARTY_IRC_HIDE = " false " -- if "true" and irc mod is active, party and squad messages are NOT sent to the irc channel. NOTE if true, comment out these few lines; https://github.com/minetest-mods/irc/blob/master/callback.lua#L22-L35 on the irc mod, else there will be double messages.
2017-10-06 10:27:11 +08:00
-- =======================
-- ===== PLAYER LIST =====
-- =======================
2017-10-05 18:24:35 +08:00
-- add new players to the mod storage playerlist - thanks to Amaz
minetest.register_on_newplayer ( function ( newplayer )
2017-10-06 09:44:00 +08:00
local player_list_l = mod_storage : get_string ( " playerlist " )
2017-10-06 10:30:51 +08:00
if player_list_l == " " then
2017-10-05 18:24:35 +08:00
player_list_t = { }
else player_list_t = minetest.deserialize ( player_list_l )
end
player_list_t [ # player_list_t + 1 ] = newplayer : get_player_name ( )
local player_list_s = minetest.serialize ( player_list_t )
mod_storage : set_string ( " playerlist " , player_list_s )
end )
-- check if old players are in the playerlist, if not, add them to the list
minetest.register_on_joinplayer ( function ( player )
2017-10-06 09:44:00 +08:00
local player_list_l = mod_storage : get_string ( " playerlist " )
2017-10-05 18:24:35 +08:00
local name = player : get_player_name ( )
2017-10-06 10:30:51 +08:00
if player_list_l == " " then
2017-10-06 09:44:00 +08:00
player_list_lt = { }
else player_list_lt = minetest.deserialize ( player_list_l )
2017-10-05 18:24:35 +08:00
end
2017-10-06 09:44:00 +08:00
2017-10-05 18:24:35 +08:00
for _ , playernames in ipairs ( player_list_lt ) do
if name == playernames then
return
end
end
2017-10-06 10:30:51 +08:00
if player_list_l == " " then
2017-10-10 20:59:51 +08:00
player_list_e = { }
2017-10-05 18:24:35 +08:00
else player_list_e = minetest.deserialize ( player_list_l )
end
2017-10-06 09:44:00 +08:00
2017-10-05 18:24:35 +08:00
player_list_e [ # player_list_e + 1 ] = player : get_player_name ( )
local player_list_s = minetest.serialize ( player_list_e )
mod_storage : set_string ( " playerlist " , player_list_s )
2017-10-04 20:07:20 +08:00
end )
2017-10-06 10:27:11 +08:00
-- =======================
-- ======= HELPERS =======
-- =======================
2017-10-04 20:07:20 +08:00
-- group notice
party.send_notice_all = function ( name , message )
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
if mod_storage : get_string ( name .. " _party " ) == mod_storage : get_string ( names .. " _party " ) then
2017-10-10 20:59:51 +08:00
minetest.chat_send_player ( names , minetest.colorize ( " limegreen " , " [Party] = PARTY-NOTICE = " ) .. " " .. message )
2017-10-04 20:07:20 +08:00
end
end
end
2017-10-10 20:59:51 +08:00
2017-10-04 20:07:20 +08:00
-- private notice
party.send_notice = function ( name , message )
2017-10-10 20:59:51 +08:00
minetest.chat_send_player ( name , minetest.colorize ( " limegreen " , " [Party] = NOTICE = " ) .. " " .. message )
2017-10-04 20:07:20 +08:00
end
2017-10-05 02:59:20 +08:00
-- chat spy for admins
2017-10-11 00:18:04 +08:00
minetest.register_privilege ( " pspy " , " " )
2017-10-05 02:59:20 +08:00
party.chat_spy = function ( name , message )
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
2017-10-11 00:18:04 +08:00
if minetest.check_player_privs ( names , { pspy = true } ) then
2017-10-05 02:59:20 +08:00
local cparty = mod_storage : get_string ( name .. " _party " )
2017-10-13 14:08:23 +08:00
local csquad = mod_storage : get_string ( name .. " _squad " )
if cparty ~= " " then
2017-10-05 02:59:20 +08:00
if cparty ~= mod_storage : get_string ( names .. " _party " ) then
2017-10-10 20:59:51 +08:00
minetest.chat_send_player ( names , minetest.colorize ( " yellow " , " [SPY] " ) .. " [PARTY: " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] < " .. name .. " > " .. message )
2017-10-13 14:08:23 +08:00
elseif cparty == mod_storage : get_string ( names .. " _party " ) and csquad ~= mod_storage : get_string ( names .. " _squad " ) then
minetest.chat_send_player ( names , minetest.colorize ( " yellow " , " [SPY] " ) .. " [PARTY: " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] [SQUAD: " .. csquad .. " ] < " .. name .. " > " .. message )
2017-10-05 02:59:20 +08:00
end
end
end
end
end
2017-10-04 20:07:20 +08:00
-- check if player is in a party [1], officer or leader [2], leader [3]
-- if not then return true
party.check = function ( name , level )
local player = minetest.get_player_by_name ( name )
local cparty = mod_storage : get_string ( name .. " _party " )
2017-10-06 10:30:51 +08:00
if level == 1 and cparty == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You are not in a party! " )
return true
elseif level == 2 then
2017-10-06 10:30:51 +08:00
if cparty == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You are not in a party! " )
return true
2017-10-06 10:30:51 +08:00
elseif cparty ~= " " then
2017-10-04 20:07:20 +08:00
local cparty_l = mod_storage : get_string ( name .. " _leader " )
local cparty_o = mod_storage : get_string ( name .. " _officer " )
2017-10-06 10:30:51 +08:00
if cparty_o == " " and cparty_l == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " Not authorized to use this command! You are neither the party leader nor an officer of this party! " )
return true
end
end
elseif level == 3 then
local cparty_l = mod_storage : get_string ( name .. " _leader " )
2017-10-06 10:30:51 +08:00
if cparty == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You are not in a party! " )
return true
2017-10-06 10:30:51 +08:00
elseif cparty ~= " " and cparty_l == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " Not authorized to use this command! You are not the party leader! " )
return true
end
else
return false
end
end
-- check if party name exists
-- if it exists, return true
party.check_tag = function ( name , tag )
2017-10-05 18:24:35 +08:00
local player_list = minetest.deserialize ( mod_storage : get_string ( " playerlist " ) )
2017-10-04 20:07:20 +08:00
for _ , playernames in ipairs ( player_list ) do
if tag == mod_storage : get_string ( playernames .. " _leader " ) then
return true
end
end
end
2017-10-10 20:59:51 +08:00
-- =======================
-- ====== LOAD FILES =====
-- =======================
dofile ( minetest.get_modpath ( " party " ) .. " /squad.lua " )
-- =======================
-- ===== MORE HELPERS ====
-- =======================
2017-10-04 20:07:20 +08:00
party.join = function ( name , partyname )
local cparty_l = mod_storage : get_string ( partyname .. " _leader " )
local player = minetest.get_player_by_name ( name )
mod_storage : set_string ( name .. " _party " , partyname )
player : set_attribute ( " partyinvite " , nil )
player : set_attribute ( " partypending " , nil )
2017-10-12 22:43:34 +08:00
local tcolour = mod_storage : get_string ( partyname .. " _colour " )
if tcolour == " " then
2017-10-13 00:55:16 +08:00
tcolour = PARTY_TAG_COLOUR
2017-10-12 22:43:34 +08:00
end
player : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. cparty_l .. " ] " ) .. " " .. name } )
2017-10-04 20:07:20 +08:00
party.send_notice_all ( name , name .. " has joined " .. partyname .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-11 18:31:03 +08:00
player : set_attribute ( " partychat " , " party " )
2017-10-04 20:07:20 +08:00
end
2017-10-05 18:24:35 +08:00
party.leave = function ( name )
local player = minetest.get_player_by_name ( name )
2017-10-12 12:00:23 +08:00
local csquad = mod_storage : get_string ( name .. " _squad " )
2017-10-11 00:18:04 +08:00
2017-10-12 12:00:23 +08:00
if csquad ~= " " then
squad.leave ( name )
end
2017-10-11 00:18:04 +08:00
2017-10-05 18:24:35 +08:00
mod_storage : set_string ( name .. " _party " , nil )
mod_storage : set_string ( name .. " _officer " , nil )
mod_storage : set_string ( name .. " _leader " , nil )
mod_storage : set_string ( name .. " _lock " , nil )
2017-10-11 18:31:03 +08:00
mod_storage : set_string ( name .. " _title " , nil )
mod_storage : set_string ( name .. " _home " , nil )
2017-10-12 22:43:34 +08:00
mod_storage : set_string ( name .. " _colour " , nil )
2017-10-05 18:24:35 +08:00
player : set_nametag_attributes ( { text = name } )
2017-10-11 18:31:03 +08:00
player : set_attribute ( " partychat " , " main " )
2017-10-05 18:24:35 +08:00
end
2017-10-04 20:07:20 +08:00
2017-10-06 21:05:59 +08:00
minetest.register_chatcommand ( " p " , {
description = " Create and join a party. For help, use /p help " ,
2017-10-05 02:59:20 +08:00
privs = { shout = true } ,
2017-10-04 20:07:20 +08:00
func = function ( name , param )
local paramlist = { }
local index = 1
for param_split in param : gmatch ( " %S+ " ) do
paramlist [ index ] = param_split
index = index + 1
end
local param1 = paramlist [ 1 ]
local param2 = paramlist [ 2 ]
2017-10-10 22:11:45 +08:00
local param3 = paramlist [ 3 ]
2017-10-04 20:07:20 +08:00
local player = minetest.get_player_by_name ( name )
local cparty = mod_storage : get_string ( name .. " _party " )
local cparty_o = mod_storage : get_string ( name .. " _officer " )
2017-10-05 18:24:35 +08:00
local player_list = minetest.deserialize ( mod_storage : get_string ( " playerlist " ) )
2017-10-04 20:07:20 +08:00
if param1 == " help " then
2017-10-10 20:59:51 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " @<message> " ) .. " --- Send message to global chat (if you are in a party). " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p " ) .. " --- List your current party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p list " ) .. " --- List online members of your party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p list all " ) .. " --- List all members of your party. " )
2017-10-12 12:00:23 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p list <playername> " ) .. " --- List party and squad of a player. " )
2017-10-11 01:54:53 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p partylist " ) .. " --- Gives full list of parties created. " )
2017-10-10 20:59:51 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p create <partyname> " ) .. " --- Create a party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p join <partyname> " ) .. " --- Join a party. " )
2017-10-10 22:11:45 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p leave " ) .. " --- Leave your party. " )
2017-10-11 18:31:03 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p home " ) .. " --- Teleport to your party home (if your leader has one set). " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p chat <main/party/squad> " ) .. " --- Switch your chat input. Leave empty to get your current chat input. " )
2017-10-10 20:59:51 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p invite <yes/no> " ) .. " --- Accept/ reject a party invite. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p noinvite " ) .. " --- Toggle noinvites, if on, reject all parties invites automatically. " )
2017-10-10 22:11:45 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p pvp " ) .. " --- Toggle friendly fire, if two players have friendly fire enabled even though they are in the same party, they can fight. " )
2017-10-04 20:07:20 +08:00
2017-10-10 20:59:51 +08:00
party.send_notice ( name , " ===== PARTY OFFICERS/ PARTY LEADER COMMANDS: ===== " )
2017-10-11 18:31:03 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p kick <playername> " ) .. " --- Kick a player out of your party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p invite <playername> " ) .. " --- Invite a player to join your party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p <accept/reject> <playername> " ) .. " --- Accept/ reject a join request (if joining method is set to [Request Mode]). " )
2017-10-04 20:07:20 +08:00
2017-10-10 20:59:51 +08:00
party.send_notice ( name , " ===== PARTY LEADER-ONLY COMMANDS: ===== " )
2017-10-11 18:31:03 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p disband " ) .. " --- Disband your party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p rename <new_partyname> " ) .. " --- Rename your party. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p sethome " ) .. " --- Set your party home. " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p sethome remove " ) .. " --- Remove your party home. " )
2017-10-12 22:43:34 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p colour <colour> " ) .. " --- Set the colour of your party tag. " )
2017-10-10 20:59:51 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p officer <playername> " ) .. " --- Toogle a player's officer position. Officers can kick & invite. " )
2017-10-11 18:31:03 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p lock <open/active/request/private> " ) .. " --- Toggle joining method for your party. " )
2017-10-10 22:11:45 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p title <playername> <title> " ) .. " --- Adds a title to a player in party chat. " )
2017-10-04 20:07:20 +08:00
2017-10-10 20:59:51 +08:00
party.send_notice ( name , " ===== ADMIN COMMANDS: ===== " )
2017-10-11 18:31:03 +08:00
party.send_notice ( name , minetest.colorize ( " cyan " , " /p forcedisband <partyname> " ) .. " --- Forcefully disband a party (requires 'ban' privilege). " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p forcejoin <partyname> " ) .. " --- Forcefully let yourself in a party regardless of its lock mode (requires 'ban' privilege). " )
party.send_notice ( name , minetest.colorize ( " cyan " , " /p forcekick <playername> " ) .. " --- Forcefully kick a player from a party (requires 'kick' privilege). " )
2017-10-05 02:59:20 +08:00
2017-10-04 20:07:20 +08:00
-- TODO
-- formspecs equivalents
2017-10-06 21:05:59 +08:00
-- party.send_notice(name, "/p ally/enemy/neutral <partyname> --- Toggle diplomacy status with another party. Allied parties will have no friendly fire and there will be ally chat.")
-- party.send_notice(name, "/p ally list --- Ally list.")
-- party.send_notice(name, "/p enemy list --- Enemies list.")
-- party.send_notice(name, "/p motd --- Adds a motd. Player receive this message when they join the game / party. ")
2017-10-06 10:27:11 +08:00
-- =======================
-- === GENERAL COMMANDS ==
-- =======================
2017-10-04 20:07:20 +08:00
elseif param1 == nil then
if party.check ( name , 1 ) == true then
return
end
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " You are currently in " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
elseif param1 == " list " then
if param2 == " all " then
if party.check ( name , 1 ) == true then
return
end
local listnames = " "
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " Full member list of " .. cparty .. " 's party [ " .. cparty_l .. " ]: " )
for _ , playernames in ipairs ( player_list ) do
if cparty == mod_storage : get_string ( playernames .. " _party " ) then
listnames = listnames .. playernames .. " , "
end
end
party.send_notice ( name , listnames )
elseif param2 == " officer " then
if party.check ( name , 1 ) == true then
return
end
local listnames = " "
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " List of " .. cparty .. " 's party [ " .. cparty_l .. " ] officers: " )
for _ , playernames in ipairs ( player_list ) do
if cparty == mod_storage : get_string ( playernames .. " _party " ) then
2017-10-06 10:30:51 +08:00
if mod_storage : get_string ( playernames .. " _officer " ) ~= " " or mod_storage : get_string ( playernames .. " _leader " ) ~= " " then
2017-10-04 20:07:20 +08:00
listnames = listnames .. playernames .. " , "
end
end
end
party.send_notice ( name , listnames )
elseif param2 == nil then
if party.check ( name , 1 ) == true then
return
end
local listnames = " "
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " Online member list of " .. cparty .. " 's party [ " .. cparty_l .. " ]: " )
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local playernames = players : get_player_name ( )
if cparty == mod_storage : get_string ( playernames .. " _party " ) then
listnames = listnames .. playernames .. " , "
end
end
party.send_notice ( name , listnames )
elseif param2 ~= nil then
if minetest.player_exists ( param2 ) then
local cparty = mod_storage : get_string ( param2 .. " _party " )
2017-10-12 12:00:23 +08:00
if cparty ~= " " and cparty ~= " @ " and cparty ~= " # " and cparty ~= " + " and cparty ~= " = " then
local csquad = mod_storage : get_string ( param2 .. " _squad " )
2017-10-04 20:07:20 +08:00
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
2017-10-12 12:00:23 +08:00
if param2 ~= cparty and csquad == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , param2 .. " is currently in " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-12 12:00:23 +08:00
elseif param2 ~= cparty and csquad ~= " " then
party.send_notice ( name , param2 .. " is currently in " .. cparty .. " 's party [ " .. cparty_l .. " ] and under the [ " .. csquad .. " ] squad. " )
elseif param2 == cparty and csquad == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , param2 .. " is currently the leader of " .. param2 .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-12 12:00:23 +08:00
elseif param2 == cparty and csquad ~= " " then
party.send_notice ( name , param2 .. " is currently the leader of " .. param2 .. " 's party [ " .. cparty_l .. " ] and under the [ " .. csquad .. " ] squad. " )
2017-10-04 20:07:20 +08:00
end
else party.send_notice ( name , param2 .. " is currently not in any party. " )
end
else party.send_notice ( name , " Player does not exist! " )
end
end
2017-10-11 01:54:53 +08:00
elseif param1 == " partylist " then
local player_list = minetest.deserialize ( mod_storage : get_string ( " playerlist " ) )
local partylist = " "
for _ , playernames in ipairs ( player_list ) do
local cparty_l = mod_storage : get_string ( playernames .. " _leader " )
if cparty_l ~= " " then
partylist = partylist .. cparty_l .. " , "
end
end
party.send_notice ( name , " Full list of parties: " )
party.send_notice ( name , partylist )
2017-10-04 20:07:20 +08:00
elseif param1 == " leave " then
if party.check ( name , 1 ) == true then
return
end
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
2017-10-06 10:30:51 +08:00
if mod_storage : get_string ( name .. " _leader " ) == " " then
2017-10-04 20:07:20 +08:00
party.send_notice_all ( name , name .. " left " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-05 18:24:35 +08:00
party.leave ( name )
2017-10-06 21:05:59 +08:00
else party.send_notice ( name , " You cannot leave your own party! Use /p disband instead. " )
2017-10-04 20:07:20 +08:00
end
elseif param1 == " create " and param2 ~= nil then
2017-10-13 00:55:16 +08:00
if string.len ( param2 ) > PARTY_PARTY_NAME_LENGTH then
party.send_notice ( name , " Nametag is too long! " .. PARTY_PARTY_NAME_LENGTH .. " is the maximum amount of characters " )
2017-10-04 20:07:20 +08:00
return
end
-- check if tag exists
if party.check_tag ( name , param2 ) == true then
party.send_notice ( name , " Party name selected already exists. Please choose another one. " )
return
end
2017-10-06 10:30:51 +08:00
if cparty == " " then
2017-10-04 20:07:20 +08:00
mod_storage : set_string ( name .. " _party " , name )
mod_storage : set_string ( name .. " _leader " , param2 )
2017-10-13 00:55:16 +08:00
mod_storage : set_string ( name .. " _lock " , PARTY_PARTY_JOIN_MODE )
2017-10-04 20:07:20 +08:00
player : set_attribute ( " partyinvite " , nil )
2017-10-11 18:31:03 +08:00
player : set_attribute ( " partychat " , " party " )
2017-10-12 22:43:34 +08:00
local tcolour = mod_storage : get_string ( name .. " _colour " )
if tcolour == " " then
2017-10-13 00:55:16 +08:00
tcolour = PARTY_TAG_COLOUR
2017-10-12 22:43:34 +08:00
end
player : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. param2 .. " ] " ) .. " " .. name } )
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You created " .. name .. " 's party [ " .. param2 .. " ]. " )
else
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " You are already in " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
end
2017-10-06 21:05:59 +08:00
-- /p join
2017-10-04 20:07:20 +08:00
elseif param1 == " join " and param2 ~= nil then
2017-10-06 10:30:51 +08:00
if cparty ~= " " then
2017-10-04 20:07:20 +08:00
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " You are already in " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
return
end
if party.check_tag ( name , param2 ) == true then
local leadername = " "
for _ , playernames in ipairs ( player_list ) do
if param2 == mod_storage : get_string ( playernames .. " _leader " ) then
leadername = leadername .. playernames
end
end
local cparty = leadername
local party_m = mod_storage : get_string ( cparty .. " _lock " )
-- active mode, only allow if leader is active
if party_m == " active " then
if minetest.get_player_by_name ( cparty ) == nil then
party.send_notice ( name , " Party leader is offline, try again when the party leader is online! " )
else party.join ( name , cparty )
end
-- request mode, sends a request if officer/leader are online
elseif party_m == " request " then
if player : get_attribute ( " partypending " ) ~= nil then
party.send_notice ( name , " You have already requested to join another party. Only one join request is allowed to prevent spamming. " )
party.send_notice ( name , " Please rejoin the game if you want to make an different request. " )
return
end
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
if cparty == mod_storage : get_string ( names .. " _party " ) then
2017-10-06 10:30:51 +08:00
if mod_storage : get_string ( names .. " _officer " ) ~= " " or mod_storage : get_string ( names .. " _leader " ) ~= " " then
2017-10-04 20:07:20 +08:00
local off_names = players : get_player_name ( )
2017-10-06 21:05:59 +08:00
party.send_notice ( off_names , name .. " has requested to join the party. Use '/p accept <playername>' to accept, '/p reject <playername>' to reject. " )
2017-10-04 20:07:20 +08:00
end
end
end
party.send_notice ( name , " Your request to join " .. cparty .. " 's party [ " .. param2 .. " ] has been sent. " )
party.send_notice ( name , " Pending approval from an officer/leader. If you do not receive a reply soon, it is likely there's no one online to review your request. " )
party.send_notice ( name , " Please do not leave the game, your join request will be rendered void if you do so. " )
player : set_attribute ( " partypending " , cparty )
-- private mode, denies all requests
elseif party_m == " private " then
party.send_notice ( name , " Party is private! Public join requests are denied! " )
-- public mode, accept all requests
else party.join ( name , cparty )
end
else party.send_notice ( name , " Party does not exist! " )
end
2017-10-11 18:31:03 +08:00
-- /p home
elseif param1 == " home " then
if party.check ( name , 1 ) == true then
return
end
local cparty_home = mod_storage : get_string ( cparty .. " _home " )
if cparty_home ~= " " then
party.send_notice ( name , " Teleporting to party home... " )
player : set_pos ( minetest.deserialize ( cparty_home ) )
else party.send_notice ( name , " Party home is not set by leader! " )
end
elseif param1 == " chat " then
if party.check ( name , 1 ) == true then
return
end
if ( param2 == " main " or param2 == " global " ) then
player : set_attribute ( " partychat " , " main " )
party.send_notice ( name , " Chat input set to main chat. " )
elseif param2 == " party " then
player : set_attribute ( " partychat " , " party " )
party.send_notice ( name , " Chat input set to party chat. " )
elseif param2 == " squad " then
if mod_storage : get_string ( name .. " _squad " ) == " " then
party.send_notice ( name , " You are not in a squad! " )
return
end
player : set_attribute ( " partychat " , " squad " )
party.send_notice ( name , " Chat input set to squad chat. " )
elseif param2 == nil then
party.send_notice ( name , " Current chat input is set to " .. player : get_attribute ( " partychat " ) .. " chat. " )
end
2017-10-06 21:05:59 +08:00
-- /p noinvite
2017-10-04 20:07:20 +08:00
elseif param1 == " noinvite " then
2017-10-06 10:30:51 +08:00
if cparty == " " then
2017-10-04 20:07:20 +08:00
if player : get_attribute ( " partynoinvite " ) == " true " then
player : set_attribute ( " partynoinvite " , nil )
party.send_notice ( name , " You have disabled noinvite - You will now receive party invites. " )
elseif player : get_attribute ( " partynoinvite " ) == nil then
player : set_attribute ( " partyinvite " , nil )
player : set_attribute ( " partynoinvite " , " true " )
party.send_notice ( name , " You have enabled noinvite - You will now NOT receive party invites. " )
end
else party.send_notice ( name , " You are already in a party! Invites wouldn't be received when you are in a party! " )
end
2017-10-10 22:11:45 +08:00
-- /p pvp
elseif param1 == " pvp " then
if player : get_attribute ( " partypvp " ) == " true " then
player : set_attribute ( " partypvp " , nil )
party.send_notice ( name , " NO friendly fire is ENABLED. " )
elseif player : get_attribute ( " partypvp " ) == nil then
player : set_attribute ( " partypvp " , " true " )
party.send_notice ( name , " Friendly fire is ENABLED. " )
end
2017-10-06 10:27:11 +08:00
-- =======================
-- = LEADERSHIP COMMANDS =
-- =======================
2017-10-06 21:05:59 +08:00
-- /p disband
2017-10-05 02:59:20 +08:00
elseif param1 == " disband " then
2017-10-04 20:07:20 +08:00
if party.check ( name , 3 ) == true then
return
end
if cparty == name then
party.send_notice_all ( name , name .. " 's party [ " .. mod_storage : get_string ( name .. " _leader " ) .. " ] has been disbanded. " )
-- remove online players
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
if mod_storage : get_string ( names .. " _party " ) == cparty then
2017-10-05 18:24:35 +08:00
party.leave ( names )
2017-10-04 20:07:20 +08:00
end
end
-- mark offline players so they would be notified when they login
for _ , playernames in ipairs ( player_list ) do
if minetest.get_player_by_name ( playernames ) == nil then
if mod_storage : get_string ( playernames .. " _party " ) == cparty then
mod_storage : set_string ( playernames .. " _party " , " @ " )
2017-10-05 18:24:35 +08:00
-- open up the alliance name for taking
mod_storage : set_string ( playernames .. " _officer " , nil )
mod_storage : set_string ( playernames .. " _leader " , nil )
mod_storage : set_string ( playernames .. " _lock " , nil )
2017-10-12 22:43:34 +08:00
mod_storage : set_string ( playernames .. " _title " , nil )
2017-10-04 20:07:20 +08:00
end
end
end
-- remove leader's powers
mod_storage : set_string ( name .. " _party " , nil )
mod_storage : set_string ( name .. " _leader " , nil )
mod_storage : set_string ( name .. " _lock " , nil )
2017-10-12 22:43:34 +08:00
mod_storage : set_string ( name .. " _colour " , nil )
mod_storage : set_string ( name .. " _title " , nil )
mod_storage : set_string ( name .. " _home " , nil )
2017-10-06 09:44:00 +08:00
player : set_nametag_attributes ( { text = name } )
2017-10-04 20:07:20 +08:00
end
elseif param1 == " rename " and param2 ~= nil then
if party.check ( name , 3 ) == true then
return
end
-- check if new name is too long
2017-10-13 00:55:16 +08:00
if string.len ( param2 ) > PARTY_PARTY_NAME_LENGTH then
party.send_notice ( name , " Nametag is too long! " .. PARTY_PARTY_NAME_LENGTH .. " is the maximum amount of characters " )
2017-10-04 20:07:20 +08:00
return
end
if party.check_tag ( name , param2 ) == true then
2017-10-13 10:25:22 +08:00
party.send_notice ( name , " Party name selected already exists. Please choose another one. " )
2017-10-04 20:07:20 +08:00
return
end
-- if not, apply rename
mod_storage : set_string ( name .. " _leader " , param2 )
party.send_notice_all ( name , name .. " renamed the party tag to [ " .. param2 .. " ]. " )
-- update online player nametags
2017-10-12 22:43:34 +08:00
local tcolour = mod_storage : get_string ( name .. " _colour " )
if tcolour == " " then
2017-10-13 00:55:16 +08:00
tcolour = PARTY_TAG_COLOUR
2017-10-12 22:43:34 +08:00
end
2017-10-04 20:07:20 +08:00
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
2017-10-12 22:43:34 +08:00
local csquad = mod_storage : get_string ( names .. " _squad " )
if mod_storage : get_string ( names .. " _party " ) == cparty and csquad == " " then
2017-10-13 10:25:22 +08:00
players : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. param2 .. " ] " ) .. " " .. names } )
2017-10-12 22:43:34 +08:00
elseif mod_storage : get_string ( names .. " _party " ) == cparty and csquad ~= " " then
2017-10-13 10:25:22 +08:00
players : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. param2 .. " - " .. csquad .. " ] " ) .. " " .. names } )
2017-10-04 20:07:20 +08:00
end
end
2017-10-12 22:43:34 +08:00
elseif param1 == " colour " and param2 ~= nil then
if party.check ( name , 3 ) == true then
return
end
party.send_notice ( name , " Party tag colour is set to " .. minetest.colorize ( param2 , param2 ) .. " . " )
mod_storage : set_string ( name .. " _colour " , param2 )
-- update online player nametags
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
local tcolour = mod_storage : get_string ( cparty .. " _colour " )
if tcolour == " " then
2017-10-13 00:55:16 +08:00
tcolour = PARTY_TAG_COLOUR
2017-10-12 22:43:34 +08:00
end
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
local csquad = mod_storage : get_string ( names .. " _squad " )
if mod_storage : get_string ( names .. " _party " ) == cparty and csquad == " " then
2017-10-13 10:25:22 +08:00
players : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. cparty_l .. " ] " ) .. " " .. names } )
2017-10-12 22:43:34 +08:00
elseif mod_storage : get_string ( names .. " _party " ) == cparty and csquad ~= " " then
2017-10-13 10:25:22 +08:00
players : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. cparty_l .. " - " .. csquad .. " ] " ) .. " " .. names } )
2017-10-12 22:43:34 +08:00
end
end
2017-10-04 20:07:20 +08:00
elseif param1 == " lock " then
if party.check ( name , 3 ) == true then
return
end
local cparty_l = mod_storage : get_string ( name .. " _leader " )
if param2 == " active " then
mod_storage : set_string ( name .. " _lock " , param2 )
party.send_notice_all ( name , " [Active mode] Public joining (Only if leader is online) is enabled for " .. name .. " 's party [ " .. cparty_l .. " ]. " )
elseif param2 == " request " then
mod_storage : set_string ( name .. " _lock " , param2 )
party.send_notice_all ( name , " [Request mode] Join requests is enabled for " .. name .. " 's party [ " .. cparty_l .. " ]. " )
elseif param2 == " private " then
mod_storage : set_string ( name .. " _lock " , param2 )
2017-10-10 20:59:51 +08:00
party.send_notice_all ( name , " [Private mode] Public joining is disabled for " .. name .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-04 20:07:20 +08:00
elseif param2 == " open " then
2017-10-11 01:54:53 +08:00
mod_storage : set_string ( name .. " _lock " , nil )
2017-10-10 20:59:51 +08:00
party.send_notice_all ( name , " [Open mode] Public joining is enabled for " .. name .. " 's party [ " .. cparty_l .. " ]. " )
2017-10-04 20:07:20 +08:00
end
2017-10-11 18:31:03 +08:00
elseif param1 == " sethome " then
if party.check ( name , 3 ) == true then
return
end
if param2 == " remove " then
mod_storage : set_string ( cparty .. " _home " , nil )
party.send_notice ( name , " Party home removed! " )
else
mod_storage : set_string ( cparty .. " _home " , minetest.serialize ( player : get_pos ( ) ) )
party.send_notice ( name , " Party home has been set to " .. minetest.serialize ( player : get_pos ( ) ) )
end
2017-10-04 20:07:20 +08:00
2017-10-06 21:05:59 +08:00
-- /p officer
2017-10-04 20:07:20 +08:00
elseif param1 == " officer " and param2 ~= nil then
if party.check ( name , 3 ) == true then
return
end
local cparty_l = mod_storage : get_string ( name .. " _leader " )
if minetest.player_exists ( param2 ) then
local target_party = mod_storage : get_string ( param2 .. " _party " )
-- if player is not in same party
if target_party ~= cparty then
party.send_notice ( name , " Player " .. param2 .. " does not exist or is not in your party! Case sensitive. " )
return
-- if player is in same party then promote/demote accordingly
elseif target_party == cparty then
local target_status = mod_storage : get_string ( param2 .. " _officer " )
2017-10-06 10:30:51 +08:00
if target_status == " " then
2017-10-04 20:07:20 +08:00
mod_storage : set_string ( param2 .. " _officer " , " true " )
party.send_notice_all ( name , param2 .. " has been promoted to an officer! " )
2017-10-06 10:30:51 +08:00
elseif target_status ~= " " then
2017-10-04 20:07:20 +08:00
mod_storage : set_string ( param2 .. " _officer " , nil )
party.send_notice_all ( name , param2 .. " has been demoted to a member. " )
end
end
else party.send_notice ( name , " Player " .. param2 .. " does not exist! Case sensitive. " )
end
2017-10-10 22:11:45 +08:00
elseif param1 == " title " and param2 ~= nil and param3 ~= nil then
if party.check ( name , 3 ) == true then
return
end
if minetest.player_exists ( param2 ) then
if cparty ~= mod_storage : get_string ( param2 .. " _party " ) then
party.send_notice ( name , " Player " .. param2 .. " is not in your party! " )
return
end
if ( param3 == " remove " or param3 == " nil " ) then
mod_storage : set_string ( param2 .. " _title " , nil )
party.send_notice ( name , " Player " .. param2 .. " 's title has been removed " )
else
mod_storage : set_string ( param2 .. " _title " , param3 )
party.send_notice ( name , " Player " .. param2 .. " 's title has been set to " .. param3 )
end
2017-10-13 14:08:23 +08:00
end
2017-10-10 22:11:45 +08:00
2017-10-06 21:05:59 +08:00
-- /p kick
2017-10-04 20:07:20 +08:00
elseif param1 == " kick " and param2 ~= nil then
if party.check ( name , 2 ) == true then
return
end
if minetest.player_exists ( param2 ) then
local cparty = mod_storage : get_string ( param2 .. " _party " )
local self_cparty = mod_storage : get_string ( name .. " _party " )
-- attempt to kick self
if param2 == name then
party.send_notice ( name , " You can't kick yourself! " )
return
-- attempt to kick someone not from your party
elseif self_cparty ~= cparty then
party.send_notice ( name , " Player " .. param2 .. " does not exist or is not in your party! Case sensitive. " )
return
-- attempt to kick leader
elseif param2 == cparty then
party.send_notice ( name , " You can't kick the leader! " )
party.send_notice_all ( name , name .. " attempted to kick the leader. " )
return
-- attempt to kick fellow officer (if officer too)
2017-10-06 10:30:51 +08:00
elseif mod_storage : get_string ( name .. " _officer " ) ~= " " and mod_storage : get_string ( param2 .. " _officer " ) ~= " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You can't kick a fellow officer! " )
party.send_notice_all ( name , name .. " attempted to kick a fellow officer. " )
return
end
-- kicking offline player, give a mark to notify player when he logins
if minetest.get_player_by_name ( param2 ) == nil then
2017-10-11 01:54:53 +08:00
party.send_notice_all ( name , param2 .. " [offline] was kicked from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] by " .. name )
2017-10-05 18:24:35 +08:00
mod_storage : set_string ( param2 .. " _party " , " # " )
mod_storage : set_string ( param2 .. " _officer " , nil )
2017-10-04 20:07:20 +08:00
end
-- kicking online player
if minetest.get_player_by_name ( param2 ) ~= nil then
2017-10-10 20:59:51 +08:00
party.send_notice_all ( name , param2 .. " was kicked from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] by " .. name )
2017-10-11 00:18:04 +08:00
party.leave ( param2 )
2017-10-04 20:07:20 +08:00
end
-- if player doesn't exist
else party.send_notice ( name , " Player " .. param2 .. " does not exist! Case sensitive. " )
end
-- Accept/reject join request
elseif ( param1 == " accept " or param1 == " reject " ) and param2 ~= nil then
if party.check ( name , 2 ) == true then
return
end
if minetest.player_exists ( param2 ) then
-- Reject if player is not online
if minetest.get_player_by_name ( param2 ) == nil then
party.send_notice ( name , " Player " .. param2 .. " is not online right now. " )
return
end
local target_party = mod_storage : get_string ( param2 .. " _party " )
-- Reject if player did not request to join the party
if minetest.get_player_by_name ( param2 ) : get_attribute ( " partypending " ) ~= cparty then
party.send_notice ( name , " Player " .. param2 .. " did not request to join the party! " )
return
-- Reject if player is already in a party
2017-10-06 10:30:51 +08:00
elseif target_party ~= " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " Player " .. param2 .. " is already in a party! " )
return
end
local t_player = minetest.get_player_by_name ( param2 )
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
if param1 == " accept " then
t_player : set_attribute ( " partypending " , nil )
party.send_notice ( param2 , " Your request to join " .. cparty .. " [ " .. cparty_l .. " ] has been accepted! " )
party.join ( param2 , cparty )
elseif param1 == " reject " then
t_player : set_attribute ( " partypending " , nil )
party.send_notice ( param2 , " Your request to join " .. cparty .. " [ " .. cparty_l .. " ] was denied. " )
party.send_notice ( name , " You have denied " .. param2 .. " 's request. " )
end
else party.send_notice ( name , " Player " .. param2 .. " does not exist! " )
end
2017-11-18 08:03:29 +08:00
elseif param1 == " invite " and param2 ~= nil then
2017-10-06 10:30:51 +08:00
if cparty ~= " " then
2017-10-04 20:07:20 +08:00
if party.check ( name , 2 ) == true then
return
end
if minetest.player_exists ( param2 ) then
-- reject if player is not online
local target_party = mod_storage : get_string ( param2 .. " _party " )
local t_player = minetest.get_player_by_name ( param2 )
if minetest.get_player_by_name ( param2 ) == nil then
party.send_notice ( name , " Player is not online! " )
return
-- reject if player is already in a party
2017-10-06 10:30:51 +08:00
elseif target_party ~= " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " Player is already in a party! " )
return
-- reject if player disabled invites
elseif t_player : get_attribute ( " partynoinvite " ) == " true " then
party.send_notice ( name , " Player has disabled invites! " )
return
end
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
t_player : set_attribute ( " partyinvite " , name )
2017-10-06 21:05:59 +08:00
party.send_notice ( param2 , name .. " has invited you to " .. cparty .. " 's party [ " .. cparty_l .. " ]! '/p invite yes' to accept or '/p invite no' to decline. " )
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " You have invited " .. param2 .. " to your party. Awaiting for their response. " )
-- player does not exist
else party.send_notice ( name , " Player " .. param2 .. " does not exist! Case sensitive. " )
end
2017-10-06 10:30:51 +08:00
elseif cparty == " " and param2 == " no " then
2017-10-04 20:07:20 +08:00
if player : get_attribute ( " partyinvite " ) ~= nil then
local iname = player : get_attribute ( " partyinvite " )
local iparty = mod_storage : get_string ( iname .. " _party " )
local iparty_l = mod_storage : get_string ( iparty .. " _leader " )
player : set_attribute ( " partyinvite " , nil )
party.send_notice ( name , " You have rejected " .. iname .. " 's invite to join " .. iparty .. " 's party [ " .. iparty_l .. " ]. " )
-- if player that sent request is online, send him a message.
if minetest.get_player_by_name ( iname ) ~= nil then
party.send_notice ( iname , name .. " has denied your invite request. " )
end
else party.send_notice ( name , " You have not received an invite! " )
end
2017-10-06 10:30:51 +08:00
elseif cparty == " " and param2 == " yes " then
2017-10-04 20:07:20 +08:00
if player : get_attribute ( " partyinvite " ) ~= nil then
local iname = player : get_attribute ( " partyinvite " )
local iparty = mod_storage : get_string ( iname .. " _party " )
local iparty_l = mod_storage : get_string ( iparty .. " _leader " )
-- if player that sent request is online, send him a message.
if minetest.get_player_by_name ( iparty ) ~= nil then
party.send_notice ( iname , name .. " has accepted your invite request. " )
end
player : set_attribute ( " partyinvite " , nil )
party.join ( name , iparty )
else party.send_notice ( name , " You have not received an invite! " )
end
else party.send_notice ( name , " You are not in a party! " )
end
2017-10-06 10:27:11 +08:00
2017-10-04 20:07:20 +08:00
2017-10-06 10:27:11 +08:00
-- =======================
-- ==== ADMIN COMMANDS ===
-- =======================
elseif param1 == " forcedisband " and param2 ~= nil then
if not minetest.check_player_privs ( name , { ban = true } ) then
party.send_notice ( name , " You are not an admin! " )
return
end
if party.check_tag ( name , param2 ) == true then
local leadername = " "
for _ , playernames in ipairs ( player_list ) do
if param2 == mod_storage : get_string ( playernames .. " _leader " ) then
leadername = leadername .. playernames
end
end
local cparty = leadername
party.send_notice ( name , " You have disbanded " .. leadername .. " 's party [ " .. param2 .. " ] " )
party.send_notice_all ( leadername , leadername .. " 's party [ " .. mod_storage : get_string ( leadername .. " _leader " ) .. " ] has been disbanded by " .. name .. " , an admin " )
-- remove online players
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
if mod_storage : get_string ( names .. " _party " ) == cparty then
party.leave ( names )
end
end
-- mark offline players so they would be notified when they login
for _ , playernames in ipairs ( player_list ) do
if minetest.get_player_by_name ( playernames ) == nil then
if mod_storage : get_string ( playernames .. " _party " ) == cparty then
mod_storage : set_string ( playernames .. " _party " , " = " )
-- open up the alliance name for taking
mod_storage : set_string ( playernames .. " _officer " , nil )
mod_storage : set_string ( playernames .. " _leader " , nil )
mod_storage : set_string ( playernames .. " _lock " , nil )
end
end
end
else party.send_notice ( name , " Party does not exist! " )
end
2017-10-11 01:54:53 +08:00
elseif param1 == " forcejoin " and param2 ~= nil then
if not minetest.check_player_privs ( name , { ban = true } ) then
party.send_notice ( name , " You are not an admin! " )
return
end
if cparty ~= " " then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " You are already in " .. cparty .. " 's party [ " .. cparty_l .. " ]. " )
return
end
if party.check_tag ( name , param2 ) == true then
local leadername = " "
for _ , playernames in ipairs ( player_list ) do
if param2 == mod_storage : get_string ( playernames .. " _leader " ) then
leadername = leadername .. playernames
end
end
local cparty = leadername
party.join ( name , cparty )
end
elseif param1 == " forcekick " and param2 ~= nil then
if not minetest.check_player_privs ( name , { kick = true } ) then
party.send_notice ( name , " You are not a mod! " )
return
end
if minetest.player_exists ( param2 ) then
local cparty = mod_storage : get_string ( param2 .. " _party " )
-- attempt to kick self
if param2 == name then
party.send_notice ( name , " You can't kick yourself! " )
return
-- attempt to kick player that doesn't have a party
elseif cparty == " " then
party.send_notice ( name , param2 .. " is not in a party! " )
return
-- attempt to kick leader
elseif mod_storage : get_string ( param2 .. " _leader " ) ~= " " then
party.send_notice ( name , " The leader can't be kicked! Use /p forcedisband instead. " )
return
end
-- kicking offline player, give a mark to notify player when he logins
if minetest.get_player_by_name ( param2 ) == nil then
party.send_notice_all ( param2 , param2 .. " [offline] was kicked from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] by an admin, " .. name )
mod_storage : set_string ( param2 .. " _party " , " + " )
mod_storage : set_string ( param2 .. " _officer " , nil )
party.send_notice ( name , " Kicked " .. param2 .. " [offline] from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] " )
else
2017-10-12 12:00:23 +08:00
-- check if online player is a squad leader
if mod_storage : get_string ( param2 .. " _squad_leader " ) ~= " " then
-- disband squad if so
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
if mod_storage : get_string ( names .. " _party " ) == mod_storage : get_string ( param2 .. " _party " ) and mod_storage : get_string ( names .. " _squad " ) == mod_storage : get_string ( param2 .. " _squad " ) then
squad.leave ( names )
end
end
party.send_notice_all ( param2 , param2 .. " was kicked from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] by an admin, " .. name )
party.send_notice ( name , " Kicked " .. param2 .. " from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] " )
party.leave ( param2 )
-- if not, normal kick
else
party.send_notice_all ( param2 , param2 .. " was kicked from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] by an admin, " .. name )
party.send_notice ( name , " Kicked " .. param2 .. " from " .. cparty .. " 's party [ " .. mod_storage : get_string ( cparty .. " _leader " ) .. " ] " )
party.leave ( param2 )
end
2017-10-11 01:54:53 +08:00
end
end
2017-10-04 20:07:20 +08:00
2017-10-06 21:05:59 +08:00
else party.send_notice ( name , " ERROR: Command is invalid! For help, use the command '/p help' " )
2017-10-04 20:07:20 +08:00
end
end ,
} )
minetest.register_on_chat_message ( function ( name , message )
local player = minetest.get_player_by_name ( name )
local cparty = mod_storage : get_string ( name .. " _party " )
2017-10-10 22:11:45 +08:00
local cparty_title = mod_storage : get_string ( name .. " _title " )
2017-10-11 18:31:03 +08:00
local csquad = mod_storage : get_string ( name .. " _squad " )
local cinput = player : get_attribute ( " partychat " )
2017-10-05 02:59:20 +08:00
-- check if player has shout privs
if not minetest.check_player_privs ( name , { shout = true } ) then
return
end
2017-10-11 18:31:03 +08:00
-- chat logging
if cparty == " " then
minetest.log ( " action " , " CHAT : < " .. name .. " > : " .. message )
elseif cparty ~= " " then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
if string.match ( message , " ^@(.+) " ) then
minetest.log ( " action " , " CHAT : < " .. name .. " > : " .. string.gsub ( message , " ^@ " , " " ) )
elseif cinput == " main " then
minetest.log ( " action " , " CHAT : < " .. name .. " > : " .. string.gsub ( message , " ^@ " , " " ) )
else minetest.log ( " action " , " CHAT [PARTY: " .. cparty_l .. " ] : < " .. name .. " > : " .. message )
end
end
2017-10-04 20:07:20 +08:00
for _ , players in ipairs ( minetest.get_connected_players ( ) ) do
local names = players : get_player_name ( )
2017-10-05 18:24:35 +08:00
2017-10-11 18:31:03 +08:00
-- Main chat
if cparty == " " then
minetest.chat_send_player ( names , " < " .. name .. " > " .. message )
end
-- Main chat (@)
if string.match ( message , " ^@(.+) " ) and cparty ~= " " then
2017-10-05 18:24:35 +08:00
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
minetest.chat_send_player ( names , " <Party: " .. cparty_l .. " | " .. name .. " > " .. string.gsub ( message , " ^@ " , " " ) )
end
2017-10-11 18:31:03 +08:00
-- Main chat (chat input)
if cinput == " main " and cparty ~= " " and not string.match ( message , " ^@(.+) " ) then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
minetest.chat_send_player ( names , " <Party: " .. cparty_l .. " | " .. name .. " > " .. message )
end
-- Party Chat
if cparty == mod_storage : get_string ( names .. " _party " ) and cinput == " party " and not string.match ( message , " ^@(.+) " ) then
2017-10-10 22:11:45 +08:00
if cparty_title ~= " " then
minetest.chat_send_player ( names , minetest.colorize ( " limegreen " , " [Party] " ) .. " < " .. minetest.colorize ( " lightgrey " , cparty_title ) .. " " .. name .. " > " .. message )
elseif cparty_title == " " then
minetest.chat_send_player ( names , minetest.colorize ( " limegreen " , " [Party] " ) .. " < " .. name .. " > " .. message )
2017-10-11 18:31:03 +08:00
end
-- Squad chat
elseif cparty == mod_storage : get_string ( names .. " _party " ) and csquad == mod_storage : get_string ( names .. " _squad " ) and cinput == " squad " and not string.match ( message , " ^@(.+) " ) then
if cparty_title ~= " " then
minetest.chat_send_player ( names , minetest.colorize ( " orange " , " [Squad] " ) .. " < " .. minetest.colorize ( " lightgrey " , cparty_title ) .. " " .. name .. " > " .. message )
elseif cparty_title == " " then
minetest.chat_send_player ( names , minetest.colorize ( " orange " , " [Squad] " ) .. " < " .. name .. " > " .. message )
2017-10-10 22:11:45 +08:00
end
2017-10-13 14:08:23 +08:00
end
end
-- chat spy
if cparty ~= " " and not string.match ( message , " ^@(.+) " ) then
if cinput == " party " or cinput == " squad " then
party.chat_spy ( name , message )
2017-10-04 20:07:20 +08:00
end
end
2017-10-13 01:23:21 +08:00
-- irc register --
if minetest.get_modpath ( " irc " ) and PARTY_IRC_HIDE == " true " then
if not irc.connected
or message : sub ( 1 , 1 ) == " / "
or message : sub ( 1 , 5 ) == " [off] "
or not irc.joined_players [ name ]
or ( not minetest.check_player_privs ( name , { shout = true } ) ) then
return
end
if cparty == ( nil or " " ) then
local nl = message : find ( " \n " , 1 , true )
if nl then
message = message : sub ( 1 , nl - 1 )
end
irc.say ( irc.playerMessage ( name , core.strip_colors ( message ) ) )
elseif cparty ~= ( nil or " " ) and string.match ( message , " ^@(.+) " ) then
local nl = message : find ( " \n " , 1 , true )
if nl then
message = message : sub ( 1 , nl - 1 )
end
local newmessage = string.gsub ( message , " ^@ " , " " )
irc.say ( irc.playerMessage ( name , core.strip_colors ( newmessage ) ) )
elseif cparty ~= ( nil or " " ) and cinput == " main " and not string.match ( message , " ^@(.+) " ) then
local nl = message : find ( " \n " , 1 , true )
if nl then
message = message : sub ( 1 , nl - 1 )
end
irc.say ( irc.playerMessage ( name , core.strip_colors ( message ) ) )
end
end
2017-10-05 18:24:35 +08:00
2017-10-04 20:07:20 +08:00
return true
end )
minetest.register_on_punchplayer ( function ( player , hitter , time_from_last_punch , tool_capabilities , dir , damage )
if player and hitter then
local playername = player : get_player_name ( )
local hittername = hitter : get_player_name ( )
local p_party = mod_storage : get_string ( playername .. " _party " )
local h_party = mod_storage : get_string ( hittername .. " _party " )
2017-10-10 22:11:45 +08:00
local p_pvp = player : get_attribute ( " partypvp " )
local h_pvp = hitter : get_attribute ( " partypvp " )
2017-10-06 10:30:51 +08:00
if p_party ~= " " and p_party == h_party then
2017-10-10 22:11:45 +08:00
if ( p_pvp == nil or h_pvp == nil ) then
party.send_notice ( hitter : get_player_name ( ) , player : get_player_name ( ) .. " is in your party and has no friendly fire enabled! " )
return true
end
2017-10-04 20:07:20 +08:00
end
end
end )
minetest.register_on_joinplayer ( function ( player )
local name = player : get_player_name ( )
local cparty = mod_storage : get_string ( name .. " _party " )
-- delete invite/join request status when player join, just in case.
player : set_attribute ( " partypending " , nil )
player : set_attribute ( " partyinvite " , nil )
-- clear all stats (just in case) if player get kick / party is disbanded / data is corrupted
if cparty == " @ " then
2017-10-05 02:59:20 +08:00
party.send_notice ( name , " While you were away, your party has disbanded! " )
2017-10-05 18:24:35 +08:00
party.leave ( name )
2017-10-04 20:07:20 +08:00
elseif cparty == " # " then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
2017-10-05 02:59:20 +08:00
party.send_notice ( name , " While you were away, you were kicked from your party! " )
2017-10-05 18:24:35 +08:00
party.leave ( name )
2017-10-11 01:54:53 +08:00
elseif cparty == " + " then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " While you were away, you were kicked from your party by an admin! " )
party.leave ( name )
2017-10-05 18:24:35 +08:00
elseif cparty == " = " then
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
party.send_notice ( name , " While you were away, your party was disbanded by an admin! " )
party.leave ( name )
2017-10-06 10:30:51 +08:00
elseif cparty ~= " " then
2017-10-04 20:07:20 +08:00
local cparty_l = mod_storage : get_string ( cparty .. " _leader " )
2017-10-06 10:30:51 +08:00
if cparty_l == " " then
2017-10-04 20:07:20 +08:00
party.send_notice ( name , " ERROR: Unable to load your party's name. " )
party.send_notice ( name , " ERROR: While you are away, you were either kicked or the party disbanded and was recreated. " )
party.send_notice ( name , " ERROR: Otherwise something became corrupted :/ " )
party.send_notice ( name , " ERROR: Your party info has been reset. " )
2017-10-05 18:24:35 +08:00
party.leave ( name )
2017-10-04 20:07:20 +08:00
return
else
2017-10-12 22:43:34 +08:00
local tcolour = mod_storage : get_string ( cparty .. " _colour " )
if tcolour == " " then
2017-10-13 00:55:16 +08:00
tcolour = PARTY_TAG_COLOUR
2017-10-12 22:43:34 +08:00
end
player : set_nametag_attributes ( { text = minetest.colorize ( tcolour , " [ " .. cparty_l .. " ] " ) .. " " .. name } )
2017-10-04 20:07:20 +08:00
end
end
end )
minetest.register_on_leaveplayer ( function ( player )
-- delete invite/join request status when player leaves
player : set_attribute ( " partypending " , nil )
player : set_attribute ( " partyinvite " , nil )
2017-10-12 22:59:47 +08:00
end )
-- register some global functions to allow external mods to obtain and set mod storage values
party.get_value = function ( value )
return mod_storage : get_string ( value )
end
party.set_value = function ( value , newvalue )
mod_storage : set_string ( value , newvalue )
2017-11-18 08:03:29 +08:00
end