Originally Posted by
Benz282
I have been conceptulizing a mod for a long time that would use a different recruiting system than is currently in place. Instead of being able to recruit every troop type right out of the barracks, you would train a "Recruit" and then place that unit on a specific tile on the map. Whenever a turn is ended and there is a "Recruit" unit on that tile, it is removed from the map and replaced with the next tier of troop, which would then continue until the highest level of troop is reached, or when the player removes the unit from the tile (this would not work for AI factions, obviously). For example:
"Peasant" is recruited in London.
Player moves "Peasant" to the magic tile.
Player's turn ends.
Script runs and replaces "Peasant" with "Levy Spearmen".
Player's turn ends.
"Town Watch" is replaced with "Sergeant Spearmen"
Player's turn ends.
"Sergeant Spearmen" is replaced with "Armored Spearmen"
Etc,
1 - Is it possible for scripts to recognize the composition of an army?
2 - Is it possible for scripts to recognize the presence of an army on a specific tile without a specific named character in the stack?
3 - Is it possible for scripts to remove specific units from the map?
4 - Is it possible for scripts to create units into a stack without the presence of a specific named character in that stack?
Soooo here comes the bad news, which happens quite often in scripting.
1- Scripts can't recognize a specific unit in an army, unless you are in a historical battle and you label the units so you inherently know which label applies to which unit. There are a few conditions that do this shoddily:
PercentageUnitCategory
UnitType
PercentageUnitAttribute
TrainedUnitCategory
TrainedUnitClass
UnitCategory
I_UnitExists
2- Again the options are limited. The following conditions could be workable in a roundabout fashion but there would be loopholes:
I_FactionNearTile
3- Yes, but not without player involvement or a character. This command is the only roundabout fashion:
destroy_units
4- spawn_army works to spawn a new army on a tile. create_unit works to spawn a unit into an existing settlement or character. So the short answer is no it probably isn't possible.
---------------------------------------------------------
Now... there might be a way to achieve something somewhat similar to what you are looking for. It would require more than you suggest, and would probably be full of loopholes, but it might work. I haven't tried this myself but I'll post my theory:
1) First create a character. This character should be created through the script and given a script label. Put the character at the location you want the units to spawn. Could give him high loyalty traits and traits that remove all his MP if you like as well. Give him a trait that only he has that he can be identified with, we'll call it "Spawner".
2) Move the unit you want to replace to join the character. Now in order to insure the unit is with the character, you have to give it an attribute in the EDU that no other units have(or only the other units in the chain). We'll say "gunpowder_unit" for now. Set up a monitor like this:
Code:
monitor_event CharacterSelected CharacterIsLocal
and PercentageUnitAttribute gunpowder_unit > 50.0 ;Only the bodyguard and the special unit
and Trait Spawner > 0
set_event_counter spawn_next_unit 1
end_monitor
This sets it up so we know the unit is with the character.
3) The next step is determining what the unit is. We only have one option to determine the exact unit type on the strat map, and that's "UnitType"(assuming it works). Since it only fires off a select few, we need to pick one that fits, so we'll use UnitDisbanded as our event.
Code:
monitor_event UnitDisbanded UnitType Peasant
and I_EventCounter spawn_next_unit == 1
wait 1
create_unit label_here, Sergeant_Spearmen, num 1, exp 0, arm 0, wep 0
set_event_counter spawn_next_unit 0
end_monitor
A similar chunk of code would need to be done for each unit type to be replaced. The player would have to manually disband the unit in order for it to fire. Now, there's already one glaring problem, the player could click any unit anywhere since the event counter has already been set. To fix this, we should set up a series of commands to disable the counter to make it impossible for them to reach the disband interface of another unit. Like so:
Code:
monitor_event SettlementSelected I_EventCounter spawn_next_unit == 1
set_event_counter spawn_next_unit 0
end_monitor
monitor_event CharacterSelected Trait Spawner < 1
and I_EventCounter spawn_next_unit == 1
set_event_counter spawn_next_unit 0
end_monitor
These two monitors should set the counter back to 0 whenever the player selects any character besides the spawner. Since the spawner also runs on character select, in order to enable it the player just has to select the spawner army again. So to trigger it the player would:
- Select spawner army
- Not select any other settlement/character
- Disband the unit to be replaced located in the spawner army
Theoretically the above code should function. One problem that may occur is inability to use unit labels with the create_unit command or the create_unit command only working with console_command in front, I'm basing it on the DocuDemons and common sense, but neither of those are always prevailing. You should also be able to do it for more than one unit since as long as only the bodyguard is there besides the replaceable units, the % with the attribute will always be over 50%.
Now, some problems assuming that code works:
- There's only so many attributes you can use, and most are useful for all units. "can_sap" is about the only one I remember that isn't all that useful. Finding a different way than attribute to determine that the unit exists in the army is potential and should be explored. You *might* be able to skip on the identification of the army composition altogether with the usage of the CharacterSelected and UnitDisbanded monitors subverting it.
- There's no delay between the unit arriving and being spawned. What you could do is set a counter timer once the unit has been detected in the selected character, then require the disband event to also require that timer to be a certain number in addition to having selected the spawner character.
- Monitors that use "Selected" will be firing all the time, so a vast number of them could cause lag.
Probably other things that would come up. But it's worth a try.