added a very simple clan system
This commit is contained in:
parent
b7833240e3
commit
81264c81f1
11
mods/clans/LICENSE.txt
Normal file
11
mods/clans/LICENSE.txt
Normal file
@ -0,0 +1,11 @@
|
||||
License for Code
|
||||
----------------
|
||||
|
||||
Copyright (C) 2016 cd2 (cdqwertz) <cdqwertz@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
73
mods/clans/init.lua
Normal file
73
mods/clans/init.lua
Normal file
@ -0,0 +1,73 @@
|
||||
clans = {}
|
||||
clans.all_clans = {}
|
||||
clans.clans_file = minetest.get_worldpath() .. "/clans"
|
||||
|
||||
function clans.create_clan(plname, clan_name)
|
||||
clans.all_clans[clan_name] = {plname}
|
||||
clans.save_clans()
|
||||
end
|
||||
|
||||
function clans.add_member(clan_name, plname)
|
||||
table.insert(clans.all_clans[clan_name], plname)
|
||||
clans.save_clans()
|
||||
end
|
||||
|
||||
function clans.load_clans()
|
||||
local input = io.open(clans.clans_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
if minetest.deserialize(str) then
|
||||
clans.all_clans = minetest.deserialize(str)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function clans.save_clans()
|
||||
if clans.all_clans then
|
||||
local output = io.open(clans.clans_file, "w")
|
||||
local str = minetest.serialize(clans.all_clans)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
clans.load_clans()
|
||||
|
||||
minetest.register_chatcommand("create_clan", {
|
||||
params = "<name>",
|
||||
description = "Creates a clan",
|
||||
privs = {},
|
||||
func = function(name, text)
|
||||
if clans.all_clans[text] then
|
||||
return true, "There already is a clan named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
clans.create_clan(name, text)
|
||||
return true, "Added a clan named " .. text
|
||||
end
|
||||
return true, "Error couldnt find player " .. name
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("join_clan", {
|
||||
params = "<name>",
|
||||
description = "Join a clan",
|
||||
privs = {},
|
||||
func = function(name, text)
|
||||
if not clans.all_clans[text] then
|
||||
return true, "There is no clan named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
clans.add_member(text, name)
|
||||
return true, "Joined clan " .. text
|
||||
end
|
||||
return true, "Error couldnt find player " .. name
|
||||
end,
|
||||
})
|
||||
|
||||
|
73
mods/clans/init.lua~
Normal file
73
mods/clans/init.lua~
Normal file
@ -0,0 +1,73 @@
|
||||
clans = {}
|
||||
clans.all_clans = {}
|
||||
clans.clans_file = minetest.get_worldpath() .. "/clans"
|
||||
|
||||
function clans.create_clan(plname, clan_name)
|
||||
clans.all_clans[clan_name] = {plname}
|
||||
clans.save_clans()
|
||||
end
|
||||
|
||||
function clans.add_member(clan_name, plname)
|
||||
table.insert(clans.all_clans[clan_name], plname)
|
||||
clans.save_clans()
|
||||
end
|
||||
|
||||
function clans.load_clans()
|
||||
local input = io.open(clans.clans_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
if minetest.deserialize(str) then
|
||||
clans.all_clans = minetest.deserialize(str)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function clans.save_clans()
|
||||
if clans.all_clans then
|
||||
local output = io.open(clans.clans_file, "w")
|
||||
local str = minetest.serialize(clans.all_clans)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
clans.load_clans()
|
||||
|
||||
minetest.register_chatcommand("create_clan", {
|
||||
params = "<name>",
|
||||
description = "Creates a clan",
|
||||
privs = {},
|
||||
func = function(name, text)
|
||||
if clans.all_clans[text] then
|
||||
return true, "There already is a clan named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
clans.create_clan(name, text)
|
||||
return true, "Added a clan named " .. text
|
||||
end
|
||||
return true, "Error couldnt find player " .. name
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("join_clan", {
|
||||
params = "<name>",
|
||||
description = "Join a clan",
|
||||
privs = {},
|
||||
func = function(name, text)
|
||||
if not clans.all_clans[text] then
|
||||
return true, "There is no clan named " .. text
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
clans.add_member(text, name)
|
||||
return true, "Joined clan " .. text
|
||||
end
|
||||
return true, "Error couldnt find player " .. name
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user