Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. import("ScarUtil.scar")
  2. import("Fatalities/Fatalities.scar")
  3. import("Prototype/WorldEntityCollector.scar")
  4. import("Prototype/VPTickerWin-Annihilate_Functions.scar")
  5. import("Prototype/SpecialAEFunctions.scar")
  6. import("WinConditions/Annihilate.scar")
  7.  
  8. FVP_CapRate = 0.25; -- Global variable the defines the capture rate of victory points - Default is 0.25 (1 is CoH2 standard)
  9. FVP_Points = 2; -- Global variable that defines the amount of points being lost per interval - Default is 2 (1 is CoH2 standard)
  10. FVP_Interval = 3; -- Global variable that defines, in seconds, the time between each point calculation - Default is 3 (4 is CoH2 standard)
  11. FVP_Extreme = true; -- Global variable defining whether a team wins if they own all victory points. - Default is true
  12.  
  13. SetGlobals();
  14.  
  15. function WinCondition_GameOver(winningTeam, losingTeam)
  16.     -- Set the winning team (this will fire win/loss events for each player).
  17.     World_SetTeamWin(winningTeam)
  18.    
  19.     local winningPlayers = Team_GetPlayers(winningTeam);
  20.     local losingPlayers = Team_GetPlayers(losingTeam);
  21.    
  22.     Fatality_Execute(winningPlayers, losingPlayers)
  23.    
  24. end
  25.  
  26. function WinCondition_Check()
  27.     local results = {}
  28.  
  29.     -- Check every player on each team for ownership of the "annihilation_condition" entity.
  30.     for i = 1, World_GetPlayerCount() do
  31.         local player = World_GetPlayerAt(i)
  32.         local team = Player_GetTeam(player)
  33.    
  34.         results[team] = results[team] or { surrender_count = 0, annihilation_condition_count = 0 }
  35.        
  36.         -- If any player on a team has surrendered, that team loses.
  37.         if (Player_IsSurrendered(player)) then
  38.             results[team].surrender_count = results[team].surrender_count + 1
  39.         end
  40.        
  41.         -- If at least one player on a given team owns an "annihilation_condition" entity, then that team has not yet lost.
  42.         if (Player_IsAlive(player)) then
  43.             local entities = Player_GetEntities(player)
  44.             for entityCount = 1, EGroup_CountSpawned(entities) do
  45.                 local entity = EGroup_GetSpawnedEntityAt(entities, entityCount)
  46.                 if (Entity_IsOfType(entity, "annihilation_condition")) then
  47.                     results[team].annihilation_condition_count = results[team].annihilation_condition_count + 1
  48.                     break
  49.                 end
  50.             end
  51.         end
  52.     end
  53.    
  54.     -- Check if any team has lost.
  55.     for team,result in pairs(results) do
  56.         if (result.surrender_count > 0 or result.annihilation_condition_count == 0) then
  57.             Rule_RemoveAll()
  58.            
  59.             local winningTeam = Team_GetEnemyTeam(team)
  60.             local losingTeam = team
  61.  
  62.             WinCondition_GameOver(winningTeam, losingTeam)
  63.         end
  64.     end
  65.  
  66. end
  67.  
  68. totalPointsOnMap = 0;
  69.  
  70. local function WinCondition_Init()
  71.    
  72.     -- VP Initialisation data
  73.     _initdata();
  74.     WinWarning_SetMaxTickers(VPTickerData.start_points, VPTickerData.start_points);
  75.    
  76.     -- Set global VP variables
  77.     totalPointsOnMap = #WorldEntityCollector:GetEntities("victory_point")
  78.     VPTickerData.ticker_per_point = FVP_Points;
  79.    
  80.     -- Initialise players
  81.     for i = 1, World_GetPlayerCount() do
  82.         local player = World_GetPlayerAt(i)
  83.         local teamId = Player_GetTeam(player)
  84.         if VPTickerData.team_data[teamId] == nil then
  85.             VPTickerData.team_data[teamId] =
  86.             {
  87.                 tickers = VPTickerData.start_points,
  88.                 points_held = 0,
  89.                 victory_balance = 0,
  90.                 pausedPoints = 0,
  91.             }
  92.         end
  93.     end
  94.    
  95.     -- Modify capture rate on victory points
  96.     local t_ventities = WorldEntityCollector:GetEntities("victory_point");
  97.     _victory = EGroup_CreateIfNotFound("_victory");
  98.     for i=1, #t_ventities do
  99.         EGroup_Add(_victory, t_ventities[i]);
  100.     end
  101.    
  102.     Modify_CaptureTime(_victory, FVP_CapRate);
  103.    
  104.     -- Kick off VP stuff
  105.     Rule_AddInterval(VPTicker_MainRule, FVP_Interval)
  106.     Rule_AddInterval(VPTicker_UpdateTickers, 0.25)
  107.  
  108.     -- Add reminders when ticker points reach certain levels and check annihilation
  109.     Rule_AddInterval(VPTicker_PointReminder, 1)
  110.     Rule_AddInterval(WinCondition_Check, 3);
  111.    
  112.     -- Check if any team owns all victory points
  113.     if (FVP_Extreme) then
  114.         Rule_AddInterval(VPTicker_SecondRule, 1);
  115.     end
  116.    
  117. end
  118.  
  119. Scar_AddInit(WinCondition_Init);
  120.  
  121. function VPTicker_SecondRule()
  122.    
  123.     for i=1, World_GetPlayerCount() do
  124.         local player = World_GetPlayerAt(i);
  125.         if (Player_GetNumVictoryPoints(player) == VPTickerData.world_point_count) then
  126.             VPTicker_GameOver(Player_GetTeam(player), Player_GetTeam(Player_FindFirstEnemyPlayer(player)));
  127.         end
  128.     end
  129.    
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement