that is quite easy to achieve. You will need to add a script in the campaign_script.txt. something along the lines of this:
Code:
monitor_event FactionturnStart FactionType sicily
and TargetFactionType milan
and DiplomaticStanceFactions = Allied
set_event_counter allowUnit 1
end_monitor
monitor_event FactionturnStart FactionType sicily
and TargetFactionType milan
and not DiplomaticStanceFactions = Allied
set_event_counter allowUnit 0
end_monitor
This is just an example and i am using sicily and milan as the two factions you want to be allied.
the first monitor sets an event counter to 1 when the two factions are allied. the second monitor sets it to 0 when they are not allied (they can still have trade agreements and be on good terms though and the unit will only be available IF they are allied).
this event counter can than be added to the EDB unit line you wish to make available, as such:
Code:
recruit_pool "rohan rider" 1 0.05 2 2 requires factions { sicily, }
and region_religion numenorian 80 and hidden_resource minas_tirith and event_counter allowUnit 1
This will make the said unit available to sicily when sicily is allied with milan.
your last question will require a little more scripting...and you can only do it for one or all of the said unit. Allow me to show you...
Code:
monitor_event FactionturnStart FactionType sicily
if I_UnitExists milan rohan rider
set_event_counter allowUnit 0
end_if
if not I_UnitExists milan rohan rider
set_event_counter allowUnit 1
end_if
end_monitor
This will only allow 1 unit of the unit type in question faction wide.
another option is the folowing:
Code:
declare_counter unitCount
monitor_event UnitTrained UnitType rohan rider
and FactionType sicily
if I_eventCounter allowUnit = 1
if I_CompareCounter unitCount <= 2
inc_counter unitCount 1
end_if
if I_CompareCounter unitCount >= 2
set_event_counter allowUnit 0
end_if
end_if
end_monitor
with this, the unitCount counter is not reduced so once you get to 2 thats it. you will need another script to decrease the unitCount to once again allow the unit to be trained. Somthing like:
Code:
monitor_event UnitDisbanded UnitType rohan rider
and FactionType sicily
inc_counter unitCount -1
end_monitor
But that still doesnt take into account if the unit is lost in battle or rebels against you. You might want to reduce the counter every 50 turns or something... or just allow the unit to be recruited once.
I am already using this script in mod i am working on and it works fine. the only difference is i am ensuring the two factions in question have trade agreements.