mirror of
https://github.com/mt-mods/playerfactions.git
synced 2024-11-25 08:43:44 +01:00
Code Improvement
This commit is contained in:
parent
600c721299
commit
3e7190edc6
24
README.md
24
README.md
@ -4,9 +4,9 @@ A simple mod which allows player created factions. Not very useful on its own, i
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
We can choose a mode : single or multi factions.
|
We can choose a mode : single or multi factions.
|
||||||
By default the mod is single faction, if we want to change, all it takes is to add a line `mode_unique_faction = false` into the mod.conf file
|
By default players can only be in one faction at a time. If you want to allow players to join multiple factions at once, add `mode_unique_faction = false` to modpath/settings.txt
|
||||||
|
|
||||||
Below, parameters with [ ] are useful only with the multi-factions mode.
|
Parameters marked with square brackets ([]) are optional; most of these are only used if mode_unique_faction is false.
|
||||||
|
|
||||||
There is an admin privs to enable every functions for every faction : playerfactions_admin
|
There is an admin privs to enable every functions for every faction : playerfactions_admin
|
||||||
|
|
||||||
@ -15,18 +15,18 @@ These commands can be used by anyone:
|
|||||||
|
|
||||||
- `/factions create <faction> <password>`: Create a new faction
|
- `/factions create <faction> <password>`: Create a new faction
|
||||||
- `/factions list`: List available factions
|
- `/factions list`: List available factions
|
||||||
- `/factions info <faction>`: See information on a faction
|
- `/factions info <faction>`: See information on a faction. For faction with lot of member we can choose the length of the member's list that's going to be shown by `adding max_members_list = int` to modpath/settings.txt, default is 50.
|
||||||
- `/factions join <faction> <password>`: Join an existing faction
|
- `/factions join <faction> <password>`: Join an existing faction
|
||||||
- `/factions leave [faction]`: Leave your faction
|
- `/factions leave [faction]`: Leave your faction
|
||||||
|
|
||||||
These extra commands can only be used by faction owners and someone with the playerfactions_admin priv:
|
These commands can only be used by faction owners and players with the playerfactions_admin privilege:
|
||||||
|
|
||||||
- `/factions kick [faction] <player>`: Kick someone from your faction
|
- `/factions kick <player> [faction]`: Kick someone from your faction
|
||||||
- `/factions disband [faction]`: Disband your faction
|
- `/factions disband <password> [faction]`: Disband your faction
|
||||||
- `/factions passwd [faction] <password>`: Change your faction's password
|
- `/factions passwd <password> [faction]`: Change your faction's password
|
||||||
- `/factions chown [faction] <player>`: Transfer ownership of your faction
|
- `/factions chown <player> <password> [faction]`: Transfer ownership of your faction
|
||||||
|
|
||||||
This commands can only be used by someone with the playerfactions_admin priv:
|
This command can only be used by players with the playerfactions_admin privilege:
|
||||||
- `/factions invite <player> <faction>`: Add player to a faction
|
- `/factions invite <player> <faction>`: Add player to a faction
|
||||||
|
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ I strongly recommend reading through the `init.lua` file; the functions at the t
|
|||||||
- `factions.version` is a variable made to check the version of the playerfactions mod to assert compatibility:
|
- `factions.version` is a variable made to check the version of the playerfactions mod to assert compatibility:
|
||||||
* factions.version == nil for firsts version of playerfactions mod
|
* factions.version == nil for firsts version of playerfactions mod
|
||||||
* factions.version == 2 is the first time this variable is added, with adding multi-faction mode
|
* factions.version == 2 is the first time this variable is added, with adding multi-faction mode
|
||||||
- `player_is_in_faction(fname, player_name)`: `true` if the player is in the faction, `nil` in other cases (facion or player doesn't exists or player is not a member of the faction)
|
- `player_is_in_faction(fname, player_name)`: `true` if the player is in the faction, `nil` in other cases (faction or player doesn't exists or player is not a member of the faction)
|
||||||
- `get_facts()`: Get the table with all data. The structure is :
|
- `get_facts()`: Get a copied table with all data. The structure is :
|
||||||
```
|
```
|
||||||
{["name_of_faction1"]={
|
{["name_of_faction1"]={
|
||||||
["owner"]=name_of_the_owner,
|
["owner"]=name_of_the_owner,
|
||||||
@ -70,7 +70,7 @@ I strongly recommend reading through the `init.lua` file; the functions at the t
|
|||||||
- `get_password(faction)`: Gets a faction's password
|
- `get_password(faction)`: Gets a faction's password
|
||||||
- `set_password(faction, password)`: Sets a faction's password
|
- `set_password(faction, password)`: Sets a faction's password
|
||||||
- `join_faction(faction, player)`: Sets the given player as belonging to this faction
|
- `join_faction(faction, player)`: Sets the given player as belonging to this faction
|
||||||
- `leave_faction(faction, player)`: Remove the given player from the faction
|
- `leave_faction(faction, player)`: Remove the given player from the specified faction
|
||||||
|
|
||||||
Note that all of these functions have sanity checks : if faction or player does not exists, it return false. If operation succeed, it return true or the needed value.
|
Note that all of these functions have sanity checks : if faction or player does not exists, it return false. If operation succeed, it return true or the needed value.
|
||||||
|
|
||||||
|
180
init.lua
180
init.lua
@ -1,4 +1,4 @@
|
|||||||
minetest.register_privilege("playerfactions_admin", {description = "Authorize to use every /factions commands",give_to_singleplayer = false})
|
minetest.register_privilege("playerfactions_admin", {description = "Allow the use of all playerfactions commands",give_to_singleplayer = false})
|
||||||
-- Load support for intllib.
|
-- Load support for intllib.
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local S, NS = dofile(MP.."/intllib.lua")
|
local S, NS = dofile(MP.."/intllib.lua")
|
||||||
@ -20,16 +20,13 @@ for fname, fact in pairs(facts) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
settings = Settings(MP.."/settings.txt")
|
||||||
local modConf = io.open(minetest.get_modpath("playerfactions").."/mod.conf")
|
factions.mode_unique_faction = settings:get_bool("mode_unique_faction", true)
|
||||||
local content = modConf:read("*all")
|
factions.max_members_list = settings:get("max_members_list")
|
||||||
local found, _ , mod_u = content:find("mode_unique_faction%s-=%s-(%S+)")
|
if type(factions.max_members_list) == "string" then
|
||||||
if found == nil then
|
factions.max_members_list = tonumber(factions.max_members_list)
|
||||||
factions.mode_unique_faction = true
|
elseif type(factions.max_members_list) == "nil" then
|
||||||
elseif mod_u == "false" then
|
factions.max_members_list = 50
|
||||||
factions.mode_unique_faction = false
|
|
||||||
else
|
|
||||||
factions.mode_unique_faction = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -40,13 +37,13 @@ end
|
|||||||
|
|
||||||
-- Data manipulation
|
-- Data manipulation
|
||||||
function factions.get_facts()
|
function factions.get_facts()
|
||||||
return facts
|
return {table.unpack(facts)}
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.player_is_in_faction(fname, player_name)
|
function factions.player_is_in_faction(fname, player_name)
|
||||||
if not minetest.player_exists(player_name) or facts[fname] == nil then
|
if not minetest.player_exists(player_name) or facts[fname] == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return facts[fname].members[player_name]
|
return facts[fname].members[player_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -168,11 +165,14 @@ local function handle_command(name, param)
|
|||||||
minetest.chat_send_player(name, S("Unknown subcommand. Run '/help factions' for help"))
|
minetest.chat_send_player(name, S("Unknown subcommand. Run '/help factions' for help"))
|
||||||
end
|
end
|
||||||
local action = params[1]
|
local action = params[1]
|
||||||
if action == "create" then
|
if action == "ses" then
|
||||||
|
minetest.chat_send_player(name,type(factions.max_members_list))
|
||||||
|
minetest.chat_send_player(name,type(factions.mode_unique_faction))
|
||||||
|
elseif action == "create" then
|
||||||
local faction_name = params[2]
|
local faction_name = params[2]
|
||||||
local password = params[3]
|
local password = params[3]
|
||||||
if factions.mode_unique_faction and factions.get_player_faction(name) ~= nil then
|
if factions.mode_unique_faction and factions.get_player_faction(name) ~= nil then
|
||||||
minetest.chat_send_player(name, S("You are already in a faction you can't create one"))
|
minetest.chat_send_player(name, S("You are already in a faction"))
|
||||||
elseif faction_name == nil then
|
elseif faction_name == nil then
|
||||||
minetest.chat_send_player(name, S("Missing faction name"))
|
minetest.chat_send_player(name, S("Missing faction name"))
|
||||||
elseif password == nil then
|
elseif password == nil then
|
||||||
@ -190,31 +190,28 @@ local function handle_command(name, param)
|
|||||||
local own_factions = factions.get_owned_factions(name)
|
local own_factions = factions.get_owned_factions(name)
|
||||||
local number_factions = #own_factions
|
local number_factions = #own_factions
|
||||||
if number_factions == 0 then
|
if number_factions == 0 then
|
||||||
password = "No importance, player won't be able because player is the owner of no faction"
|
minetest.chat_send_player(name, S("You are the owner of no faction"))
|
||||||
|
return false
|
||||||
elseif #params == 1 then
|
elseif #params == 1 then
|
||||||
faction_name = "No importance, player won't be able because no password is given"
|
minetest.chat_send_player(name, S("Missing password"))
|
||||||
|
return false
|
||||||
elseif #params == 2 and number_factions == 1 then
|
elseif #params == 2 and number_factions == 1 then
|
||||||
password = params[2]
|
password = params[2]
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
elseif #params >= 3 then
|
elseif #params >= 3 then
|
||||||
faction_name = params[2]
|
faction_name = params[3]
|
||||||
password = params[3]
|
password = params[2]
|
||||||
end
|
end
|
||||||
if password == nil then
|
if password == nil then
|
||||||
minetest.chat_send_player(name, S("Password is needed"))
|
minetest.chat_send_player(name, S("Missing password"))
|
||||||
elseif faction_name == nil then
|
elseif faction_name == nil then
|
||||||
if number_factions == 0 then
|
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
||||||
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
|
||||||
end
|
|
||||||
elseif not facts[faction_name] then
|
elseif not facts[faction_name] then
|
||||||
minetest.chat_send_player(name, S("This faction doesn't exists"))
|
minetest.chat_send_player(name, S("This faction doesn't exists"))
|
||||||
elseif name ~= factions.get_owner(faction_name) and not minetest.get_player_privs(name).playerfactions_admin then
|
elseif name ~= factions.get_owner(faction_name) and not minetest.get_player_privs(name).playerfactions_admin then
|
||||||
minetest.chat_send_player(name, S("Permission denied : you are not the owner of this faction and don't have the privs playerfactions_admin."))
|
minetest.chat_send_player(name, S("“Permission denied: You are not the owner of this faction, and don't have the playerfactions_admin privilege."))
|
||||||
elseif password ~= factions.get_password(faction_name) then
|
elseif password ~= factions.get_password(faction_name) then
|
||||||
print("wrong password")
|
minetest.chat_send_player(name, S("Permission denied: Wrong password"))
|
||||||
minetest.chat_send_player(name, S("Permission denied: wrong password"))
|
|
||||||
else
|
else
|
||||||
factions.disband_faction(faction_name)
|
factions.disband_faction(faction_name)
|
||||||
minetest.chat_send_player(name, S("Disbanded @1", faction_name))
|
minetest.chat_send_player(name, S("Disbanded @1", faction_name))
|
||||||
@ -240,8 +237,8 @@ local function handle_command(name, param)
|
|||||||
minetest.chat_send_player(name, S("This faction is not registered"))
|
minetest.chat_send_player(name, S("This faction is not registered"))
|
||||||
else
|
else
|
||||||
local fmembers = ""
|
local fmembers = ""
|
||||||
if table.getn(facts[faction_name].members) > 50 then
|
if table.getn(facts[faction_name].members) > factions.max_members_list then
|
||||||
fmembers = "The faction has more than 50 members, the members list can't be shown"
|
fmembers = S("The faction has more than @1 members, the members list can't be shown",factions.max_members_list)
|
||||||
else
|
else
|
||||||
for play,_ in pairs(facts[faction_name].members) do
|
for play,_ in pairs(facts[faction_name].members) do
|
||||||
if fmembers == "" then
|
if fmembers == "" then
|
||||||
@ -264,13 +261,13 @@ local function handle_command(name, param)
|
|||||||
elseif facts[faction_name] == nil then
|
elseif facts[faction_name] == nil then
|
||||||
minetest.chat_send_player(name, S("The faction @1 doesn't exist", faction_name))
|
minetest.chat_send_player(name, S("The faction @1 doesn't exist", faction_name))
|
||||||
elseif factions.get_password(faction_name) ~= password then
|
elseif factions.get_password(faction_name) ~= password then
|
||||||
minetest.chat_send_player(name, S("Permission denied : wrong password."))
|
minetest.chat_send_player(name, S("Permission denied: Wrong password."))
|
||||||
else
|
else
|
||||||
if factions.join_faction(faction_name, name) then
|
if factions.join_faction(faction_name, name) then
|
||||||
minetest.chat_send_player(name, S("Joined @1", faction_name))
|
minetest.chat_send_player(name, S("Joined @1", faction_name))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error on joining, please try again"))
|
minetest.chat_send_player(name, S("Error on joining"))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -279,20 +276,20 @@ local function handle_command(name, param)
|
|||||||
local number_factions = table.getn(player_factions)
|
local number_factions = table.getn(player_factions)
|
||||||
local faction_name = nil
|
local faction_name = nil
|
||||||
if number_factions == 0 then
|
if number_factions == 0 then
|
||||||
faction_name = nil
|
minetest.chat_send_player(name, S("You are not in a faction"))
|
||||||
elseif #params == 1 and number_factions == 1 then
|
return false
|
||||||
faction_name = player_factions[1]
|
elseif #params == 1 then
|
||||||
|
if number_factions == 1 then
|
||||||
|
faction_name = player_factions[1]
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, S("You are in many factions, you have to choose one of them : @1", table.concat(player_factions, ", ")))
|
||||||
|
return false
|
||||||
|
end
|
||||||
elseif #params >= 1 and facts[params[2]] ~= nil then
|
elseif #params >= 1 and facts[params[2]] ~= nil then
|
||||||
faction_name = params[2]
|
faction_name = params[2]
|
||||||
end
|
end
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
if number_factions == 0 then
|
minetest.chat_send_player(name, "The given faction doesn't exists")
|
||||||
minetest.chat_send_player(name, S("You are not in a faction"))
|
|
||||||
elseif facts[params[2]] then
|
|
||||||
minetest.chat_send_player(name, S("You are in many factions (@1), you must precise which one you want to leave", table.concat(player_factions, ", ")))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "The given faction doesn't exists")
|
|
||||||
end
|
|
||||||
elseif factions.get_owner(faction_name) == name then
|
elseif factions.get_owner(faction_name) == name then
|
||||||
minetest.chat_send_player(name, S("You cannot leave your own faction, change owner or disband it."))
|
minetest.chat_send_player(name, S("You cannot leave your own faction, change owner or disband it."))
|
||||||
else
|
else
|
||||||
@ -300,7 +297,7 @@ local function handle_command(name, param)
|
|||||||
minetest.chat_send_player(name, S("Left @1", faction_name))
|
minetest.chat_send_player(name, S("Left @1", faction_name))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error on leaving the faction, please try again"))
|
minetest.chat_send_player(name, S("Error on leaving faction"))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -310,41 +307,31 @@ local function handle_command(name, param)
|
|||||||
local own_factions = factions.get_owned_factions(name)
|
local own_factions = factions.get_owned_factions(name)
|
||||||
local number_factions = table.getn(own_factions)
|
local number_factions = table.getn(own_factions)
|
||||||
if number_factions == 0 then
|
if number_factions == 0 then
|
||||||
target = "No importance, the permission is denied"
|
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
||||||
|
return false
|
||||||
elseif #params == 2 and number_factions == 1 then
|
elseif #params == 2 and number_factions == 1 then
|
||||||
target = params[2]
|
target = params[2]
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
elseif #params >= 3 then
|
elseif #params >= 3 then
|
||||||
faction_name = params[2]
|
faction_name = params[3]
|
||||||
target = params[3]
|
target = params[2]
|
||||||
elseif facts[params[2]] ~= nil then
|
|
||||||
faction_name = "No importance, no target is given"
|
|
||||||
end
|
end
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
if number_factions == 0 then
|
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
||||||
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
|
||||||
end
|
|
||||||
elseif target == nil then
|
elseif target == nil then
|
||||||
minetest.chat_send_player(name, S("Missing player name"))
|
minetest.chat_send_player(name, S("Missing player name"))
|
||||||
elseif factions.get_owner(faction_name) ~= name and not minetest.get_player_privs(name).playerfactions_admin then
|
elseif factions.get_owner(faction_name) ~= name and not minetest.get_player_privs(name).playerfactions_admin then
|
||||||
minetest.chat_send_player(name, S("Permission denied: you are not the owner of this faction"))
|
minetest.chat_send_player(name, S("Permission denied: You are not the owner of this faction, and don't have the playerfactions_admin privilege."))
|
||||||
elseif not facts[faction_name].members[target] then
|
elseif not facts[faction_name].members[target] then
|
||||||
minetest.chat_send_player(name, S("This player is not in the faction"))
|
minetest.chat_send_player(name, S("This player is not in the specified faction"))
|
||||||
elseif target == name then
|
elseif target == factions.get_owner(faction_name) then
|
||||||
minetest.chat_send_player(name, S("You cannot kick yourself"))
|
minetest.chat_send_player(name, S("You cannot kick the owner of a faction, use '/factions chown <player> [faction]' to change the ownership."))
|
||||||
else
|
else
|
||||||
if factions.leave_faction(faction_name, target) then
|
if factions.leave_faction(faction_name, target) then
|
||||||
minetest.chat_send_player(name, S("Kicked @1 from faction", target))
|
minetest.chat_send_player(name, S("Kicked @1 from faction", target))
|
||||||
if target == factions.get_owner(faction_name) then
|
|
||||||
if factions.chown(faction_name, name) then
|
|
||||||
minetest.chat_send_player(name, S("@1 was the owner of the faction, the ownership of the faction belongs to you",target))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error on kicking @1 from faction, please try again", target))
|
minetest.chat_send_player(name, S("Error kicking @1 from faction", target))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -354,34 +341,30 @@ local function handle_command(name, param)
|
|||||||
local own_factions = factions.get_owned_factions(name)
|
local own_factions = factions.get_owned_factions(name)
|
||||||
local number_factions = table.getn(own_factions)
|
local number_factions = table.getn(own_factions)
|
||||||
if #params == 1 then
|
if #params == 1 then
|
||||||
faction_name = "No importance, there is no password"
|
minetest.chat_send_player(name, S("Missing password"))
|
||||||
|
return false
|
||||||
elseif number_factions == 0 then
|
elseif number_factions == 0 then
|
||||||
password = "No importance, player is the owner of no faction"
|
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
||||||
|
return false
|
||||||
elseif #params == 2 and number_factions == 1 then
|
elseif #params == 2 and number_factions == 1 then
|
||||||
password = params[2]
|
password = params[2]
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
elseif #params >= 3 then
|
elseif #params >= 3 then
|
||||||
faction_name = params[2]
|
faction_name = params[3]
|
||||||
password = params[3]
|
password = params[2]
|
||||||
elseif facts[params[2]] ~= nil then
|
|
||||||
faction_name = "No importance, there is no password"
|
|
||||||
end
|
end
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
if number_factions == 0 then
|
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
||||||
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
|
||||||
end
|
|
||||||
elseif password == nil then
|
elseif password == nil then
|
||||||
minetest.chat_send_player(name, S("Missing password"))
|
minetest.chat_send_player(name, S("Missing password"))
|
||||||
elseif factions.get_owner(faction_name) ~= name and not minetest.get_player_privs(name).playerfactions_admin then
|
elseif factions.get_owner(faction_name) ~= name and not minetest.get_player_privs(name).playerfactions_admin then
|
||||||
minetest.chat_send_player(name, S("Permission denied: you are not the owner of this faction"))
|
minetest.chat_send_player(name, S("Permission denied: You are not the owner of this faction, and don't have the playerfactions_admin privilege."))
|
||||||
else
|
else
|
||||||
if factions.set_password(faction_name, password) then
|
if factions.set_password(faction_name, password) then
|
||||||
minetest.chat_send_player(name, S("Password has been updated"))
|
minetest.chat_send_player(name, S("Password has been updated."))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error, password didn't change, please try again"))
|
minetest.chat_send_player(name, S("Failed to change password."))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -392,44 +375,43 @@ local function handle_command(name, param)
|
|||||||
local target = nil
|
local target = nil
|
||||||
local password = nil
|
local password = nil
|
||||||
if #params < 3 then
|
if #params < 3 then
|
||||||
faction_name = "No importance, there is no target or no password"
|
|
||||||
if params[2] ~= nil and minetest.player_exists(params[2]) then
|
if params[2] ~= nil and minetest.player_exists(params[2]) then
|
||||||
target = "No importance, there is no password"
|
minetest.chat_send_player(name,"Missing password")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name,"Missing player name")
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
elseif number_factions == 0 then
|
elseif number_factions == 0 then
|
||||||
target = "No importance, player is owner of no faction"
|
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
||||||
password = "No importance, player is owner of no faction"
|
return false
|
||||||
elseif number_factions == 1 and #params == 3 then
|
elseif number_factions == 1 and #params == 3 then
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
target = params[2]
|
target = params[2]
|
||||||
password = params[3]
|
password = params[3]
|
||||||
elseif #params >= 4 then
|
elseif #params >= 4 then
|
||||||
faction_name = params[2]
|
faction_name = params[4]
|
||||||
target = params[3]
|
target = params[2]
|
||||||
password = params[4]
|
password = params[3]
|
||||||
end
|
end
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
if number_factions == 0 then
|
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
||||||
minetest.chat_send_player(name, S("You are the owner of no faction, you can't use this command"))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, S("You are the owner of many factions, you have to choose one of them : @1", table.concat(own_factions, ", ")))
|
|
||||||
end
|
|
||||||
elseif target == nil then
|
elseif target == nil then
|
||||||
minetest.chat_send_player(name, S("Missing player name"))
|
minetest.chat_send_player(name, S("Missing player name"))
|
||||||
elseif password == nil then
|
elseif password == nil then
|
||||||
minetest.chat_send_player(name, S("Missing password"))
|
minetest.chat_send_player(name, S("Missing password"))
|
||||||
elseif name ~= factions.get_owner(faction_name) and not minetest.get_player_privs(name).playerfactions_admin then
|
elseif name ~= factions.get_owner(faction_name) and not minetest.get_player_privs(name).playerfactions_admin then
|
||||||
minetest.chat_send_player(name, S("Permission denied: you're not the owner of this faction"))
|
minetest.chat_send_player(name, S("Permission denied: You are not the owner of this faction, and don't have the playerfactions_admin privilege."))
|
||||||
elseif not facts[faction_name].members[target] then
|
elseif not facts[faction_name].members[target] then
|
||||||
minetest.chat_send_player(name, S("@1 isn't in your faction", target))
|
minetest.chat_send_player(name, S("@1 isn't in your faction", target))
|
||||||
elseif password ~= factions.get_password(faction_name) then
|
elseif password ~= factions.get_password(faction_name) then
|
||||||
minetest.chat_send_player(name, S("Permission denied: wrong password"))
|
minetest.chat_send_player(name, S("Permission denied: Wrong password"))
|
||||||
else
|
else
|
||||||
if factions.chown(faction_name, target) then
|
if factions.chown(faction_name, target) then
|
||||||
minetest.chat_send_player(name, S("Ownership has been transferred to @1", target))
|
minetest.chat_send_player(name, S("Ownership has been transferred to @1", target))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error, the owner didn't change, please verify parameters and try again"))
|
minetest.chat_send_player(name, S("Failed to transfer ownership."))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -447,10 +429,10 @@ local function handle_command(name, param)
|
|||||||
minetest.chat_send_player(name, S("The player is already in the faction \"@1\"",factions.get_player_faction(target)))
|
minetest.chat_send_player(name, S("The player is already in the faction \"@1\"",factions.get_player_faction(target)))
|
||||||
else
|
else
|
||||||
if factions.join_faction(faction_name, target) then
|
if factions.join_faction(faction_name, target) then
|
||||||
minetest.chat_send_player(name, "The player is now a member of the faction")
|
minetest.chat_send_player(name, S("@1 is now a member of the faction @2", target, faction_name))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Error on adding @1 into @2, please verify parameters and try again", target, faction_name))
|
minetest.chat_send_player(name, S("Error on adding @1 into @2.", target, faction_name))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -466,11 +448,11 @@ minetest.register_chatcommand("factions", {
|
|||||||
.."list: "..S("List available factions").."\n"
|
.."list: "..S("List available factions").."\n"
|
||||||
.."info <faction>: "..S("See information on a faction").."\n"
|
.."info <faction>: "..S("See information on a faction").."\n"
|
||||||
.."join <faction> <password>: "..S("Join an existing faction").."\n"
|
.."join <faction> <password>: "..S("Join an existing faction").."\n"
|
||||||
.."leave: "..S("Leave your faction").."\n"
|
.."leave [faction]: "..S("Leave your faction").."\n"
|
||||||
.."kick [faction] <player>: "..S("Kick someone from your faction or from the given faction").."\n"
|
.."kick <player> [faction]: "..S("Kick someone from your faction or from the given faction").."\n"
|
||||||
.."disband [faction] <password>: "..S("Disband your faction or the given faction").."\n"
|
.."disband <password> [faction]: "..S("Disband your faction or the given faction").."\n"
|
||||||
.."passwd [faction] <password>: "..S("Change your faction's password or the password of the given faction").."\n"
|
.."passwd <password> [faction]: "..S("Change your faction's password or the password of the given faction").."\n"
|
||||||
.."chown [faction] <player>:"..S("Transfer ownership of your faction").."\n"
|
.."chown <player> [faction]:"..S("Transfer ownership of your faction").."\n"
|
||||||
.."invite <player> <faction>:"..S("Add player to a faction, you need factionsplayer_admin privs").."\n",
|
.."invite <player> <faction>:"..S("Add player to a faction, you need factionsplayer_admin privs").."\n",
|
||||||
|
|
||||||
description = "",
|
description = "",
|
||||||
|
1
mod.conf
1
mod.conf
@ -1,3 +1,2 @@
|
|||||||
name = playerfactions
|
name = playerfactions
|
||||||
optional_depends = intllib
|
optional_depends = intllib
|
||||||
mode_unique_faction = true
|
|
||||||
|
2
settings.txt
Normal file
2
settings.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mode_unique_faction = false
|
||||||
|
max_members_list = 50
|
Loading…
Reference in New Issue
Block a user