Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import("ScarUtil.scar")
- import("Fatalities/Fatalities.scar")
- import("Prototype/WorldEntityCollector.scar")
- import("Prototype/VPTickerWin-Annihilate_Functions.scar")
- import("Prototype/SpecialAEFunctions.scar")
- import("WinConditions/Annihilate.scar")
- FVP_CapRate = 0.25; -- Global variable the defines the capture rate of victory points - Default is 0.25 (1 is CoH2 standard)
- FVP_Points = 2; -- Global variable that defines the amount of points being lost per interval - Default is 2 (1 is CoH2 standard)
- FVP_Interval = 3; -- Global variable that defines, in seconds, the time between each point calculation - Default is 3 (4 is CoH2 standard)
- FVP_Extreme = true; -- Global variable defining whether a team wins if they own all victory points. - Default is true
- SetGlobals();
- function WinCondition_GameOver(winningTeam, losingTeam)
- -- Set the winning team (this will fire win/loss events for each player).
- World_SetTeamWin(winningTeam)
- local winningPlayers = Team_GetPlayers(winningTeam);
- local losingPlayers = Team_GetPlayers(losingTeam);
- Fatality_Execute(winningPlayers, losingPlayers)
- end
- function WinCondition_Check()
- local results = {}
- -- Check every player on each team for ownership of the "annihilation_condition" entity.
- for i = 1, World_GetPlayerCount() do
- local player = World_GetPlayerAt(i)
- local team = Player_GetTeam(player)
- results[team] = results[team] or { surrender_count = 0, annihilation_condition_count = 0 }
- -- If any player on a team has surrendered, that team loses.
- if (Player_IsSurrendered(player)) then
- results[team].surrender_count = results[team].surrender_count + 1
- end
- -- If at least one player on a given team owns an "annihilation_condition" entity, then that team has not yet lost.
- if (Player_IsAlive(player)) then
- local entities = Player_GetEntities(player)
- for entityCount = 1, EGroup_CountSpawned(entities) do
- local entity = EGroup_GetSpawnedEntityAt(entities, entityCount)
- if (Entity_IsOfType(entity, "annihilation_condition")) then
- results[team].annihilation_condition_count = results[team].annihilation_condition_count + 1
- break
- end
- end
- end
- end
- -- Check if any team has lost.
- for team,result in pairs(results) do
- if (result.surrender_count > 0 or result.annihilation_condition_count == 0) then
- Rule_RemoveAll()
- local winningTeam = Team_GetEnemyTeam(team)
- local losingTeam = team
- WinCondition_GameOver(winningTeam, losingTeam)
- end
- end
- end
- totalPointsOnMap = 0;
- local function WinCondition_Init()
- -- VP Initialisation data
- _initdata();
- WinWarning_SetMaxTickers(VPTickerData.start_points, VPTickerData.start_points);
- -- Set global VP variables
- totalPointsOnMap = #WorldEntityCollector:GetEntities("victory_point")
- VPTickerData.ticker_per_point = FVP_Points;
- -- Initialise players
- for i = 1, World_GetPlayerCount() do
- local player = World_GetPlayerAt(i)
- local teamId = Player_GetTeam(player)
- if VPTickerData.team_data[teamId] == nil then
- VPTickerData.team_data[teamId] =
- {
- tickers = VPTickerData.start_points,
- points_held = 0,
- victory_balance = 0,
- pausedPoints = 0,
- }
- end
- end
- -- Modify capture rate on victory points
- local t_ventities = WorldEntityCollector:GetEntities("victory_point");
- _victory = EGroup_CreateIfNotFound("_victory");
- for i=1, #t_ventities do
- EGroup_Add(_victory, t_ventities[i]);
- end
- Modify_CaptureTime(_victory, FVP_CapRate);
- -- Kick off VP stuff
- Rule_AddInterval(VPTicker_MainRule, FVP_Interval)
- Rule_AddInterval(VPTicker_UpdateTickers, 0.25)
- -- Add reminders when ticker points reach certain levels and check annihilation
- Rule_AddInterval(VPTicker_PointReminder, 1)
- Rule_AddInterval(WinCondition_Check, 3);
- -- Check if any team owns all victory points
- if (FVP_Extreme) then
- Rule_AddInterval(VPTicker_SecondRule, 1);
- end
- end
- Scar_AddInit(WinCondition_Init);
- function VPTicker_SecondRule()
- for i=1, World_GetPlayerCount() do
- local player = World_GetPlayerAt(i);
- if (Player_GetNumVictoryPoints(player) == VPTickerData.world_point_count) then
- VPTicker_GameOver(Player_GetTeam(player), Player_GetTeam(Player_FindFirstEnemyPlayer(player)));
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement