forked from mtcontrib/factions
		
	Upload from hard disk.
This upload contains many bug fixes.
This commit is contained in:
		
							
								
								
									
										195
									
								
								chatcommands.lua
									
									
									
									
									
								
							
							
						
						
									
										195
									
								
								chatcommands.lua
									
									
									
									
									
								
							| @@ -5,8 +5,8 @@ | |||||||
| -- | -- | ||||||
| --! @file chatcommnd.lua | --! @file chatcommnd.lua | ||||||
| --! @brief factions chat interface | --! @brief factions chat interface | ||||||
| --! @copyright Sapier, agrecascino, shamoanjac | --! @copyright Sapier, agrecascino, shamoanjac, Coder12a  | ||||||
| --! @author Sapier, agrecascino, shamoanjac | --! @author Sapier, agrecascino, shamoanjac, Coder12a  | ||||||
| --! @date 2016-08-12 | --! @date 2016-08-12 | ||||||
| -- | -- | ||||||
| -- Contact sapier a t gmx net | -- Contact sapier a t gmx net | ||||||
| @@ -20,7 +20,7 @@ factions_chat = {} | |||||||
|  |  | ||||||
| factions.commands = {} | factions.commands = {} | ||||||
|  |  | ||||||
| factions.register_command = function(cmd_name, cmd) | factions.register_command = function(cmd_name, cmd, ignore_param_count) | ||||||
|     factions.commands[cmd_name] = { -- default command |     factions.commands[cmd_name] = { -- default command | ||||||
|         name = cmd_name, |         name = cmd_name, | ||||||
|         faction_permissions = {}, |         faction_permissions = {}, | ||||||
| @@ -47,10 +47,24 @@ factions.register_command = function(cmd_name, cmd) | |||||||
|                 strings = {}, |                 strings = {}, | ||||||
|                 other = {} |                 other = {} | ||||||
|             } |             } | ||||||
|  | 			if not ignore_param_count then | ||||||
| 				if #argv < #(self.format) then | 				if #argv < #(self.format) then | ||||||
| 					send_error(player, "Not enough parameters.") | 					send_error(player, "Not enough parameters.") | ||||||
| 					return false | 					return false | ||||||
| 				end | 				end | ||||||
|  | 				else | ||||||
|  | 				if self.format[1] then | ||||||
|  | 					local fm = self.format[1] | ||||||
|  | 					for i in ipairs(argv) do | ||||||
|  | 						if #argv > #(self.format) then | ||||||
|  | 							table.insert(self.format, fm) | ||||||
|  | 						else | ||||||
|  | 							break | ||||||
|  | 						end | ||||||
|  | 					end | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 			 | ||||||
|             for i in ipairs(self.format) do |             for i in ipairs(self.format) do | ||||||
|                 local argtype = self.format[i] |                 local argtype = self.format[i] | ||||||
|                 local arg = argv[i] |                 local arg = argv[i] | ||||||
| @@ -78,9 +92,11 @@ factions.register_command = function(cmd_name, cmd) | |||||||
|                     return false |                     return false | ||||||
|                 end |                 end | ||||||
|             end |             end | ||||||
|             for i=#self.format, #argv, 1 do |             for i=2, #argv do | ||||||
|  | 				if argv[i] then | ||||||
| 					table.insert(args.other, argv[i]) | 					table.insert(args.other, argv[i]) | ||||||
| 				end | 				end | ||||||
|  |             end | ||||||
|  |  | ||||||
|             -- checks permissions |             -- checks permissions | ||||||
|             local player_faction = factions.get_player_faction(player) |             local player_faction = factions.get_player_faction(player) | ||||||
| @@ -123,6 +139,7 @@ init_commands = function() | |||||||
| 		} | 		} | ||||||
| 	) | 	) | ||||||
| 	 | 	 | ||||||
|  | 	 | ||||||
| 	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", | ||||||
| @@ -134,7 +151,7 @@ init_commands = function() | |||||||
| 		{ | 		{ | ||||||
| 			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,faction_user=true }, | ||||||
| 			func = factions_chat.cmdhandler, | 			func = factions_chat.cmdhandler, | ||||||
| 		} | 		} | ||||||
| 	) | 	) | ||||||
| @@ -144,7 +161,7 @@ init_commands = function() | |||||||
| 		{ | 		{ | ||||||
| 			params = "<command> parameters", | 			params = "<command> parameters", | ||||||
| 			description = "Factions commands. Type /f help for available commands.", | 			description = "Factions commands. Type /f help for available commands.", | ||||||
|             privs = { interact=true}, |             privs = { interact=true,faction_user=true}, | ||||||
| 			func = factions_chat.cmdhandler, | 			func = factions_chat.cmdhandler, | ||||||
| 		} | 		} | ||||||
| 	) | 	) | ||||||
| @@ -158,6 +175,7 @@ end | |||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local can_claim = faction:can_claim_parcel(parcelpos) |         local can_claim = faction:can_claim_parcel(parcelpos) | ||||||
|         if can_claim then |         if can_claim then | ||||||
| @@ -178,13 +196,18 @@ factions.register_command ("claim", { | |||||||
|             end |             end | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local parcel_faction = factions.get_parcel_faction(parcelpos) |         local parcel_faction = factions.get_parcel_faction(parcelpos) | ||||||
|  | 		if not parcel_faction then | ||||||
|  | 		    send_error(player, "This parcel does not exist.") | ||||||
|  |             return false | ||||||
|  | 		end | ||||||
|         if parcel_faction.name ~= faction.name then |         if parcel_faction.name ~= faction.name then | ||||||
|             send_error(player, "This parcel does not belong to you.") |             send_error(player, "This parcel does not belong to you.") | ||||||
|             return false |             return false | ||||||
| @@ -193,12 +216,13 @@ factions.register_command("unclaim", { | |||||||
|             return true |             return true | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| --list all known factions | --list all known factions | ||||||
| factions.register_command("list", { | factions.register_command("list", { | ||||||
|     description = "List all registered factions.", |     description = "List all registered factions.", | ||||||
|     infaction = false, |     infaction = false, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local list = factions.get_faction_list() |         local list = factions.get_faction_list() | ||||||
|         local tosend = "Existing factions:" |         local tosend = "Existing factions:" | ||||||
| @@ -213,7 +237,7 @@ factions.register_command("list", { | |||||||
|         minetest.chat_send_player(player, tosend, false) |         minetest.chat_send_player(player, tosend, false) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| --show factions mod version | --show factions mod version | ||||||
| factions.register_command("version", { | factions.register_command("version", { | ||||||
| @@ -221,32 +245,35 @@ factions.register_command("version", { | |||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         minetest.chat_send_player(player, "factions: version " .. factions_version , false) |         minetest.chat_send_player(player, "factions: version " .. factions_version , false) | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| --show description  of faction | --show description  of faction | ||||||
| factions.register_command("info", { | factions.register_command("info", { | ||||||
|     format = {"faction"}, |     format = {"faction"}, | ||||||
|     description = "Shows a faction's description.", |     description = "Shows a faction's description.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         minetest.chat_send_player(player, |         minetest.chat_send_player(player, | ||||||
|             "factions: " .. 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 | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("leave", { | factions.register_command("leave", { | ||||||
|     description = "Leave your faction.", |     description = "Leave your faction.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:remove_player(player) |         faction:remove_player(player) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("kick", { | factions.register_command("kick", { | ||||||
|     faction_permissions = {"playerslist"}, |     faction_permissions = {"playerslist"}, | ||||||
|     format = {"player"}, |     format = {"player"}, | ||||||
|     description = "Kick a player from your faction.", |     description = "Kick a player from your faction.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local victim = args.players[1] |         local victim = args.players[1] | ||||||
|         local victim_faction = factions.get_player_faction(victim:get_player_name()) |         local victim_faction = factions.get_player_faction(victim:get_player_name()) | ||||||
| @@ -261,13 +288,14 @@ factions.register_command("kick", { | |||||||
|             return false |             return false | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| --create new faction | --create new faction | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         if faction then |         if faction then | ||||||
|             send_error(player, "You are already in a faction.") |             send_error(player, "You are already in a faction.") | ||||||
| @@ -283,12 +311,13 @@ factions.register_command("create", { | |||||||
|             return false |             return false | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("join", { | factions.register_command("join", { | ||||||
|     format = {"faction"}, |     format = {"faction"}, | ||||||
|     description = "Join a faction.", |     description = "Join a faction.", | ||||||
|     infaction = false, |     infaction = false, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local new_faction = args.factions[1] |         local new_faction = args.factions[1] | ||||||
|         if new_faction:can_join(player) then |         if new_faction:can_join(player) then | ||||||
| @@ -302,63 +331,69 @@ factions.register_command("join", { | |||||||
|         end |         end | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("disband", { | factions.register_command("disband", { | ||||||
|     faction_permissions = {"disband"}, |     faction_permissions = {"disband"}, | ||||||
|     description = "Disband your faction.", |     description = "Disband your faction.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:disband() |         faction:disband() | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:toggle_join_free(false) |         faction:toggle_join_free(false) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:toggle_join_free(true) |         faction:toggle_join_free(true) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:set_description(table.concat(args.other," ")) |         faction:set_description(table.concat(args.other," ")) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:invite_player(args.players[1]:get_player_name()) |         faction:invite_player(args.players[1]:get_player_name()) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:revoke_invite(args.players[1]:get_player_name()) |         faction:revoke_invite(args.players[1]:get_player_name()) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("delete", { | factions.register_command("delete", { | ||||||
|     global_privileges = {"faction_admin"}, |     global_privileges = {"faction_admin"}, | ||||||
| @@ -369,20 +404,22 @@ factions.register_command("delete", { | |||||||
|         args.factions[1]:disband() |         args.factions[1]:disband() | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("ranks", { | factions.register_command("ranks", { | ||||||
|     description = "List ranks within your faction", |     description = "List ranks within your faction", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         for rank, permissions in pairs(faction.ranks) do |         for rank, permissions in pairs(faction.ranks) do | ||||||
|             minetest.chat_send_player(player, rank..": "..table.concat(permissions, " ")) |             minetest.chat_send_player(player, rank..": "..table.concat(permissions, " ")) | ||||||
|         end |         end | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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.", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         if not faction.players then |         if not faction.players then | ||||||
|             minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")") |             minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")") | ||||||
| @@ -394,31 +431,57 @@ factions.register_command("who", { | |||||||
|         end |         end | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|  | 		if args.strings[1] then | ||||||
| 			local rank = args.strings[1] | 			local rank = args.strings[1] | ||||||
|         if #rank > factions.rank then |  | ||||||
|             send_error(player, "Go away Todd") |  | ||||||
|             return false |  | ||||||
|         end |  | ||||||
| 			if faction.ranks[rank] then | 			if faction.ranks[rank] then | ||||||
| 				send_error(player, "Rank already exists") | 				send_error(player, "Rank already exists") | ||||||
| 				return false | 				return false | ||||||
| 			end | 			end | ||||||
|  | 			local success = false | ||||||
|  | 			local failindex = -1 | ||||||
|  | 			for _, f in pairs(args.strings) do | ||||||
|  | 				if f then | ||||||
|  | 					for q, r in pairs(factions.permissions) do | ||||||
|  | 						if f == r then | ||||||
|  | 							success = true | ||||||
|  | 							break | ||||||
|  | 						end | ||||||
|  | 					end | ||||||
|  | 					if not success and _ ~= 1 then | ||||||
|  | 						failindex = _ | ||||||
|  | 						break | ||||||
|  | 					end | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 			if not success then | ||||||
|  | 				if args.strings[failindex] then | ||||||
|  | 					send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.") | ||||||
|  | 					else | ||||||
|  | 					send_error(player, "No permission was given.") | ||||||
|  | 				end | ||||||
|  | 				return false | ||||||
|  | 			end | ||||||
| 			faction:add_rank(rank, args.other) | 			faction:add_rank(rank, args.other) | ||||||
| 			return true | 			return true | ||||||
| 		end | 		end | ||||||
| }) | 		send_error(player, "No rank was given.") | ||||||
|  | 		return false | ||||||
|  |     end | ||||||
|  | },true) | ||||||
|  |  | ||||||
| factions.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"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local rank = args.strings[1] |         local rank = args.strings[1] | ||||||
|         local newrank = args.strings[2] |         local newrank = args.strings[2] | ||||||
| @@ -429,39 +492,43 @@ factions.register_command("delrank", { | |||||||
|         faction:delete_rank(rank, newrank) |         faction:delete_rank(rank, newrank) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.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"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         faction:set_spawn(pos) |         faction:set_spawn(pos) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("where", { | factions.register_command("where", { | ||||||
|     description = "See whose parcel you stand on.", |     description = "See whose parcel you stand on.", | ||||||
|     infaction = false, |     infaction = false, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local parcel_faction = factions.get_parcel_faction(parcelpos) |         local parcel_faction = factions.get_parcel_faction(parcelpos) | ||||||
|         local place_name = (parcel_faction and parcel_faction.name) or "Wilderness" |         local place_name = (parcel_faction and parcel_faction.name) or "Wilderness" | ||||||
|         minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..place_name) |         minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..place_name) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("help", { | factions.register_command("help", { | ||||||
|     description = "Shows help for commands.", |     description = "Shows help for commands.", | ||||||
|     infaction = false, |     infaction = false, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         factions_chat.show_help(player) |         factions_chat.show_help(player) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("spawn", { | factions.register_command("spawn", { | ||||||
|     description = "Shows your faction's spawn", |     description = "Shows your faction's spawn", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local spawn = faction.spawn |         local spawn = faction.spawn | ||||||
|         if spawn then |         if spawn then | ||||||
| @@ -473,12 +540,13 @@ factions.register_command("spawn", { | |||||||
|             return false |             return false | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("promote", { | factions.register_command("promote", { | ||||||
|     description = "Promotes a player to a rank", |     description = "Promotes a player to a rank", | ||||||
|     format = {"player", "string"}, |     format = {"player", "string"}, | ||||||
|     faction_permissions = {"promote"}, |     faction_permissions = {"promote"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local rank = args.strings[1] |         local rank = args.strings[1] | ||||||
|         if faction.ranks[rank] then |         if faction.ranks[rank] then | ||||||
| @@ -489,16 +557,17 @@ factions.register_command("promote", { | |||||||
|             return false |             return false | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("power", { | factions.register_command("power", { | ||||||
|     description = "Display your faction's power", |     description = "Display your faction's power", | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower) |         minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  | --[[ | ||||||
| factions.register_command("setbanner", { | factions.register_command("setbanner", { | ||||||
|     description = "Sets the banner you're on as the faction's banner.", |     description = "Sets the banner you're on as the faction's banner.", | ||||||
|     faction_permissions = {"banner"}, |     faction_permissions = {"banner"}, | ||||||
| @@ -511,8 +580,9 @@ factions.register_command("setbanner", { | |||||||
|         end |         end | ||||||
|         faction:set_banner(banner) |         faction:set_banner(banner) | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  | --]] | ||||||
|  | --[[ | ||||||
| factions.register_command("convert", { | factions.register_command("convert", { | ||||||
|     description = "Load factions in the old format", |     description = "Load factions in the old format", | ||||||
|     infaction = false, |     infaction = false, | ||||||
| @@ -526,8 +596,8 @@ factions.register_command("convert", { | |||||||
|         end |         end | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  | --]] | ||||||
| factions.register_command("free", { | factions.register_command("free", { | ||||||
|     description = "Forcefully frees a parcel", |     description = "Forcefully frees a parcel", | ||||||
|     infaction = false, |     infaction = false, | ||||||
| @@ -542,15 +612,17 @@ factions.register_command("free", { | |||||||
|             return true |             return true | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("chat", { | factions.register_command("chat", { | ||||||
|     description = "Send a message to your faction's members", |     description = "Send a message to your faction's members", | ||||||
|  | 	format = {"string"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local msg = table.concat(args.other, " ") |         local msg = table.concat(args.strings, " ") | ||||||
|         faction:broadcast(msg, player) |         faction:broadcast(msg, player) | ||||||
|     end |     end | ||||||
| }) | },true) | ||||||
|  |  | ||||||
| factions.register_command("forceupdate", { | factions.register_command("forceupdate", { | ||||||
|     description = "Forces an update tick.", |     description = "Forces an update tick.", | ||||||
| @@ -558,12 +630,13 @@ factions.register_command("forceupdate", { | |||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         factions.faction_tick() |         factions.faction_tick() | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("which", { | factions.register_command("which", { | ||||||
|     description = "Gets a player's faction", |     description = "Gets a player's faction", | ||||||
|     infaction = false, |     infaction = false, | ||||||
|     format = {"string"}, |     format = {"string"}, | ||||||
|  | 	global_privileges = {"faction_user"}, | ||||||
|     on_success = function(player, faction, pos, parcelpos, args) |     on_success = function(player, faction, pos, parcelpos, args) | ||||||
|         local playername = args.strings[1] |         local playername = args.strings[1] | ||||||
|         local faction = factions.get_player_faction(playername) |         local faction = factions.get_player_faction(playername) | ||||||
| @@ -575,7 +648,7 @@ factions.register_command("which", { | |||||||
|             return true |             return true | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("setleader", { | factions.register_command("setleader", { | ||||||
|     description = "Set a player as a faction's leader", |     description = "Set a player as a faction's leader", | ||||||
| @@ -593,7 +666,7 @@ factions.register_command("setleader", { | |||||||
|         targetfaction:set_leader(playername) |         targetfaction:set_leader(playername) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("setadmin", { | factions.register_command("setadmin", { | ||||||
|     description = "Make a faction an admin faction", |     description = "Make a faction an admin faction", | ||||||
| @@ -604,7 +677,7 @@ factions.register_command("setadmin", { | |||||||
|         args.factions[1].is_admin = false |         args.factions[1].is_admin = false | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("resetpower", { | factions.register_command("resetpower", { | ||||||
|     description = "Reset a faction's power", |     description = "Reset a faction's power", | ||||||
| @@ -615,7 +688,7 @@ factions.register_command("resetpower", { | |||||||
|         args.factions[1].power = 0 |         args.factions[1].power = 0 | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
|  |  | ||||||
| factions.register_command("obliterate", { | factions.register_command("obliterate", { | ||||||
| @@ -628,7 +701,7 @@ factions.register_command("obliterate", { | |||||||
|         end |         end | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("getspawn", { | factions.register_command("getspawn", { | ||||||
|     description = "Get a faction's spawn", |     description = "Get a faction's spawn", | ||||||
| @@ -645,7 +718,7 @@ factions.register_command("getspawn", { | |||||||
|             return false |             return false | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("whoin", { | factions.register_command("whoin", { | ||||||
|     description = "Get all members of a faction.", |     description = "Get all members of a faction.", | ||||||
| @@ -660,7 +733,7 @@ factions.register_command("whoin", { | |||||||
|         minetest.chat_send_player(player, table.concat(msg, ", ")) |         minetest.chat_send_player(player, table.concat(msg, ", ")) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("stats", { | factions.register_command("stats", { | ||||||
|     description = "Get stats of a faction.", |     description = "Get stats of a faction.", | ||||||
| @@ -672,7 +745,7 @@ factions.register_command("stats", { | |||||||
|         minetest.chat_send_player(player, "Power: "..f.power.."/"..f.maxpower - f.usedpower.."/"..f.maxpower) |         minetest.chat_send_player(player, "Power: "..f.power.."/"..f.maxpower - f.usedpower.."/"..f.maxpower) | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| factions.register_command("seen", { | factions.register_command("seen", { | ||||||
|     description = "Check the last time a faction had a member logged in", |     description = "Check the last time a faction had a member logged in", | ||||||
| @@ -690,7 +763,7 @@ factions.register_command("seen", { | |||||||
|             hours % 24 .." hour(s), "..minutes % 60 .." minutes, "..time % 60 .." second(s) ago.") |             hours % 24 .." hour(s), "..minutes % 60 .." minutes, "..time % 60 .." second(s) ago.") | ||||||
|         return true |         return true | ||||||
|     end |     end | ||||||
| }) | },false) | ||||||
|  |  | ||||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||||||
| -- name: cmdhandler(playername,parameter) | -- name: cmdhandler(playername,parameter) | ||||||
| @@ -733,6 +806,15 @@ factions_chat.cmdhandler = function (playername,parameter) | |||||||
|  |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function table_Contains(t,v) | ||||||
|  | 	for k, a in pairs(t) do | ||||||
|  | 		if a == v then | ||||||
|  | 			return true | ||||||
|  | 		end		 | ||||||
|  | 	end | ||||||
|  | 	return false | ||||||
|  | end | ||||||
|  |  | ||||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||||||
| -- name: show_help(playername,parameter) | -- name: show_help(playername,parameter) | ||||||
| -- | -- | ||||||
| @@ -750,13 +832,18 @@ function factions_chat.show_help(playername) | |||||||
| 	 | 	 | ||||||
| 	MSG("factions mod") | 	MSG("factions mod") | ||||||
| 	MSG("Usage:") | 	MSG("Usage:") | ||||||
|  | 	local has, missing = minetest.check_player_privs(playername,  { | ||||||
|  |     faction_admin = true}) | ||||||
|  | 	 | ||||||
|     for k, v in pairs(factions.commands) do |     for k, v in pairs(factions.commands) do | ||||||
|         local args = {} |         local args = {} | ||||||
|  | 		if has or not table_Contains(v.global_privileges,"faction_admin") then | ||||||
| 			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/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description) | 			MSG("\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description) | ||||||
| 		end | 		end | ||||||
|  |     end | ||||||
| end | end | ||||||
|  |  | ||||||
| init_commands() | init_commands() | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								config.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								config.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | ------------------------------------------------------------------------------- | ||||||
|  | -- factions Mod by Sapier | ||||||
|  | -- | ||||||
|  | -- License WTFPL | ||||||
|  | -- | ||||||
|  | --! @file config.lua | ||||||
|  | --! @brief settings file | ||||||
|  | --! @copyright Coder12a | ||||||
|  | --! @author Coder12a | ||||||
|  | --! @date 2018-03-13 | ||||||
|  | -- | ||||||
|  | -- Contact sapier a t gmx net | ||||||
|  | ------------------------------------------------------------------------------- | ||||||
|  |  | ||||||
|  | config = {} | ||||||
|  | config.protection_max_depth = tonumber(minetest.setting_get("protection_max_depth")) or -512 | ||||||
|  | config.power_per_parcel = tonumber(minetest.setting_get("power_per_parcel")) or 0.5 | ||||||
|  | config.power_per_death = tonumber(minetest.setting_get("power_per_death")) or 0.25 | ||||||
|  | config.power_per_tick = tonumber(minetest.setting_get("power_per_tick")) or 0.125 | ||||||
|  | config.tick_time = tonumber(minetest.setting_get("tick_time")) or 60 | ||||||
|  | config.power_per_attack = tonumber(minetest.setting_get("power_per_attack")) or 10 | ||||||
|  | config.faction_name_max_length = tonumber(minetest.setting_get("faction_name_max_length")) or 50 | ||||||
|  | config.rank_name_max_length = tonumber(minetest.setting_get("rank_name_max_length")) or 25 | ||||||
|  | config.maximum_faction_inactivity = tonumber(minetest.setting_get("maximum_faction_inactivity")) or 604800 | ||||||
|  | config.power = tonumber(minetest.setting_get("power")) or 2 | ||||||
|  | config.maxpower = tonumber(minetest.setting_get("maxpower")) or 2 | ||||||
|  | config.power_per_banner = minetest.settings:get_bool("power_per_banner") or 10. | ||||||
|  | config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false | ||||||
							
								
								
									
										1
									
								
								depends.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								depends.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | default? | ||||||
| @@ -1,5 +1 @@ | |||||||
| Version 1.1.5 | Mod for handling in game factions and reputation. | ||||||
|  |  | ||||||
| Mod for handling in game factions and reputation |  | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										238
									
								
								factions.lua
									
									
									
									
									
								
							
							
						
						
									
										238
									
								
								factions.lua
									
									
									
									
									
								
							| @@ -5,8 +5,8 @@ | |||||||
| -- | -- | ||||||
| --! @file factions.lua | --! @file factions.lua | ||||||
| --! @brief factions core file | --! @brief factions core file | ||||||
| --! @copyright Sapier, agrecascino, shamoanjac | --! @copyright Sapier, agrecascino, shamoanjac, Coder12a | ||||||
| --! @author Sapier, agrecascino, shamoanjac | --! @author Sapier, agrecascino, shamoanjac, Coder12a | ||||||
| --! @date 2016-08-12 | --! @date 2016-08-12 | ||||||
| -- | -- | ||||||
| -- Contact sapier a t gmx net | -- Contact sapier a t gmx net | ||||||
| @@ -27,15 +27,15 @@ factions.players = {} | |||||||
|  |  | ||||||
| factions.factions = {} | factions.factions = {} | ||||||
| --- settings | --- settings | ||||||
| factions.protection_max_depth = -512 | factions.protection_max_depth = config.protection_max_depth | ||||||
| factions.power_per_parcel = .5 | factions.power_per_parcel = config.power_per_parcel | ||||||
| factions.power_per_death = .25 | factions.power_per_death = config.power_per_death | ||||||
| factions.power_per_tick = .125 | factions.power_per_tick = config.power_per_tick | ||||||
| factions.tick_time = 60. | factions.tick_time = config.tick_time | ||||||
| factions.power_per_attack = 10. | factions.power_per_attack = config.power_per_attack | ||||||
| factions.faction_name_max_length = 50 | factions.faction_name_max_length = config.faction_name_max_length | ||||||
| factions.rank_name_max_length = 25 | factions.rank_name_max_length = config.rank_name_max_length | ||||||
| factions.maximum_faction_inactivity = 604800 -- 1 week | factions.maximum_faction_inactivity = config.maximum_faction_inactivity | ||||||
|  |  | ||||||
| --------------------- | --------------------- | ||||||
| --! @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) | ||||||
| @@ -62,7 +62,6 @@ util = { | |||||||
|  |  | ||||||
| factions.Faction.__index = factions.Faction | factions.Faction.__index = factions.Faction | ||||||
|  |  | ||||||
|  |  | ||||||
| -- Faction permissions: | -- Faction permissions: | ||||||
| -- | -- | ||||||
| -- disband: disband the faction | -- disband: disband the faction | ||||||
| @@ -75,12 +74,14 @@ factions.Faction.__index = factions.Faction | |||||||
| -- banner: set the faction's banner | -- banner: set the faction's banner | ||||||
| -- promote: set a player's rank | -- promote: set a player's rank | ||||||
|  |  | ||||||
|  | factions.permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"} | ||||||
|  |  | ||||||
| function factions.Faction:new(faction)  | function factions.Faction:new(faction)  | ||||||
|     faction = { |     faction = { | ||||||
|         --! @brief power of a faction (needed for parcel claiming) |         --! @brief power of a faction (needed for parcel claiming) | ||||||
|         power = 0., |         power = config.power, | ||||||
|         --! @brief maximum power of a faction |         --! @brief maximum power of a faction | ||||||
|         maxpower = 0., |         maxpower = config.maxpower, | ||||||
|         --! @brief power currently in use |         --! @brief power currently in use | ||||||
|         usedpower = 0., |         usedpower = 0., | ||||||
|         --! @brief list of player names |         --! @brief list of player names | ||||||
| @@ -137,16 +138,43 @@ function factions.Faction.increase_power(self, power) | |||||||
|     if self.power > self.maxpower  - self.usedpower then |     if self.power > self.maxpower  - self.usedpower then | ||||||
|         self.power = self.maxpower - self.usedpower |         self.power = self.maxpower - self.usedpower | ||||||
|     end |     end | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.decrease_power(self, power) | function factions.Faction.decrease_power(self, power) | ||||||
|     self.power = self.power - power |     self.power = self.power - power | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.increase_maxpower(self, power) | function factions.Faction.increase_maxpower(self, power) | ||||||
|     self.maxpower = self.maxpower + power |     self.maxpower = self.maxpower + power | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -155,10 +183,28 @@ function factions.Faction.decrease_maxpower(self, power) | |||||||
|     if self.maxpower < 0. then -- should not happen |     if self.maxpower < 0. then -- should not happen | ||||||
|         self.maxpower = 0. |         self.maxpower = 0. | ||||||
|     end |     end | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.increase_usedpower(self, power) | function factions.Faction.increase_usedpower(self, power) | ||||||
|     self.usedpower = self.usedpower + power |     self.usedpower = self.usedpower + power | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.decrease_usedpower(self, power) | function factions.Faction.decrease_usedpower(self, power) | ||||||
| @@ -166,6 +212,15 @@ function factions.Faction.decrease_usedpower(self, power) | |||||||
|     if self.usedpower < 0. then |     if self.usedpower < 0. then | ||||||
|         self.usedpower = 0. |         self.usedpower = 0. | ||||||
|     end |     end | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		for player, _ in pairs(self.players) do | ||||||
|  | 			local realplayer = playerslist[i] | ||||||
|  | 			if realplayer:get_player_name() == player then | ||||||
|  | 				updateHudPower(realplayer,self) | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.count_land(self) | function factions.Faction.count_land(self) | ||||||
| @@ -181,13 +236,38 @@ function factions.Faction.add_player(self, player, rank) | |||||||
|     self.players[player] = rank or self.default_rank |     self.players[player] = rank or self.default_rank | ||||||
|     factions.players[player] = self.name |     factions.players[player] = self.name | ||||||
|     self.invited_players[player] = nil |     self.invited_players[player] = nil | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		local realplayer = playerslist[i] | ||||||
|  | 		if realplayer:get_player_name() == player then | ||||||
|  | 			createHudFactionName(realplayer,self.name) | ||||||
|  | 			createHudPower(realplayer,self) | ||||||
|  | 			break | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function factions.Faction.check_players_in_faction(self) | ||||||
|  | 	local players = #self.players | ||||||
|  | 	if players < 1 then | ||||||
|  | 		self:disband("Zero players on faction.") | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
| function factions.Faction.remove_player(self, player) | function factions.Faction.remove_player(self, player) | ||||||
|     self.players[player] = nil |     self.players[player] = nil | ||||||
|     factions.players[player] = nil |     factions.players[player] = nil | ||||||
|     self:on_player_leave(player) |     self:on_player_leave(player) | ||||||
|  | 	self:check_players_in_faction(self) | ||||||
|  | 	local playerslist = minetest.get_connected_players() | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		local realplayer = playerslist[i] | ||||||
|  | 		if realplayer:get_player_name() == player then | ||||||
|  | 			removeHud(realplayer,"1") | ||||||
|  | 			removeHud(realplayer,"2") | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -235,7 +315,8 @@ end | |||||||
|  |  | ||||||
| --! @brief disband faction, updates global players and parcels table | --! @brief disband faction, updates global players and parcels table | ||||||
| function factions.Faction.disband(self, reason) | function factions.Faction.disband(self, reason) | ||||||
|     for k, _ in pairs(self.players) do -- remove players affiliation | 	local playerslist = minetest.get_connected_players() | ||||||
|  |     for k, _ in pairs(factions.players) do -- remove players affiliation | ||||||
|         factions.players[k] = nil |         factions.players[k] = nil | ||||||
|     end |     end | ||||||
|     for k, v in pairs(self.land) do -- remove parcel claims |     for k, v in pairs(self.land) do -- remove parcel claims | ||||||
| @@ -243,6 +324,14 @@ function factions.Faction.disband(self, reason) | |||||||
|     end |     end | ||||||
|     self:on_disband(reason) |     self:on_disband(reason) | ||||||
|     factions.factions[self.name] = nil |     factions.factions[self.name] = nil | ||||||
|  | 	for i in pairs(playerslist) do | ||||||
|  | 		local realplayer = playerslist[i] | ||||||
|  | 		local faction = factions.get_player_faction(realplayer:get_player_name()) | ||||||
|  |         if not faction then | ||||||
|  | 			removeHud(realplayer,"1") | ||||||
|  | 			removeHud(realplayer,"2") | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|     factions.save() |     factions.save() | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -395,7 +484,8 @@ function factions.Faction.is_online(self) | |||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.attack_parcel(self, parcelpos) | function factions.Faction.attack_parcel(self, parcelpos) | ||||||
| --[[    local attacked_faction = factions.get_parcel_faction(parcelpos) | 	if config.attack_parcel then | ||||||
|  | 		local attacked_faction = factions.get_parcel_faction(parcelpos) | ||||||
| 		if attacked_faction then | 		if attacked_faction then | ||||||
| 			self.power = self.power - factions.power_per_attack | 			self.power = self.power - factions.power_per_attack | ||||||
| 			if attacked_faction.attacked_parcels[parcelpos] then  | 			if attacked_faction.attacked_parcels[parcelpos] then  | ||||||
| @@ -409,7 +499,7 @@ function factions.Faction.attack_parcel(self, parcelpos) | |||||||
| 			end | 			end | ||||||
| 			factions.save() | 			factions.save() | ||||||
| 		end     | 		end     | ||||||
|     ]] | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function factions.Faction.stop_attack(self, parcelpos) | function factions.Faction.stop_attack(self, parcelpos) | ||||||
| @@ -723,11 +813,10 @@ factions.faction_tick = function() | |||||||
|         end |         end | ||||||
|     end |     end | ||||||
| end | end | ||||||
|  | --[[ | ||||||
| local hudUpdate = 0. | local hudUpdate = 0. | ||||||
| local factionUpdate = 0. | local factionUpdate = 0. | ||||||
|  |  | ||||||
|  |  | ||||||
| minetest.register_globalstep( | minetest.register_globalstep( | ||||||
| function(dtime) | function(dtime) | ||||||
|     hudUpdate = hudUpdate + dtime |     hudUpdate = hudUpdate + dtime | ||||||
| @@ -756,14 +845,120 @@ function(dtime) | |||||||
|     end |     end | ||||||
| end | end | ||||||
| ) | ) | ||||||
|  | --]] | ||||||
|  |  | ||||||
|  | hud_ids = {} | ||||||
|  |  | ||||||
|  | createHudFactionName = function(player,factionname) | ||||||
|  | 	local name = player:get_player_name() | ||||||
|  | 	local id_name = name .. "1" | ||||||
|  | 	if not hud_ids[id_name] then | ||||||
|  | 		hud_ids[id_name] = player:hud_add({ | ||||||
|  | 			hud_elem_type = "text", | ||||||
|  | 			name = "factionName", | ||||||
|  | 			number = 0xFFFFFF, | ||||||
|  | 			position = {x=1, y = 0}, | ||||||
|  | 			text = "Faction "..factionname, | ||||||
|  | 			scale = {x=1, y=1}, | ||||||
|  | 			alignment = {x=-1, y=0}, | ||||||
|  | 			offset = {x = -20, y = 20} | ||||||
|  | 		}) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | createHudPower = function(player,faction) | ||||||
|  | 	local name = player:get_player_name() | ||||||
|  | 	local id_name = name .. "2" | ||||||
|  | 	if not hud_ids[id_name] then | ||||||
|  | 		hud_ids[id_name] = player:hud_add({ | ||||||
|  | 			hud_elem_type = "text", | ||||||
|  | 			name = "powerWatch", | ||||||
|  | 			number = 0xFFFFFF, | ||||||
|  | 			position = {x=0.9, y = .98}, | ||||||
|  | 			text = "Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower, | ||||||
|  | 			scale = {x=1, y=1}, | ||||||
|  | 			alignment = {x=-1, y=0}, | ||||||
|  | 			offset = {x = 0, y = 0} | ||||||
|  | 		}) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | updateHudPower = function(player,faction) | ||||||
|  | 	local name = player:get_player_name() | ||||||
|  | 	local id_name = name .. "2" | ||||||
|  | 	if hud_ids[id_name] then | ||||||
|  | 		player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | removeHud = function(player,numberString) | ||||||
|  | 	local name = player:get_player_name() | ||||||
|  | 	local id_name = name .. numberString | ||||||
|  | 	if hud_ids[id_name] then | ||||||
|  | 		player:hud_remove(hud_ids[id_name]) | ||||||
|  | 		hud_ids[id_name] = nil | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | hudUpdate = function() | ||||||
|  | 	minetest.after(.5,  | ||||||
|  | 	function() | ||||||
|  | 		local playerslist = minetest.get_connected_players() | ||||||
|  | 		for i in pairs(playerslist) do | ||||||
|  | 			local player = playerslist[i] | ||||||
|  | 			local name = player:get_player_name() | ||||||
|  | 			local faction = factions.get_faction_at(player:getpos()) | ||||||
|  | 			local id_name = name .. "0" | ||||||
|  | 			if hud_ids[id_name] then | ||||||
|  | 				player:hud_change(hud_ids[id_name],"text",(faction and faction.name) or "Wilderness") | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 		hudUpdate() | ||||||
|  | 	end) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | factionUpdate = function() | ||||||
|  | 	minetest.after(factions.tick_time,  | ||||||
|  | 	function() | ||||||
|  | 		factions.faction_tick() | ||||||
|  | 		factionUpdate() | ||||||
|  | 	end) | ||||||
|  | end | ||||||
|  |  | ||||||
| minetest.register_on_joinplayer( | minetest.register_on_joinplayer( | ||||||
| function(player) | function(player) | ||||||
|     local faction = factions.get_player_faction(player:get_player_name()) | 	local name = player:get_player_name() | ||||||
|  | 	hud_ids[name .. "0"] = player:hud_add({ | ||||||
|  | 		hud_elem_type = "text", | ||||||
|  | 		name = "factionLand", | ||||||
|  | 		number = 0xFFFFFF, | ||||||
|  | 		position = {x=0.1, y = .98}, | ||||||
|  | 		text = "Wilderness", | ||||||
|  | 		scale = {x=1, y=1}, | ||||||
|  | 		alignment = {x=0, y=0}, | ||||||
|  | 	}) | ||||||
|  |     local faction = factions.get_player_faction(name) | ||||||
|     if faction then |     if faction then | ||||||
|         faction.last_logon = os.time() |         faction.last_logon = os.time() | ||||||
|  | 		createHudFactionName(player,faction.name) | ||||||
|  | 		createHudPower(player,faction) | ||||||
|     end |     end | ||||||
| end | end | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | minetest.register_on_leaveplayer( | ||||||
|  | 	function(player) | ||||||
|  | 		local name = player:get_player_name() | ||||||
|  | 		local id_name = name .. "0" | ||||||
|  | 		if hud_ids[id_name] then | ||||||
|  | 			player:hud_remove(hud_ids[id_name]) | ||||||
|  | 			hud_ids[id_name] = nil | ||||||
|  | 		end | ||||||
|  | 		removeHud(player,"1") | ||||||
|  | 		removeHud(player,"2") | ||||||
|  | 	end | ||||||
|  | ) | ||||||
|  |  | ||||||
| minetest.register_on_respawnplayer( | minetest.register_on_respawnplayer( | ||||||
|     function(player) |     function(player) | ||||||
|         local faction = factions.get_player_faction(player:get_player_name()) |         local faction = factions.get_player_faction(player:get_player_name()) | ||||||
| @@ -782,7 +977,6 @@ minetest.register_on_respawnplayer( | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| local default_is_protected = minetest.is_protected | local default_is_protected = minetest.is_protected | ||||||
| minetest.is_protected = function(pos, player) | minetest.is_protected = function(pos, player) | ||||||
|     if pos.y < factions.protection_max_depth then |     if pos.y < factions.protection_max_depth then | ||||||
| @@ -822,3 +1016,5 @@ minetest.is_protected = function(pos, player) | |||||||
|     end |     end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | hudUpdate() | ||||||
|  | factionUpdate() | ||||||
							
								
								
									
										8
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								init.lua
									
									
									
									
									
								
							| @@ -5,21 +5,21 @@ | |||||||
| -- | -- | ||||||
| --! @file init.lua | --! @file init.lua | ||||||
| --! @brief factions mod to be used by other mods | --! @brief factions mod to be used by other mods | ||||||
| --! @copyright Sapier | --! @copyright Sapier, Coder12a | ||||||
| --! @author Sapier | --! @author Sapier, Coder12a | ||||||
| --! @date 2013-05-08 | --! @date 2013-05-08 | ||||||
| --! | --! | ||||||
| -- Contact sapier a t gmx net | -- Contact sapier a t gmx net | ||||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||||||
|  |  | ||||||
| factions_version = "0.8.0" | factions_version = "0.8.1" | ||||||
|  |  | ||||||
| core.log("action", "MOD: factions (by sapier) loading ...") | core.log("action", "MOD: factions (by sapier) loading ...") | ||||||
|  |  | ||||||
| --!path of mod | --!path of mod | ||||||
| factions_modpath = minetest.get_modpath("factions") | factions_modpath = minetest.get_modpath("factions") | ||||||
|  |  | ||||||
|  | dofile (factions_modpath .. "/config.lua") | ||||||
| dofile (factions_modpath .. "/factions.lua") | dofile (factions_modpath .. "/factions.lua") | ||||||
| dofile (factions_modpath .. "/chatcommands.lua") | dofile (factions_modpath .. "/chatcommands.lua") | ||||||
| dofile (factions_modpath .. "/nodes.lua") | dofile (factions_modpath .. "/nodes.lua") | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								settingtypes.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								settingtypes.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | [ValueSettings] | ||||||
|  |  | ||||||
|  | # The max depth of protection from a parcel. | ||||||
|  | protection_max_depth (Protection max depth) float -512 | ||||||
|  | # Cost of power to claim a parcel of land. | ||||||
|  | power_per_parcel (Power-per-parcel) float 0.5 | ||||||
|  | # Power lost on death. | ||||||
|  | power_per_death (Power-per-death) float 0.25 | ||||||
|  | # Power regeneration rate. | ||||||
|  | power_per_tick (Power-per-tick) float 0.125 | ||||||
|  | # Faction timer. This timer regenerates power if the faction members are online. | ||||||
|  | tick_time (Faction timer) float 60 | ||||||
|  | # Not in use. | ||||||
|  | power_per_attack (Power-per-attack) float 10 | ||||||
|  | # Limit how long a faction name can be. | ||||||
|  | faction_name_max_length (Faction name max) int 50 | ||||||
|  | # Limit how long a rank name can be. | ||||||
|  | rank_name_max_length (Rank name max length) int 25 | ||||||
|  | # The maximum amount of inactivity before disbanning a faction. | ||||||
|  | maximum_faction_inactivity (Maximum faction inactivity) int 604800 | ||||||
|  | # Power of a starting faction (needed for parcel claiming). | ||||||
|  | power (Starting power) float 2 | ||||||
|  | # Maximum power of a faction. | ||||||
|  | maxpower (Maximum power) float 2 | ||||||
|  | # How much power the banners make. | ||||||
|  | power_per_banner (power-per-banner) float 10 | ||||||
|  |  | ||||||
|  | [BoolSettings] | ||||||
|  |  | ||||||
|  | # Enable or disabled attack_parcel function. | ||||||
|  | attack_parcel (Enable attack parcel) bool false | ||||||
		Reference in New Issue
	
	Block a user