mirror of
https://github.com/mt-mods/playerfactions.git
synced 2024-11-22 15:23:47 +01:00
Fixed create, disband, and chown commands
This commit is contained in:
parent
f9ce04c4c4
commit
9adfb56b3b
24
init.lua
24
init.lua
@ -25,11 +25,17 @@ function factions.get_player_faction(name)
|
|||||||
local faction = player:get_meta():get_string("faction")
|
local faction = player:get_meta():get_string("faction")
|
||||||
if faction == "" then
|
if faction == "" then
|
||||||
return nil
|
return nil
|
||||||
|
else
|
||||||
|
-- Check that faction still exists
|
||||||
|
if facts[faction] == nil then
|
||||||
|
factions.leave_faction(name)
|
||||||
|
return nil
|
||||||
else
|
else
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function factions.get_owner(name)
|
function factions.get_owner(name)
|
||||||
if facts[name] == nil then
|
if facts[name] == nil then
|
||||||
@ -39,6 +45,10 @@ function factions.get_owner(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.chown(name, owner)
|
||||||
|
facts[name].owner = owner
|
||||||
|
end
|
||||||
|
|
||||||
function factions.register_faction(fname, founder, pw)
|
function factions.register_faction(fname, founder, pw)
|
||||||
facts[fname] = {
|
facts[fname] = {
|
||||||
name = fname,
|
name = fname,
|
||||||
@ -46,6 +56,7 @@ function factions.register_faction(fname, founder, pw)
|
|||||||
password = pw
|
password = pw
|
||||||
}
|
}
|
||||||
save_factions()
|
save_factions()
|
||||||
|
factions.join_faction(fname, founder)
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.disband_faction(name)
|
function factions.disband_faction(name)
|
||||||
@ -71,7 +82,6 @@ end
|
|||||||
|
|
||||||
-- Chat commands
|
-- Chat commands
|
||||||
local function handle_command(name, param)
|
local function handle_command(name, param)
|
||||||
--local params = {string.match(param, "^([^ ]+)%s?(.*)")}
|
|
||||||
local params = {}
|
local params = {}
|
||||||
for p in string.gmatch(param, "[^%s]+") do
|
for p in string.gmatch(param, "[^%s]+") do
|
||||||
table.insert(params, p)
|
table.insert(params, p)
|
||||||
@ -95,7 +105,7 @@ local function handle_command(name, param)
|
|||||||
minetest.chat_send_player(name, S("Registered @1", faction_name))
|
minetest.chat_send_player(name, S("Registered @1", faction_name))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif action == "factions.disband" then
|
elseif action == "disband" then
|
||||||
local faction_name = factions.get_player_faction(name)
|
local faction_name = factions.get_player_faction(name)
|
||||||
local password = params[2]
|
local password = params[2]
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
@ -105,6 +115,7 @@ local function handle_command(name, param)
|
|||||||
elseif password == nil then
|
elseif password == nil then
|
||||||
minetest.chat_send_player(name, S("WARNING! This cannot be reversed! Run again with the password if you're absolutely certain"))
|
minetest.chat_send_player(name, S("WARNING! This cannot be reversed! Run again with the password if you're absolutely certain"))
|
||||||
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"))
|
minetest.chat_send_player(name, S("Permission denied"))
|
||||||
else
|
else
|
||||||
factions.disband_faction(faction_name, name, name)
|
factions.disband_faction(faction_name, name, name)
|
||||||
@ -196,8 +207,10 @@ local function handle_command(name, param)
|
|||||||
local password = params[3]
|
local password = params[3]
|
||||||
if faction_name == nil then
|
if faction_name == nil then
|
||||||
minetest.chat_send_player(name, S("You are not in a faction"))
|
minetest.chat_send_player(name, S("You are not in a faction"))
|
||||||
elseif factions.get_player_faction(name) ~= faction_name then
|
elseif target == nil then
|
||||||
minetest.chat_send_player(name, S("@1 isn't in your faction", name))
|
minetest.chat_send_player(name, S("Missing player name"))
|
||||||
|
elseif factions.get_player_faction(target) ~= faction_name then
|
||||||
|
minetest.chat_send_player(name, S("@1 isn't in your faction", target))
|
||||||
elseif factions.get_owner(faction_name) ~= name then
|
elseif factions.get_owner(faction_name) ~= name then
|
||||||
minetest.chat_send_player(name, S("Permission denied"))
|
minetest.chat_send_player(name, S("Permission denied"))
|
||||||
elseif password == nil then
|
elseif password == nil then
|
||||||
@ -205,7 +218,8 @@ local function handle_command(name, param)
|
|||||||
elseif password ~= factions.get_password(faction_name) then
|
elseif password ~= factions.get_password(faction_name) then
|
||||||
minetest.chat_send_player(name, S("Permission denied"))
|
minetest.chat_send_player(name, S("Permission denied"))
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, S("Ownership has been transferred to @1", name))
|
factions.chown(faction_name, target)
|
||||||
|
minetest.chat_send_player(name, S("Ownership has been transferred to @1", target))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user