You can use my Garrison script if you want. Mine is based in the Garrison script made by LorDBulA (included into SPQR mod).
Here it is the code:

Code:
script

;console_command toggle_perfect_spy
;very useful to debug

declare_counter City1Besiged
set_counter City1Besiged 0
declare_counter City2Besiged
set_counter City2Besiged 0
;...per settlement

monitor_event FactionTurnEnd FactionType [faction1]
and I_LocalFaction [faction1]

   if I_CompareCounter City1Besiged = 0
      and not I_SettlementOwner [city1] = [faction1]
      if I_CharacterTypeNearTile [faction1] general,  2 x1,y1
         set_counter City1Besiged 1
      end_if
      if I_CharacterTypeNearTile [faction1] family,  2 x1,y1
         set_counter City1Besiged 1
      end_if
   end_if
   if I_CompareCounter City1Besiged = 2
      and not I_CharacterTypeNearTile [faction1] family, 2 x1,y1
      and not I_CharacterTypeNearTile [faction1] general, 2 x1,y1
      set_counter City1Besiged 0
   end_if

   if I_CompareCounter City2Besiged = 0
      and not I_SettlementOwner [city2] = [faction1]
      if I_CharacterTypeNearTile [faction1] general,  2 x2,y2
         set_counter City2Besiged 1
      end_if
      if I_CharacterTypeNearTile [faction1] family,  2 x2,y2
         set_counter City2Besiged 1
      end_if
   end_if
   if I_CompareCounter City2Besiged = 2
      and not I_CharacterTypeNearTile [faction1] family, 2 x2,y2
      and not I_CharacterTypeNearTile [faction1] general, 2 x2,y2
      set_counter City2Besiged 0
   end_if
   ;...per settlement

end_monitor
;...a monitor per possible local faction

monitor_event SettlementTurnEnd SettlementName [city1-mapname]
   and I_CompareCounter City1Besiged = 1
   and GarrisonSettlementRatio < 0.5
      if I_SettlementOwner [city1] = [faction1]
         console_command create_unit [city1] "unit name" 4
         console_command add_money -2000       
         console_command add_population City -1500
      end_if
      if I_SettlementOwner [city1] = [faction2]
         console_command create_unit [city1] "unit name" 4
         console_command add_money -2000       
         console_command add_population City -1500
      end_if
      set_counter City1Besiged 2
      ;...an if per faction
end_monitor

monitor_event SettlementTurnEnd SettlementName [city2-mapname]
   and I_CompareCounter City2Besiged = 1
   and GarrisonSettlementRatio < 0.5
      if I_SettlementOwner [city2] = [faction1]
         console_command create_unit [city1] "unit name" 4
         console_command add_money -2000       
         console_command add_population City -1500
      end_if
      if I_SettlementOwner [city2] = [faction2]
         console_command create_unit [city1] "unit name" 4
         console_command add_money -2000       
         console_command add_population City -1500
      end_if
      ;...an if per faction
      set_counter City2Besiged 2
end_monitor
;...a monitor per settlement


while TrueCondition
end_while

end_script
You need to change all words in brackets, I tried to use your same nomenclature. And copy-paste the code where it says ";...per faction or settlement"

Note: The condition "SettlementName" needs the name of the city that it is shown in the map, not the internal name.
You can see it in the file: data\text\imperial_campaign_regions_and_settlement_names.txt

ie:{Lepcis_Magna} Lepcis Magna
[city1]=internal name, ie:Lepcis_Magna
[city1-mapname]=name show in map, ie:Lepcis Magna

I also recommend you to read the Intermediate Guide to Scripting, By Epistolary Richard & Myrddraal. (if you didn't already read it)

Note2 - Important thing not said in this guide: When you use an "if" or "while" statment, you can only use conditions starting by "I_" . All other conditions need some Trigger requirements, and they can only be used with monitor_events. (the "Trigger requirements" of the condition must be in the "Exports" of the event)

start very simple, make sure what you have works, then add on. Writing more than a half-dozen lines of script without errors is difficult, particularly if you haven't done a lot of scripting.
Wise words. It is almost impossible to write the full script and get it working at the first attempt. I suggest you to test it with one city and 2 factions until the script is working. Then, you can add lines and adjust the script.

I hope this helps