Skip to content

Commit

Permalink
Add Parties Feature (experimental) (#1337)
Browse files Browse the repository at this point in the history
* Add basic parties

Add parties that mostly work but dont do anything

* Basic parties working

Fix bugs with basic parties

* Add in full draft of parties

Add in draft of party alloc functionality

* fix maxpartysize glitch

Fix glitch where it used MAX_PARTY_SIZE instead of ctf_teams.MAX_PARTY_SIZE

* Party allocation fix

Make it work with any party allocator. Also fix some bugs with invites etc.

* Add better allocator for parties

Use a modified player allocator for the parties

* fix typos

* Add max party size as a setting you can change

* Clean up code

Make code pass luacheck. Fix a small bug. Make some of the unchanging party messages be in a table instead of hardcoded

* Try and fix merge conflicts

* Try and fix merge conflict in features.lua

* Try again to fix merge conflict in features.lua

* More info when player is not allowed to join invite

Notify inviter and not just the invited when the invited was unable to join a party cause it was already too big

* Delete an invite if player tries to accept and party is too big

If a valid invite is sent out but in the mean time the number of players in the sender's party grows, and then the invited tries to accept but is rejected cause the inviter's party is too big, the invite will be deleted.

* Fix difference between files

Add back in a newline at end of file that I deleted, in a random file. So that it is identical to upstream.

* Add newline at end of parties.lua

Make parties.lua fit formatting better with a newline at the end

---------

Co-authored-by: LandarVargan <[email protected]>
  • Loading branch information
Silvager and LoneWolfHT authored Jan 11, 2025
1 parent 8005a8b commit 58e47ae
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 4 deletions.
1 change: 1 addition & 0 deletions minetest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ctf.allocate_mode = 4
ctf.players_can_change_team = false
ctf.friendly_fire = false
ctf.autoalloc_on_joinplayer = true
ctf.max_party_size = 4

ctf.match = true
ctf.match.teams = 2
Expand Down
15 changes: 12 additions & 3 deletions mods/ctf/ctf_teams/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ end

local tpos = 1
function ctf_teams.default_team_allocator(player)
print("default team allocator ran")
if #ctf_teams.current_team_list <= 0 then return end -- No teams initialized yet
player = PlayerName(player)

Expand Down Expand Up @@ -100,9 +101,17 @@ function ctf_teams.allocate_teams(teams)
table.insert(ctf_teams.current_team_list, teamname)
end

local players = minetest.get_connected_players()
table.shuffle(players)
for _, player in ipairs(players) do
local unallocatedPlayers = minetest.get_connected_players()
if #ctf_teams.parties ~= 0 then
-- Remove any parties that are too big
ctf_teams.deleteOversizedParties()
-- This function will allocate party players into teams
-- and also remove players in parties who have been allocated from the table
unallocatedPlayers = ctf_teams.allocate_parties(unallocatedPlayers)
end
table.shuffle(unallocatedPlayers)

for _, player in ipairs(unallocatedPlayers) do
ctf_teams.allocate_player(player)
end
end
Expand Down
6 changes: 5 additions & 1 deletion mods/ctf/ctf_teams/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ ctf_core.include_files(
"commands.lua",
"register.lua",
"team_chest.lua",
"team_door.lua"
"team_door.lua",
"parties.lua"
)

minetest.register_on_mods_loaded(function()
Expand Down Expand Up @@ -103,6 +104,9 @@ minetest.register_on_mods_loaded(function()
end)

minetest.register_on_leaveplayer(function(player, timed_out, ...)

ctf_teams.checkAndClearAllPartyInfo(player:get_player_name())

local pteam = ctf_teams.get(player)

if not pteam then
Expand Down
Loading

0 comments on commit 58e47ae

Please sign in to comment.