Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lywit authored Nov 1, 2021
1 parent fd4b302 commit c3dd2f0
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
101 changes: 101 additions & 0 deletions ext/server/__init__.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
require 'config'

local humanTeamId = 2
local botTeamId = 1

Events:Subscribe('Level:Loaded', function(levelName, gameMode, round, roundsPerMap)
DisableTeamSwitching()

print("Team selection mode = " .. teamMode)

if teamMode == 1 then
SetHumanTeam(math.random(1, 2))
elseif teamMode == 2 then
SwapTeams()
elseif teamMode == 3 then
SetHumanTeam(1)
elseif teamMode == 4 then
SetHumanTeam(2)
end

PrintHumanTeam()
print("Squad size = " .. squadSize)

BalanceAllPlayers()
end)


Events:Subscribe('Player:TeamChange', function(player, team, squad)
BalancePlayer(player)
end)

function BalancePlayer(player)
if player == nil then
return
end

if player.onlineId == 0 or player.guid == 0 then
return
else
if player.teamId ~= humanTeamId then
player.teamId = humanTeamId
else
return
end
end

if player.squadId == 0 or player.squadId == 33 then
FindSquad(player)
end

print("Moved " .. player.name .. " to team '" .. player.teamId .. "' squad '" .. player.squadId .. "'")
end

function BalanceAllPlayers()
for i,player in ipairs(PlayerManager:GetPlayers()) do
BalancePlayer(player)
end
end

function FindSquad(player)
for i=1,32 do
if TeamSquadManager:GetSquadPlayerCount(player.teamId, i) < squadSize then
player.squadId = i
break
end
end
end

function SetHumanTeam(team)
if team == 1 then
humanTeamId = 1
botTeamId = 2
else
humanTeamId = 2
botTeamId = 1
end
end

function SwapTeams()
local tempHumanId = humanTeamId
local tempBotId = botTeamId

humanTeamId = tempBotId
botTeamId = tempHumanId
end

function PrintHumanTeam()
if humanTeamId == 1 then
print("Human team = US")
else
print("Human team = RU")
end
end

function DisableTeamSwitching()
local s_SyncedBFSettings = ResourceManager:GetSettings("SyncedBFSettings")
if s_SyncedBFSettings ~= nil then
s_SyncedBFSettings = SyncedBFSettings(s_SyncedBFSettings)
s_SyncedBFSettings.teamSwitchingAllowed = false
end
end
10 changes: 10 additions & 0 deletions ext/server/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- The teamMode allows you to choose how the human team is selected every round
-- 1 = random team
-- 2 = swapped teams (This will swap the teams between rounds, if humans were US in the last round, they'll get RU in the next)
-- 3 = Always US
-- 4 = Always RU
teamMode = 1

-- Set squadSize equal to the squad size you've configured in your server's startup.txt
-- Vanilla default = 4
squadSize = 4
12 changes: 12 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Name": "No PVP",
"Description": "Puts those pesky humans in one place",
"Authors": ["P!NK_Lesley aka PowerChopper"],
"Tags": ["no-pvp"],
"Version": "1.0.0",
"HasVeniceEXT": true,
"HasWebUI": false,
"Dependencies": {
"veniceext": "^1.0.0"
}
}

0 comments on commit c3dd2f0

Please sign in to comment.