Advertisement
Neirai

BlackFoot

Dec 1st, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. -- CountingCoup -- Author: Neirai -- DateCreated: 5/8/2014 1:40:33 PM
  2. -- Allows Counting Coup to be a big part of playing the Blackfoot --
  3. --------------------------------------------------------------------
  4. function CheckBravery(pPlayer, pUnit)
  5.     --local pPlayer = Players[player]
  6.     --local pUnit = pPlayer:GetUnitByID(unit)
  7.     local pPlot = pUnit:GetPlot()
  8.     local x = pPlot:GetX()
  9.     local y = pPlot:GetY()
  10.     print(x .. ", " .. y)
  11.     local range = 1
  12.     for dx = -range, range do
  13.         for dy = -range, range do
  14.             local plot = Map.PlotXYWithRangeCheck(x, y, dx, dy, range)
  15.             if plot then
  16.                 local pOther = plot:GetUnit()
  17.                 if pOther ~= nil then
  18.                     local pTeam = pPlayer:GetTeam()
  19.                     local oTeam = pOther:GetTeam()
  20.                     if Teams[pTeam]:IsAtWar(Teams[oTeam]) then
  21.                         print("We're at war")
  22.                         return true
  23.                     end
  24.                 end
  25.             end
  26.         end
  27.     end
  28.     return false
  29. end
  30.  
  31. function CountSomeCoup(PlayerID)
  32.     local pPlayer = Players[PlayerID]
  33.     local pCiv = pPlayer:GetCivilizationType()
  34.     if (pCiv == GameInfoTypes.CIVILIZATION_BLACKFOOTFIRSTNATION) then
  35.         print ("I'm gonna count me some coup")
  36.         for pUnit in pPlayer:Units() do
  37.             if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_COUNTSCOUP1) then --has this unit triggered counting coup?
  38.                 if CheckBravery(pPlayer, pUnit) then
  39.                     local pExp = (pUnit:GetLevel() * 0.4)
  40.                     if pExp > 2 then
  41.                         print("Big Extra XP")
  42.                         pUnit:ChangeExperience(pExp, -1)
  43.                     else
  44.                         print("Little Extra XP")
  45.                         pUnit:ChangeExperience(2, -1)
  46.                     end
  47.                 end
  48.                 local pPlot = pUnit:GetPlot()
  49.                 if pPlot:GetResourceType(-1) == GameInfoTypes.RESOURCE_BISON or pPlot:GetResourceType(-1) == GameInfoTypes.RESOURCE_PRESERVEDBISON then
  50.                     local pExp = (pUnit:GetLevel() * 0.4)
  51.                     if pExp > 2 then
  52.                         print("Big Extra XP")
  53.                         pUnit:ChangeExperience(pExp, -1)
  54.                     else
  55.                         print("Little Extra XP")
  56.                         pUnit:ChangeExperience(2, -1)
  57.                     end
  58.                     pUnit:ChangeDamage(15)
  59.                 end
  60.             end
  61.         end
  62.     else
  63.         for pUnit in pPlayer:Units() do
  64.             local pPlot = pUnit:GetPlot()
  65.             if pPlot ~= nil then
  66.                 local owner = pPlot:GetOwner()
  67.                 if owner ~= -1 then
  68.                     local pOwner = Players[owner]
  69.                     if pOwner:GetCivilizationType() == GameInfoTypes.CIVILIZATION_BLACKFOOTFIRSTNATION then
  70.                         if pPlot:GetResourceType(-1) == GameInfoTypes.RESOURCE_BISON or pPlot:GetResourceType(-1) == GameInfoTypes.RESOURCE_PRESERVEDBISON then
  71.                             print("Bison Damage!")
  72.                             local BisonDamage = pUnit:GetCurrHitPoints() - 25
  73.                             if BisonDamage > 0 then
  74.                                 pUnit:ChangeDamage(25)
  75.                             else
  76.                                 pUnit:Kill(true, -1)
  77.                             end
  78.                         end
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.     end
  84. end
  85. GameEvents.PlayerDoTurn.Add(CountSomeCoup)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement