forked from mtcontrib/factions
Renamed mod to "factions"
This commit is contained in:
parent
1145203353
commit
62b8f82c6a
112
chatcommands.lua
112
chatcommands.lua
@ -1,10 +1,10 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file chatcommnd.lua
|
--! @file chatcommnd.lua
|
||||||
--! @brief factionsmod chat interface
|
--! @brief factions chat interface
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
@ -12,20 +12,20 @@
|
|||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
--! @class factionsmod_chat
|
--! @class factions_chat
|
||||||
--! @brief chat interface class
|
--! @brief chat interface class
|
||||||
factionsmod_chat = {}
|
factions_chat = {}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: init()
|
-- name: init()
|
||||||
--
|
--
|
||||||
--! @brief initialize chat interface
|
--! @brief initialize chat interface
|
||||||
--! @memberof factionsmod_chat
|
--! @memberof factions_chat
|
||||||
--! @public
|
--! @public
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
factionsmod.register_command = function(cmd_name, cmd)
|
factions.register_command = function(cmd_name, cmd)
|
||||||
factionsmod.commands[cmd_name] = { -- default command
|
factions.commands[cmd_name] = { -- default command
|
||||||
name = cmd_name,
|
name = cmd_name,
|
||||||
faction_permissions = {},
|
faction_permissions = {},
|
||||||
global_privileges = {},
|
global_privileges = {},
|
||||||
@ -54,7 +54,7 @@ factionsmod.register_command = function(cmd_name, cmd)
|
|||||||
local argtype = format[i]
|
local argtype = format[i]
|
||||||
local arg = argv[i]
|
local arg = argv[i]
|
||||||
if argtype == "faction" then
|
if argtype == "faction" then
|
||||||
local fac = factionsmod.factions[arg]
|
local fac = factions.factions[arg]
|
||||||
if not fac then
|
if not fac then
|
||||||
--TODO: error (faction required)
|
--TODO: error (faction required)
|
||||||
return false
|
return false
|
||||||
@ -81,7 +81,7 @@ factionsmod.register_command = function(cmd_name, cmd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- checks if player in faction
|
-- checks if player in faction
|
||||||
local player_faction = factionsmod.players[faction]
|
local player_faction = factions.players[faction]
|
||||||
if not player_faction and self.infaction then
|
if not player_faction and self.infaction then
|
||||||
--TODO: error message
|
--TODO: error message
|
||||||
return false
|
return false
|
||||||
@ -96,7 +96,7 @@ factionsmod.register_command = function(cmd_name, cmd)
|
|||||||
|
|
||||||
-- get some more data
|
-- get some more data
|
||||||
local pos = minetest.get_player_by_name(player):getpos()
|
local pos = minetest.get_player_by_name(player):getpos()
|
||||||
local chunkpos = factionsmod.get_chunk_pos(pos)
|
local chunkpos = factions.get_chunk_pos(pos)
|
||||||
return self.on_success(player, player_faction, pos, chunkpos, args)
|
return self.on_success(player, player_faction, pos, chunkpos, args)
|
||||||
end,
|
end,
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -105,13 +105,13 @@ factionsmod.register_command = function(cmd_name, cmd)
|
|||||||
}
|
}
|
||||||
-- override defaults
|
-- override defaults
|
||||||
for k, v in pairs(cmd) do
|
for k, v in pairs(cmd) do
|
||||||
factionsmod.commands[cmd_name][k] = v
|
factions.commands[cmd_name][k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function factionsmod_chat.init()
|
function factions_chat.init()
|
||||||
|
|
||||||
minetest.register_privilege("faction_user",
|
minetest.register_privilege("faction_user",
|
||||||
{
|
{
|
||||||
@ -122,17 +122,17 @@ function factionsmod_chat.init()
|
|||||||
|
|
||||||
minetest.register_privilege("faction_admin",
|
minetest.register_privilege("faction_admin",
|
||||||
{
|
{
|
||||||
description = "this user is allowed to create or delete factionsmod",
|
description = "this user is allowed to create or delete factions",
|
||||||
give_to_singleplayer = true,
|
give_to_singleplayer = true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
minetest.register_chatcommand("factionsmod",
|
minetest.register_chatcommand("factions",
|
||||||
{
|
{
|
||||||
params = "<cmd> <parameter 1> .. <parameter n>",
|
params = "<cmd> <parameter 1> .. <parameter n>",
|
||||||
description = "faction administration functions",
|
description = "faction administration functions",
|
||||||
privs = { interact=true },
|
privs = { interact=true },
|
||||||
func = factionsmod_chat.cmdhandler,
|
func = factions_chat.cmdhandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ function factionsmod_chat.init()
|
|||||||
params = "<factionname> text",
|
params = "<factionname> text",
|
||||||
description = "send message to a specific faction",
|
description = "send message to a specific faction",
|
||||||
privs = { faction_user=true },
|
privs = { faction_user=true },
|
||||||
func = factionsmod_chat.chathandler,
|
func = factions_chat.chathandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -152,11 +152,11 @@ end
|
|||||||
-- R E G I S T E R E D C O M M A N D S |
|
-- R E G I S T E R E D C O M M A N D S |
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
factionsmod.register_command ("claim", {
|
factions.register_command ("claim", {
|
||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Claim the plot of land you're on.",
|
description = "Claim the plot of land you're on.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local chunk = factionsmod.chunk[chunkpos]
|
local chunk = factions.chunk[chunkpos]
|
||||||
if not chunk then
|
if not chunk then
|
||||||
--TODO: success message
|
--TODO: success message
|
||||||
player_faction:claim_chunk(chunkpos)
|
player_faction:claim_chunk(chunkpos)
|
||||||
@ -173,11 +173,11 @@ factionsmod.register_command ("claim", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("unclaim", {
|
factions.register_command("unclaim", {
|
||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Unclaim the plot of land you're on.",
|
description = "Unclaim the plot of land you're on.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local chunk = factionsmod.chunk[chunkpos]
|
local chunk = factions.chunk[chunkpos]
|
||||||
if chunk ~= player_faction.name then
|
if chunk ~= player_faction.name then
|
||||||
--TODO: error (not your faction's chunk)
|
--TODO: error (not your faction's chunk)
|
||||||
return false
|
return false
|
||||||
@ -189,11 +189,11 @@ factionsmod.register_command("unclaim", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--list all known factions
|
--list all known factions
|
||||||
factionsmod.register_command("list", {
|
factions.register_command("list", {
|
||||||
description = "List all registered factions.",
|
description = "List all registered factions.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local list = factionsmod.get_faction_list()
|
local list = factions.get_faction_list()
|
||||||
local tosend = "factionsmod: current available factionsmod:"
|
local tosend = "factions: current available factionsmod:"
|
||||||
|
|
||||||
for i,v in ipairs(list) do
|
for i,v in ipairs(list) do
|
||||||
if i ~= #list then
|
if i ~= #list then
|
||||||
@ -207,27 +207,27 @@ factionsmod.register_command("list", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
--show factionsmod mod version
|
--show factions mod version
|
||||||
factionsmod.register_command("version", {
|
factions.register_command("version", {
|
||||||
description = "Displays mod version.",
|
description = "Displays mod version.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
minetest.chat_send_player(player, "factionsmod: version " .. factionsmod_version , false)
|
minetest.chat_send_player(player, "factions: version " .. factionsmod_version , false)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
--show description of faction
|
--show description of faction
|
||||||
factionsmod.register_command("info", {
|
factions.register_command("info", {
|
||||||
format = {"faction"},
|
format = {"faction"},
|
||||||
description = "Shows a faction's description.",
|
description = "Shows a faction's description.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
minetest.chat_send_player(player,
|
minetest.chat_send_player(player,
|
||||||
"factionsmod: " .. args.factions[1].name .. ": " ..
|
"factions: " .. args.factions[1].name .. ": " ..
|
||||||
args.factions[1].description, false)
|
args.factions[1].description, false)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("leave", {
|
factions.register_command("leave", {
|
||||||
description = "Leave your faction."
|
description = "Leave your faction."
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
faction:remove_player(player)
|
faction:remove_player(player)
|
||||||
@ -236,13 +236,13 @@ factionsmod.register_command("leave", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("kick", {
|
factions.register_command("kick", {
|
||||||
faction_permissions = {"playerlist"},
|
faction_permissions = {"playerlist"},
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
description = "Kick a player from your faction.",
|
description = "Kick a player from your faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local victim = args.players[1]
|
local victim = args.players[1]
|
||||||
if factionsmod.players[victim.name] == faction.name then
|
if factions.players[victim.name] == faction.name then
|
||||||
and victim.name ~= faction.leader -- can't kick da king
|
and victim.name ~= faction.leader -- can't kick da king
|
||||||
faction:remove_player(player)
|
faction:remove_player(player)
|
||||||
--TODO: message?
|
--TODO: message?
|
||||||
@ -255,7 +255,7 @@ factionsmod.register_command("kick", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--create new faction
|
--create new faction
|
||||||
factionsmod.register_command("create", {
|
factions.register_command("create", {
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
infaction = false,
|
infaction = false,
|
||||||
description = "Create a new faction.",
|
description = "Create a new faction.",
|
||||||
@ -265,8 +265,8 @@ factionsmod.register_command("create", {
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local factioname = args.strings[1]
|
local factioname = args.strings[1]
|
||||||
if factionsmod.can_create_faction(factionname) then
|
if factions.can_create_faction(factionname) then
|
||||||
new_faction = factionsmod.create_faction(faction)
|
new_faction = factions.create_faction(faction)
|
||||||
new_faction:add_player(player)
|
new_faction:add_player(player)
|
||||||
new_faction:set_leader(player)
|
new_faction:set_leader(player)
|
||||||
return true
|
return true
|
||||||
@ -277,7 +277,7 @@ factionsmod.register_command("create", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_commmand("join", {
|
factions.register_commmand("join", {
|
||||||
format = {"faction"},
|
format = {"faction"},
|
||||||
description = "Join a faction.",
|
description = "Join a faction.",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
@ -297,7 +297,7 @@ factionsmod.register_commmand("join", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("disband", {
|
factions.register_command("disband", {
|
||||||
faction_permissions = {"disband"},
|
faction_permissions = {"disband"},
|
||||||
description = "Disband your faction.",
|
description = "Disband your faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -307,7 +307,7 @@ factionsmod.register_command("disband", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("close", {
|
factions.register_command("close", {
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"playerslist"},
|
||||||
description = "Make your faction invite-only.",
|
description = "Make your faction invite-only.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -317,7 +317,7 @@ factionsmod.register_command("close", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("open", {
|
factions.register_command("open", {
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"playerslist"},
|
||||||
description = "Allow any player to join your faction.",
|
description = "Allow any player to join your faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -327,7 +327,7 @@ factionsmod.register_command("open", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("description", {
|
factions.register_command("description", {
|
||||||
faction_permissions = {"description"},
|
faction_permissions = {"description"},
|
||||||
description = "Set your faction's description",
|
description = "Set your faction's description",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -337,7 +337,7 @@ factionsmod.register_command("description", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("invite", {
|
factions.register_command("invite", {
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"playerslist"},
|
||||||
description = "Invite a player to your faction.",
|
description = "Invite a player to your faction.",
|
||||||
@ -348,7 +348,7 @@ factionsmod.register_command("invite", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("uninvite", {
|
factions.register_command("uninvite", {
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"playerslist"},
|
||||||
description = "Revoke a player's invite.",
|
description = "Revoke a player's invite.",
|
||||||
@ -359,7 +359,7 @@ factionsmod.register_command("uninvite", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("delete", {
|
factions.register_command("delete", {
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
format = {"faction"},
|
format = {"faction"},
|
||||||
description = "Delete a faction.",
|
description = "Delete a faction.",
|
||||||
@ -370,7 +370,7 @@ factionsmod.register_command("delete", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("ranks", {
|
factions.register_command("ranks", {
|
||||||
description = "List ranks within your faction",
|
description = "List ranks within your faction",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
if not faction then
|
if not faction then
|
||||||
@ -384,7 +384,7 @@ factionsmod.register_command("ranks", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("who", {
|
factions.register_command("who", {
|
||||||
description = "List players in your faction, and their ranks.",
|
description = "List players in your faction, and their ranks.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
if not faction then
|
if not faction then
|
||||||
@ -398,7 +398,7 @@ factionsmod.register_command("who", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("newrank", {
|
factions.register_command("newrank", {
|
||||||
description = "Add a new rank.",
|
description = "Add a new rank.",
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"ranks"},
|
||||||
@ -413,7 +413,7 @@ factionsmod.register_command("newrank", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("delrank", {
|
factions.register_command("delrank", {
|
||||||
description = "Replace and delete a rank.",
|
description = "Replace and delete a rank.",
|
||||||
format = {"string", "string"},
|
format = {"string", "string"},
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"ranks"},
|
||||||
@ -429,7 +429,7 @@ factionsmod.register_command("delrank", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factionsmod.register_command("setspawn", {
|
factions.register_command("setspawn", {
|
||||||
description = "Set the faction's spawn",
|
description = "Set the faction's spawn",
|
||||||
faction_permissions = {"spawn"},
|
faction_permissions = {"spawn"},
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
@ -442,17 +442,17 @@ factionsmod.register_command("setspawn", {
|
|||||||
-- name: cmdhandler(playername,parameter)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
--! @brief chat command handler
|
--! @brief chat command handler
|
||||||
--! @memberof factionsmod_chat
|
--! @memberof factions_chat
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @param playername name
|
--! @param playername name
|
||||||
--! @param parameter data supplied to command
|
--! @param parameter data supplied to command
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod_chat.cmdhandler(playername,parameter)
|
function factions_chat.cmdhandler(playername,parameter)
|
||||||
|
|
||||||
local player = minetest.env:get_player_by_name(playername)
|
local player = minetest.env:get_player_by_name(playername)
|
||||||
local params = parameter:split(" ")
|
local params = parameter:split(" ")
|
||||||
local player_faction = factionsmod.players[playersname]
|
local player_faction = factions.players[playersname]
|
||||||
|
|
||||||
if parameter == nil or
|
if parameter == nil or
|
||||||
parameter == "" then
|
parameter == "" then
|
||||||
@ -464,7 +464,7 @@ function factionsmod_chat.cmdhandler(playername,parameter)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd = factionsmod.commands[params[1]]
|
local cmd = factions.commands[params[1]]
|
||||||
if not cmd then
|
if not cmd then
|
||||||
--TODO: error (unknown command)
|
--TODO: error (unknown command)
|
||||||
end
|
end
|
||||||
@ -482,25 +482,25 @@ end
|
|||||||
-- name: show_help(playername,parameter)
|
-- name: show_help(playername,parameter)
|
||||||
--
|
--
|
||||||
--! @brief send help message to player
|
--! @brief send help message to player
|
||||||
--! @memberof factionsmod_chat
|
--! @memberof factions_chat
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @param playername name
|
--! @param playername name
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod_chat.show_help(playername)
|
function factions_chat.show_help(playername)
|
||||||
|
|
||||||
local MSG = function(text)
|
local MSG = function(text)
|
||||||
minetest.chat_send_player(playername,text,false)
|
minetest.chat_send_player(playername,text,false)
|
||||||
end
|
end
|
||||||
|
|
||||||
MSG("factionsmod mod")
|
MSG("factions mod")
|
||||||
MSG("Usage:")
|
MSG("Usage:")
|
||||||
for k, v in pairs(factionsmod.commands) do
|
for k, v in pairs(factions.commands) do
|
||||||
local args = {}
|
local args = {}
|
||||||
for i in ipairs(v.format) do
|
for i in ipairs(v.format) do
|
||||||
table.insert(args, v.format[i])
|
table.insert(args, v.format[i])
|
||||||
end
|
end
|
||||||
MSG{"\t/factionsmod "..k.." <"..table.concat(args, "> <").."> : "..v.description}
|
MSG{"\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file factionsmod.lua
|
--! @file factions.lua
|
||||||
--! @brief factionsmod core file containing datastorage
|
--! @brief factions core file containing datastorage
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
@ -13,33 +13,33 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
--read some basic information
|
--read some basic information
|
||||||
local factionsmod_worldid = minetest.get_worldpath()
|
local factions_worldid = minetest.get_worldpath()
|
||||||
|
|
||||||
--! @class factionsmod
|
--! @class factions
|
||||||
--! @brief main class for factionsmod
|
--! @brief main class for factions
|
||||||
factionsmod = {}
|
factions = {}
|
||||||
|
|
||||||
--! @brief runtime data
|
--! @brief runtime data
|
||||||
factionsmod.factions = {}
|
factions.factions = {}
|
||||||
factionsmod.chunks = {}
|
factions.chunks = {}
|
||||||
factionsmod.players = {}
|
factions.players = {}
|
||||||
|
|
||||||
factionsmod.print = function(text)
|
factions.print = function(text)
|
||||||
print("factionsmod: " .. dump(text))
|
print("factions: " .. dump(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
factionsmod.dbg_lvl1 = function() end --factionsmod.print -- errors
|
factions.dbg_lvl1 = function() end --factionsmod.print -- errors
|
||||||
factionsmod.dbg_lvl2 = function() end --factionsmod.print -- non cyclic trace
|
factions.dbg_lvl2 = function() end --factionsmod.print -- non cyclic trace
|
||||||
factionsmod.dbg_lvl3 = function() end --factionsmod.print -- cyclic trace
|
factions.dbg_lvl3 = function() end --factionsmod.print -- cyclic trace
|
||||||
|
|
||||||
factionsmod.factions = {}
|
factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factionsmod.lower_claimable_height = -512
|
factions.lower_claimable_height = -512
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||||
factionsmod.can_create_faction = function(name)
|
factions.can_create_faction = function(name)
|
||||||
if factionsmod.factions[name] then
|
if factions.factions[name] then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
@ -48,7 +48,7 @@ end
|
|||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief create a faction object
|
--! @brief create a faction object
|
||||||
factionsmod.new_faction = function(name)
|
factions.new_faction = function(name)
|
||||||
local faction = {
|
local faction = {
|
||||||
name = name,
|
name = name,
|
||||||
power = 0.,
|
power = 0.,
|
||||||
@ -85,22 +85,22 @@ factionsmod.new_faction = function(name)
|
|||||||
self:on_player_leave(player)
|
self:on_player_leave(player)
|
||||||
end,
|
end,
|
||||||
claim_chunk = function(self, chunkpos)
|
claim_chunk = function(self, chunkpos)
|
||||||
factionsmod.chunks[chunkpos] = self.name
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
self:on_claim_chunk(chunkpos)
|
self:on_claim_chunk(chunkpos)
|
||||||
end,
|
end,
|
||||||
unclaim_chunk = function(self, chunkpos)
|
unclaim_chunk = function(self, chunkpos)
|
||||||
factionsmod.chunks[chunkpos] = nil
|
factions.chunks[chunkpos] = nil
|
||||||
self.land[chunkpos] = nil
|
self.land[chunkpos] = nil
|
||||||
self:on_unclaim_chunks(chunkpos)
|
self:on_unclaim_chunks(chunkpos)
|
||||||
end,
|
end,
|
||||||
disband = function(self)
|
disband = function(self)
|
||||||
factionsmod.factions[self.name] = nil
|
factions.factions[self.name] = nil
|
||||||
for i in ipairs(self.players) do -- remove players affiliation
|
for i in ipairs(self.players) do -- remove players affiliation
|
||||||
factionsmod.players[self.players[i]] = nil
|
factions.players[self.players[i]] = nil
|
||||||
end
|
end
|
||||||
for k, v in self.land do -- remove chunk claims
|
for k, v in self.land do -- remove chunk claims
|
||||||
factionsmod.chunks[v] = nil
|
factions.chunks[v] = nil
|
||||||
end
|
end
|
||||||
self:on_disband()
|
self:on_disband()
|
||||||
end,
|
end,
|
||||||
@ -226,21 +226,21 @@ factionsmod.new_faction = function(name)
|
|||||||
--TODO: implement
|
--TODO: implement
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
factionsmod[name] = faction
|
factions[name] = faction
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
|
|
||||||
--??????????????
|
--??????????????
|
||||||
function factionsmod.fix_powercap(name)
|
function factions.fix_powercap(name)
|
||||||
factionsmod.data.factionsmod[name].powercap = #factionsmod.dynamic_data.membertable[name] + 10
|
factions.data.factionsmod[name].powercap = #factionsmod.dynamic_data.membertable[name] + 10
|
||||||
end
|
end
|
||||||
--??????????????
|
--??????????????
|
||||||
|
|
||||||
function factionsmod.get_chunk(pos)
|
function factions.get_chunk(pos)
|
||||||
return factionsmod.chunks[factionsmod.get_chunkpos(pos)]
|
return factions.chunks[factionsmod.get_chunkpos(pos)]
|
||||||
end
|
end
|
||||||
|
|
||||||
function factionsmod.get_chunkpos(pos)
|
function factions.get_chunkpos(pos)
|
||||||
return {math.floor(pos.x / 16.), math.floor(pos.z / 16.)}
|
return {math.floor(pos.x / 16.), math.floor(pos.z / 16.)}
|
||||||
|
|
||||||
|
|
||||||
@ -248,16 +248,16 @@ function factionsmod.get_chunkpos(pos)
|
|||||||
-- name: add_faction(name)
|
-- name: add_faction(name)
|
||||||
--
|
--
|
||||||
--! @brief add a faction
|
--! @brief add a faction
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @public
|
--! @public
|
||||||
--
|
--
|
||||||
--! @param name of faction to add
|
--! @param name of faction to add
|
||||||
--!
|
--!
|
||||||
--! @return faction object/false (succesfully added faction or not)
|
--! @return faction object/false (succesfully added faction or not)
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.add_faction(name)
|
function factions.add_faction(name)
|
||||||
if factionsmod.can_create_faction(name) then
|
if factions.can_create_faction(name) then
|
||||||
local fac = factionsmod.new_faction(name)
|
local fac = factions.new_faction(name)
|
||||||
fac:on_create()
|
fac:on_create()
|
||||||
return fac
|
return fac
|
||||||
else
|
else
|
||||||
@ -268,17 +268,17 @@ end
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: get_faction_list()
|
-- name: get_faction_list()
|
||||||
--
|
--
|
||||||
--! @brief get list of factionsmod
|
--! @brief get list of factions
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @public
|
--! @public
|
||||||
--!
|
--!
|
||||||
--! @return list of factionsmod
|
--! @return list of factions
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.get_faction_list()
|
function factions.get_faction_list()
|
||||||
|
|
||||||
local retval = {}
|
local retval = {}
|
||||||
|
|
||||||
for key,value in pairs(factionsmod.factions) do
|
for key,value in pairs(factions.factions) do
|
||||||
table.insert(retval,key)
|
table.insert(retval,key)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -289,23 +289,23 @@ end
|
|||||||
-- name: save()
|
-- name: save()
|
||||||
--
|
--
|
||||||
--! @brief save data to file
|
--! @brief save data to file
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @private
|
--! @private
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.save()
|
function factions.save()
|
||||||
|
|
||||||
--saving is done much more often than reading data to avoid delay
|
--saving is done much more often than reading data to avoid delay
|
||||||
--due to figuring out which data to save and which is temporary only
|
--due to figuring out which data to save and which is temporary only
|
||||||
--all data is saved here
|
--all data is saved here
|
||||||
--this implies data needs to be cleant up on load
|
--this implies data needs to be cleant up on load
|
||||||
|
|
||||||
local file,error = io.open(factionsmod_worldid .. "/" .. "factionsmod.conf","w")
|
local file,error = io.open(factions_worldid .. "/" .. "factionsmod.conf","w")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write(minetest.serialize(factionsmod.factions))
|
file:write(minetest.serialize(factions.factions))
|
||||||
file:close()
|
file:close()
|
||||||
else
|
else
|
||||||
minetest.log("error","MOD factionsmod: unable to save factionsmod world specific data!: " .. error)
|
minetest.log("error","MOD factions: unable to save factionsmod world specific data!: " .. error)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -314,23 +314,23 @@ end
|
|||||||
-- name: load()
|
-- name: load()
|
||||||
--
|
--
|
||||||
--! @brief load data from file
|
--! @brief load data from file
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @return true/false
|
--! @return true/false
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.load()
|
function factions.load()
|
||||||
local file,error = io.open(factionsmod_worldid .. "/" .. "factionsmod.conf","r")
|
local file,error = io.open(factions_worldid .. "/" .. "factionsmod.conf","r")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
factionsmod.factions = minetest.deserialize(raw_data)
|
factions.factions = minetest.deserialize(raw_data)
|
||||||
for facname, faction in pairs(factionsmod.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
for i in ipairs(faction.players) do
|
for i in ipairs(faction.players) do
|
||||||
factionsmod.players[faction.players[i]] = facname
|
factions.players[faction.players[i]] = facname
|
||||||
end
|
end
|
||||||
for chunkpos, val in pairs(faction.land) do
|
for chunkpos, val in pairs(faction.land) do
|
||||||
factionsmod.chunks[chunkpos] = val
|
factions.chunks[chunkpos] = val
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
20
init.lua
20
init.lua
@ -1,10 +1,10 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file init.lua
|
--! @file init.lua
|
||||||
--! @brief factionsmod mod to be used by other mods
|
--! @brief factions mod to be used by other mods
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
@ -12,18 +12,18 @@
|
|||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
local factionsmod_version = "0.1.6"
|
local factions_version = "0.1.6"
|
||||||
|
|
||||||
core.log("action", "MOD: factionsmod (by sapier) loading ...")
|
core.log("action", "MOD: factions (by sapier) loading ...")
|
||||||
|
|
||||||
--!path of mod
|
--!path of mod
|
||||||
factionsmod_modpath = minetest.get_modpath("factionsmod")
|
factions_modpath = minetest.get_modpath("factions")
|
||||||
|
|
||||||
|
|
||||||
dofile (factionsmod_modpath .. "/factionsmod.lua")
|
dofile (factions_modpath .. "/factionsmod.lua")
|
||||||
dofile (factionsmod_modpath .. "/chatcommands.lua")
|
dofile (factions_modpath .. "/chatcommands.lua")
|
||||||
|
|
||||||
factionsmod.load()
|
factions.load()
|
||||||
factionsmod_chat.init()
|
factions_chat.init()
|
||||||
|
|
||||||
core.log("action","MOD: factionsmod (by sapier) " .. factionsmod_version .. " loaded.")
|
core.log("action","MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
||||||
|
Loading…
Reference in New Issue
Block a user