Version MFF.

This commit is contained in:
sys4-fr 2018-09-07 20:55:56 +02:00
parent 220d0c4f26
commit e5fdd2bdee
5 changed files with 128 additions and 137 deletions

135
chatcommands.lua Normal file → Executable file
View File

@ -31,23 +31,23 @@ function factions_chat.init()
give_to_singleplayer = true, give_to_singleplayer = true,
} }
) )
minetest.register_privilege("faction_admin", minetest.register_privilege("faction_admin",
{ {
description = "this user is allowed to create or delete factions", description = "this user is allowed to create or delete factions",
give_to_singleplayer = true, give_to_singleplayer = true,
} }
) )
minetest.register_chatcommand("factions", 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 = { faction_user=true },
func = factions_chat.cmdhandler, func = factions_chat.cmdhandler,
} }
) )
minetest.register_chatcommand("af", minetest.register_chatcommand("af",
{ {
params = "text", params = "text",
@ -56,7 +56,7 @@ function factions_chat.init()
func = factions_chat.allfactions_chathandler, func = factions_chat.allfactions_chathandler,
} }
) )
minetest.register_chatcommand("f", minetest.register_chatcommand("f",
{ {
params = "<factionname> text", params = "<factionname> text",
@ -79,16 +79,16 @@ end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions_chat.cmdhandler(playername,parameter) function factions_chat.cmdhandler(playername,parameter)
local player = minetest.env:get_player_by_name(playername) local player = minetest.get_player_by_name(playername)
local params = parameter:split(" ") local params = parameter:split(" ")
local cmd = params[1] local cmd = params[1]
--handle common commands --handle common commands
if parameter == nil or if parameter == nil or
parameter == "" then parameter == "" then
local playerfactions = factions.get_factions(player) local playerfactions = factions.get_factions(player)
local tosend = "Factions: " .. playername .. " factions:" local tosend = "Factions: " .. playername .. " factions:"
for i,v in ipairs(playerfactions) do for i,v in ipairs(playerfactions) do
if i ~= #playerfactions then if i ~= #playerfactions then
@ -96,40 +96,33 @@ function factions_chat.cmdhandler(playername,parameter)
else else
tosend = tosend .. " " .. v tosend = tosend .. " " .. v
end end
end end
minetest.chat_send_player(playername, tosend, false) minetest.chat_send_player(playername, tosend, false)
return return
end end
if cmd == "claim" then
minetest.chat_send_player(playername,"Trust me, we're working on it",false)
return
end
if cmd == "unclaim" then
return
end
--list all known factions --list all known factions
if cmd == "list" then if cmd == "list" then
local list = factions.get_faction_list() local list = factions.get_faction_list()
local tosend = "Factions: current available factions:" local tosend = "Factions: current available factions:"
for i,v in ipairs(list) do for i,v in ipairs(list) do
if i ~= #list then if i ~= #list then
tosend = tosend .. " " .. v .. "," tosend = tosend .. " " .. v .. ","
else else
tosend = tosend .. " " .. v tosend = tosend .. " " .. v
end end
end end
minetest.chat_send_player(playername, tosend, false) minetest.chat_send_player(playername, tosend, false)
return return
end end
--show factions mod version --show factions mod version
if cmd == "version" then if cmd == "version" then
minetest.chat_send_player(playername, "Factions: version " .. factions_version , false) minetest.chat_send_player(playername, "Factions: version " .. factions_version , false)
return return
end end
--show description of faction --show description of faction
if cmd == "info" then if cmd == "info" then
if params[2] ~= nil then if params[2] ~= nil then
@ -139,31 +132,31 @@ function factions_chat.cmdhandler(playername,parameter)
return return
end end
end end
if cmd == "leave" then if cmd == "leave" then
if params[2] ~= nil then if params[2] ~= nil then
if params[3] ~= nil then if params[3] ~= nil then
local toremove = minetest.env:get_player_by_name(params[3]) local toremove = minetest.get_player_by_name(params[3])
--allowed if faction_admin, admin of faction or player itself --allowed if faction_admin, admin of faction or player itself
if minetest.check_player_privs(playername,{ faction_admin=true }) or if minetest.check_player_privs(playername,{ faction_admin=true }) or
factions.is_admin(params[2],playername) and factions.is_admin(params[2],playername) and
toremove ~= nil then toremove ~= nil then
factions.member_remove(params[2],toremove) factions.member_remove(params[2],toremove)
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: " .. params[3] .. " has been removed from " "Factions: " .. params[3] .. " has been removed from "
.. params[2], false) .. params[2], false)
return return
end end
else else
factions.member_remove(params[2],player) factions.member_remove(params[2],player)
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: You have left " .. params[2], false) "Factions: You have left " .. params[2], false)
return return
end end
end end
end end
--handle superadmin only commands --handle superadmin only commands
if minetest.check_player_privs(playername,{ faction_admin=true }) then if minetest.check_player_privs(playername,{ faction_admin=true }) then
--create new faction --create new faction
@ -183,14 +176,14 @@ function factions_chat.cmdhandler(playername,parameter)
end end
end end
end end
if cmd == "join" then if cmd == "join" then
if params[2] ~= nil then if params[2] ~= nil then
if params[3] ~= nil and if params[3] ~= nil and
minetest.check_player_privs(playername,{ faction_admin=true }) then minetest.check_player_privs(playername,{ faction_admin=true }) then
local toadd = minetest.env:get_player_by_name(params[3]) local toadd = minetest.get_player_by_name(params[3])
if toadd ~= nil then if toadd ~= nil then
if factions.member_add(params[2],toadd) then if factions.member_add(params[2],toadd) then
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
@ -226,16 +219,16 @@ function factions_chat.cmdhandler(playername,parameter)
"Factions: you are not allowed to join " .. params[2], "Factions: you are not allowed to join " .. params[2],
false) false)
return return
end end
end end
end end
end end
--all following commands require at least two parameters --all following commands require at least two parameters
if params[2] ~= nil then if params[2] ~= nil then
if minetest.check_player_privs(playername,{ faction_admin=true }) or if minetest.check_player_privs(playername,{ faction_admin=true }) or
factions.is_admin(params[2],playername) then factions.is_admin(params[2],playername) then
--delete faction --delete faction
if cmd == "delete" then if cmd == "delete" then
if factions.delete_faction(params[2]) then if factions.delete_faction(params[2]) then
@ -250,19 +243,19 @@ function factions_chat.cmdhandler(playername,parameter)
return return
end end
end end
if cmd == "set_free" then if cmd == "set_free" then
if params[3] ~= nil and if params[3] ~= nil and
(params[3] == "true" or params[3] == "false")then (params[3] == "true" or params[3] == "false")then
local value = false local value = false
if params[3] == "true" then if params[3] == "true" then
value = true value = true
end end
if factions.set_free(params[2],value) then if factions.set_free(params[2],value) then
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: free to join for " .. params[2] .. "Factions: free to join for " .. params[2] ..
" has been set to " .. params[3], " has been set to " .. params[3],
false) false)
else else
@ -273,20 +266,20 @@ function factions_chat.cmdhandler(playername,parameter)
end end
end end
end end
--set player admin status --set player admin status
if cmd == "admin" then if cmd == "admin" then
if params[3] ~= nil and params[4] ~= nil and if params[3] ~= nil and params[4] ~= nil and
(params[4] == "true" or params[4] == "false") then (params[4] == "true" or params[4] == "false") then
local value = false local value = false
if params[4] == "true" then if params[4] == "true" then
value = true value = true
end end
if factions.set_admin(params[2],params[3],value) then if factions.set_admin(params[2],params[3],value) then
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: adminstate of " .. params[3] .. "Factions: adminstate of " .. params[3] ..
" has been set to " .. params[4], " has been set to " .. params[4],
false) false)
else else
@ -298,40 +291,40 @@ function factions_chat.cmdhandler(playername,parameter)
end end
return return
end end
if cmd == "description" and if cmd == "description" and
params[2] ~= nil and params[2] ~= nil and
params[3] ~= nil then params[3] ~= nil then
local desc = params[3] local desc = params[3]
for i=4, #params, 1 do for i=4, #params, 1 do
desc = desc .. " " .. params[i] desc = desc .. " " .. params[i]
end end
if factions.set_description(params[2],desc) then if factions.set_description(params[2],desc) then
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: updated description of faction " .. "Factions: updated description of faction " ..
params[2], params[2],
false) false)
return return
else else
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: FAILED to update description of faction " .. "Factions: FAILED to update description of faction " ..
params[2], params[2],
false) false)
return return
end end
end end
if cmd == "invite" and if cmd == "invite" and
params[2] ~= nil and params[2] ~= nil and
params[3] ~= nil then params[3] ~= nil then
if factions.member_invite(params[2],params[3]) then if factions.member_invite(params[2],params[3]) then
minetest.chat_send_player(params[3], minetest.chat_send_player(params[3],
"Factions: " .. params[3] .. "Factions: " .. params[3] ..
" you have been invited to join faction " .. params[2], " you have been invited to join faction " .. params[2],
false) false)
minetest.chat_send_player(playername, minetest.chat_send_player(playername,
"Factions: " .. params[3] .. "Factions: " .. params[3] ..
" has been invited to join faction " .. params[2], " has been invited to join faction " .. params[2],
false) false)
return return
@ -360,22 +353,22 @@ end
--! @param parameter data supplied to command --! @param parameter data supplied to command
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions_chat.allfactions_chathandler(playername,parameter) function factions_chat.allfactions_chathandler(playername,parameter)
local player = minetest.env:get_player_by_name(playername) local player = minetest.get_player_by_name(playername)
if player ~= nil then if player ~= nil then
local recipients = {} local recipients = {}
for faction,value in pairs(factions.get_factions(player)) do for faction,value in pairs(factions.get_factions(player)) do
for name,value in pairs(factions.dynamic_data.membertable[faction]) do for name,value in pairs(factions.dynamic_data.membertable[faction]) do
local object_to_check = mientest.env:get_player_by_name(name) local object_to_check = minetest.get_player_by_name(name)
if object_to_check ~= nil then if object_to_check ~= nil then
recipients[name] = true recipients[name] = true
end end
end end
end end
for recipient,value in pairs(recipients) do for recipient,value in pairs(recipients) do
if recipient ~= playername then if recipient ~= playername then
minetest.chat_send_player(recipient,playername ..": " .. parameter,false) minetest.chat_send_player(recipient,playername ..": " .. parameter,false)
@ -397,30 +390,30 @@ end
--! @param parameter data supplied to command --! @param parameter data supplied to command
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions_chat.chathandler(playername,parameter) function factions_chat.chathandler(playername,parameter)
local player = minetest.env:get_player_by_name(playername) local player = minetest.get_player_by_name(playername)
if player ~= nil then if player ~= nil then
local line = parameter:split(" ") local line = parameter:split(" ")
local target_faction = line[1] local target_faction = line[1]
local text = line[2] local text = line[2]
for i=3,#line,1 do for i=3,#line,1 do
text = text .. " " .. line[i] text = text .. " " .. line[i]
end end
local valid_faction = false local valid_faction = false
for faction,value in pairs(factions.get_factions(player)) do for faction,value in pairs(factions.get_factions(player)) do
if target_faction == faction then if target_faction == faction then
valid_faction = true valid_faction = true
end end
end end
if faction ~= nil and valid_faction and if faction ~= nil and valid_faction and
factions.dynamic_data.membertable[faction] ~= nil then factions.dynamic_data.membertable[faction] ~= nil then
for name,value in pairs(factions.dynamic_data.membertable[faction]) do for name,value in pairs(factions.dynamic_data.membertable[faction]) do
local object_to_check = mientest.env:get_player_by_name(name) local object_to_check = minetest.get_player_by_name(name)
factions_chat.show_help(playername) factions_chat.show_help(playername)
if object_to_check ~= nil and if object_to_check ~= nil and
name ~= playername then name ~= playername then
@ -450,7 +443,7 @@ 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("Factions mod") MSG("Factions mod")
MSG("Usage:") MSG("Usage:")
MSG("\tUser commands:") MSG("\tUser commands:")
@ -460,7 +453,7 @@ function factions_chat.show_help(playername)
MSG("\t\t/factions leave <factionname> -> leave specified faction") MSG("\t\t/factions leave <factionname> -> leave specified faction")
MSG("\t\t/factions join <factionname> -> join specified faction") MSG("\t\t/factions join <factionname> -> join specified faction")
MSG("\t\t/factions version -> show version number of mod") MSG("\t\t/factions version -> show version number of mod")
MSG("\tAdmin commands:") MSG("\tAdmin commands:")
MSG("\t\t/factions create <factionname> -> create a new faction") MSG("\t\t/factions create <factionname> -> create a new faction")
MSG("\t\t/factions delete <factionname> -> delete a faction faction") MSG("\t\t/factions delete <factionname> -> delete a faction faction")
@ -469,4 +462,4 @@ function factions_chat.show_help(playername)
MSG("\t\t/factions set_free <factionname> <value> -> set faction free to join") MSG("\t\t/factions set_free <factionname> <value> -> set faction free to join")
MSG("\t\t/factions admin <factionname> <playername> <value> -> make player admin of faction") MSG("\t\t/factions admin <factionname> <playername> <value> -> make player admin of faction")
MSG("\t\t/factions description <factionname> <text> -> set description for faction") MSG("\t\t/factions description <factionname> <text> -> set description for faction")
end end

0
description.txt Normal file → Executable file
View File

0
doc/Doxyfile Normal file → Executable file
View File

130
factions.lua Normal file → Executable file
View File

@ -53,11 +53,11 @@ function factions.add_faction(name)
factions.data.factions[name].base_reputation = {} factions.data.factions[name].base_reputation = {}
factions.data.factions[name].adminlist = {} factions.data.factions[name].adminlist = {}
factions.data.factions[name].invitations = {} factions.data.factions[name].invitations = {}
factions.dynamic_data.membertable[name] = {} factions.dynamic_data.membertable[name] = {}
factions.save() factions.save()
return true return true
end end
@ -81,7 +81,7 @@ function factions.set_base_reputation(faction1,faction2,value)
if factions.data.factions[faction1] ~= nil and if factions.data.factions[faction1] ~= nil and
factions.data.factions[faction2] ~= nil then factions.data.factions[faction2] ~= nil then
factions.data.factions[faction1].base_reputation[faction2] = value factions.data.factions[faction1].base_reputation[faction2] = value
factions.data.factions[faction2].base_reputation[faction1] = value factions.data.factions[faction2].base_reputation[faction1] = value
factions.save() factions.save()
@ -166,13 +166,13 @@ end
--! @return true/false --! @return true/false
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.exists(name) function factions.exists(name)
for key,value in pairs(factions.data.factions) do for key,value in pairs(factions.data.factions) do
if key == name then if key == name then
return true return true
end end
end end
return false return false
end end
@ -188,11 +188,11 @@ end
function factions.get_faction_list() function factions.get_faction_list()
local retval = {} local retval = {}
for key,value in pairs(factions.data.factions) do for key,value in pairs(factions.data.factions) do
table.insert(retval,key) table.insert(retval,key)
end end
return retval return retval
end end
@ -210,9 +210,9 @@ end
function factions.delete_faction(name) function factions.delete_faction(name)
factions.data.factions[name] = nil factions.data.factions[name] = nil
factions.save() factions.save()
if factions.data.factions[name] == nil then if factions.data.factions[name] == nil then
return true return true
end end
@ -232,32 +232,28 @@ end
--! --!
--! @return true/false (succesfully added faction or not) --! @return true/false (succesfully added faction or not)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.claim()
end
function factions.unclaim()
end
function factions.member_add(name, object) function factions.member_add(name, object)
local new_entry = {} local new_entry = {}
new_entry.factions = {} new_entry.factions = {}
if object.object ~= nil then if object.object ~= nil then
object = object.object object = object.object
end end
if not factions.exists(name) then if not factions.exists(name) then
print("Unable to add to NON existant faction >" .. name .. "<") print("Unable to add to NON existant faction >" .. name .. "<")
return false return false
end end
new_entry.name,new_entry.temporary = factions.get_name(object) new_entry.name,new_entry.temporary = factions.get_name(object)
factions.dbg_lvl2("Adding name=" .. dump(new_entry.name) .. " to faction: " .. name ) factions.dbg_lvl2("Adding name=" .. dump(new_entry.name) .. " to faction: " .. name )
if new_entry.name ~= nil then if new_entry.name ~= nil then
if factions.data.objects[new_entry.name] == nil then if factions.data.objects[new_entry.name] == nil then
factions.data.objects[new_entry.name] = new_entry factions.data.objects[new_entry.name] = new_entry
end end
if factions.data.objects[new_entry.name].factions[name] == nil then if factions.data.objects[new_entry.name].factions[name] == nil then
factions.data.objects[new_entry.name].factions[name] = true factions.data.objects[new_entry.name].factions[name] = true
factions.dynamic_data.membertable[name][new_entry.name] = true factions.dynamic_data.membertable[name][new_entry.name] = true
@ -266,7 +262,7 @@ function factions.member_add(name, object)
return true return true
end end
end end
--return false if no valid object or already member --return false if no valid object or already member
return false return false
end end
@ -291,7 +287,7 @@ function factions.member_invite(name, playername)
factions.save() factions.save()
return true return true
end end
--return false if not a valid faction or player already invited --return false if not a valid faction or player already invited
return false return false
end end
@ -311,9 +307,9 @@ end
function factions.member_remove(name,object) function factions.member_remove(name,object)
local id,type = factions.get_name(object) local id,type = factions.get_name(object)
factions.dbg_lvl2("removing name=" .. dump(id) .. " to faction: " .. name ) factions.dbg_lvl2("removing name=" .. dump(id) .. " to faction: " .. name )
if id ~= nil and if id ~= nil and
factions.data.objects[id] ~= nil and factions.data.objects[id] ~= nil and
factions.data.objects[id].factions[name] ~= nil then factions.data.objects[id].factions[name] ~= nil then
@ -322,7 +318,7 @@ function factions.member_remove(name,object)
factions.save() factions.save()
return true return true
end end
if id ~= nil and if id ~= nil and
factions.data.factions[name].invitations[id] ~= nil then factions.data.factions[name].invitations[id] ~= nil then
factions.data.factions[name].invitations[id] = nil factions.data.factions[name].invitations[id] = nil
@ -347,7 +343,7 @@ end
--! @return true/false (succesfully changed privileges) --! @return true/false (succesfully changed privileges)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.set_admin(name,playername,value) function factions.set_admin(name,playername,value)
mobf_assert_backtrace(type(playername) == "string") --mobf_assert_backtrace(type(playername) == "string")
if factions.data.factions[name] ~= nil then if factions.data.factions[name] ~= nil then
if value then if value then
factions.data.factions[name].adminlist[playername] = true factions.data.factions[name].adminlist[playername] = true
@ -418,7 +414,7 @@ function factions.is_free(name)
factions.data.factions[name].open then factions.data.factions[name].open then
return true return true
end end
return false return false
end end
@ -440,7 +436,7 @@ function factions.is_admin(name,playername)
factions.data.factions[name].adminlist[playername] == true then factions.data.factions[name].adminlist[playername] == true then
return true return true
end end
return false return false
end end
@ -463,7 +459,7 @@ function factions.is_invited(name,playername)
factions.data.factions[name].open == true) then factions.data.factions[name].open == true) then
return true return true
end end
return false return false
end end
@ -481,7 +477,7 @@ end
function factions.get_factions(object) function factions.get_factions(object)
local id,type = factions.get_name(object) local id,type = factions.get_name(object)
local retval = {} local retval = {}
if id ~= nil and if id ~= nil and
factions.data.objects[id] ~= nil then factions.data.objects[id] ~= nil then
@ -489,7 +485,7 @@ function factions.get_factions(object)
table.insert(retval,key) table.insert(retval,key)
end end
end end
return retval return retval
end end
@ -508,7 +504,7 @@ end
function factions.is_member(name,object) function factions.is_member(name,object)
local retval = false local retval = false
local id,type = factions.get_name(object) local id,type = factions.get_name(object)
if id ~= nil and if id ~= nil and
@ -520,7 +516,7 @@ function factions.is_member(name,object)
end end
end end
end end
return retval return retval
end end
@ -540,14 +536,14 @@ end
function factions.get_reputation(name,object) function factions.get_reputation(name,object)
local id,type = factions.get_name(object) local id,type = factions.get_name(object)
factions.dbg_lvl3("get_reputation: " .. name .. "<-->" .. dump(id)) factions.dbg_lvl3("get_reputation: " .. name .. "<-->" .. dump(id))
if id ~= nil and if id ~= nil and
factions.data.factions[name] ~= nil then factions.data.factions[name] ~= nil then
factions.dbg_lvl3("get_reputation: object reputation: " .. dump(factions.data.factions[name].reputation[id])) factions.dbg_lvl3("get_reputation: object reputation: " .. dump(factions.data.factions[name].reputation[id]))
if factions.data.factions[name].reputation[id] == nil then if factions.data.factions[name].reputation[id] == nil then
factions.data.factions[name].reputation[id] factions.data.factions[name].reputation[id]
= factions.calc_base_reputation(name,object) = factions.calc_base_reputation(name,object)
@ -575,21 +571,21 @@ end
--! @return true/false --! @return true/false
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.modify_reputation(name,object,delta) function factions.modify_reputation(name,object,delta)
local id,type = factions.get_name(object) local id,type = factions.get_name(object)
if factions.data.factions[name] ~= nil then if factions.data.factions[name] ~= nil then
if factions.data.factions[name].reputation[id] == nil then if factions.data.factions[name].reputation[id] == nil then
factions.data.factions[name].reputation[id] factions.data.factions[name].reputation[id]
= factions.calc_base_reputation(name,object) = factions.calc_base_reputation(name,object)
end end
factions.data.factions[name].reputation[id] factions.data.factions[name].reputation[id]
= factions.data.factions[name].reputation[id] + delta = factions.data.factions[name].reputation[id] + delta
factions.save() factions.save()
return true return true
end end
return false return false
end end
@ -608,21 +604,21 @@ function factions.get_name(object)
if object == nil then if object == nil then
return nil,true return nil,true
end end
if object.object ~= nil then if object.object ~= nil then
object = object.object object = object.object
end end
if object:is_player() then if object:is_player() then
return object:get_player_name(),false return object:get_player_name(),false
else else
local luaentity = object:get_luaentity() local luaentity = object:get_luaentity()
if luaentity ~= nil then if luaentity ~= nil then
return tostring(luaentity),true return tostring(luaentity),true
end end
end end
return nil,true return nil,true
end end
@ -643,9 +639,9 @@ function factions.calc_base_reputation(name,object)
--calculate initial reputation based uppon all groups --calculate initial reputation based uppon all groups
local object_factions = factions.get_factions(object) local object_factions = factions.get_factions(object)
local rep_value = 0 local rep_value = 0
factions.dbg_lvl3("calc_base_reputation: " .. name .. " <--> " .. tostring(object)) factions.dbg_lvl3("calc_base_reputation: " .. name .. " <--> " .. tostring(object))
if object_factions ~= nil then if object_factions ~= nil then
factions.dbg_lvl3("calc_base_reputation: " .. tostring(object) .. " is in " .. #object_factions .. " factions") factions.dbg_lvl3("calc_base_reputation: " .. tostring(object) .. " is in " .. #object_factions .. " factions")
for k,v in pairs(object_factions) do for k,v in pairs(object_factions) do
@ -659,10 +655,10 @@ function factions.calc_base_reputation(name,object)
end end
end end
end end
rep_value = rep_value / #object_factions rep_value = rep_value / #object_factions
end end
return rep_value return rep_value
end end
@ -679,16 +675,16 @@ function factions.save()
--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(factions_worldid .. "/" .. "factions.conf","w") local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
if file ~= nil then if file ~= nil then
file:write(minetest.serialize(factions.data)) file:write(minetest.serialize(factions.data))
file:close() file:close()
else else
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error) minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
end end
end end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -702,23 +698,23 @@ end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.load() function factions.load()
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r") local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
if file ~= nil then if file ~= nil then
local raw_data = file:read("*a") local raw_data = file:read("*a")
file:close() file:close()
if raw_data ~= nil and if raw_data ~= nil and
raw_data ~= "" then raw_data ~= "" then
local raw_table = minetest.deserialize(raw_data) local raw_table = minetest.deserialize(raw_data)
--read object data --read object data
local temp_objects = {} local temp_objects = {}
if raw_table.objects ~= nil then if raw_table.objects ~= nil then
for key,value in pairs(raw_table.objects) do for key,value in pairs(raw_table.objects) do
if value.temporary == false then if value.temporary == false then
factions.data.objects[key] = value factions.data.objects[key] = value
else else
@ -726,7 +722,7 @@ function factions.load()
end end
end end
end end
if raw_table.factions ~= nil then if raw_table.factions ~= nil then
for key,value in pairs(raw_table.factions) do for key,value in pairs(raw_table.factions) do
factions.data.factions[key] = {} factions.data.factions[key] = {}
@ -734,30 +730,32 @@ function factions.load()
factions.data.factions[key].adminlist = value.adminlist factions.data.factions[key].adminlist = value.adminlist
factions.data.factions[key].open = value.open factions.data.factions[key].open = value.open
factions.data.factions[key].invitations = value.invitations factions.data.factions[key].invitations = value.invitations
factions.data.factions[key].reputation = {} factions.data.factions[key].reputation = {}
for repkey,repvalue in pairs(value.reputation) do for repkey,repvalue in pairs(value.reputation) do
if temp_objects[repkey] == nil then if temp_objects[repkey] == nil then
factions.data.factions[key].reputation[repkey] = repvalue factions.data.factions[key].reputation[repkey] = repvalue
end end
end end
factions.dynamic_data.membertable[key] = {} factions.dynamic_data.membertable[key] = {}
end end
end end
--populate dynamic faction member table --populate dynamic faction member table
for id,object in pairs(factions.data.objects) do for id,object in pairs(factions.data.objects) do
for name,value in pairs(factions.data.objects[id].factions) do for name,value in pairs(factions.data.objects[id].factions) do
if value then if value then
factions.dynamic_data.membertable[name][id] = true if factions.dynamic_data.membertable[name] then -- One of the indexes above is nil. Which one? No idea. //MFF(Mg|07/29/15)
factions.dynamic_data.membertable[name][id] = true
end
end end
end end
end end
end end
else else
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w") local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
if file ~= nil then if file ~= nil then
file:close() file:close()
else else
@ -776,4 +774,4 @@ function factions.load()
end end
end end
) )
end end

0
init.lua Normal file → Executable file
View File