Scripting AI unit spawn/behavior at particular location?

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, Panzer Corps Design, Panzer Corps Moderators

Post Reply
Spaznetz
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Fri Mar 09, 2018 4:42 pm

Scripting AI unit spawn/behavior at particular location?

Post by Spaznetz »

Are there any tutorials on scripting AI unit spawn and behavior?

I'm trying to figure out how to get the AI to spawn reinforcements at a particular hex (or set of hexes) and then have them move into attack positions or retake cities that have been left open.

TIA for any info.
dalfrede
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1462
Joined: Wed Mar 15, 2017 7:48 pm

Re: Scripting AI unit spawn/behavior at particular location?

Post by dalfrede »

Spaznetz wrote: Are there any tutorials on scripting AI unit spawn and behavior?
No.
Spaznetz wrote: I'm trying to figure out how to get the AI to spawn reinforcements at a particular hex (or set of hexes) and then have them move into attack positions or retake cities that have been left open.
Spawning won't work, the AI is mindless. :D

The key is to place units with triggers.
The unit appears when the trigger is activated.
Set AI behavior to:
'Attacker' or
'move to' , and set AI zone to where you choose to retake.
These units can be placed somewhat randomly, the last option on Unit Params.
The trigger can be randomized as well, such as 50% chance of unit appearing on trigger.


The second way is to place units into a zone.
Add Scenario Param script:
Add trigger.
Add script 'Set All units in zone X to' . . .
These units sit in place and can be attacked/destroyed before they are triggered.
There comes a time on every project when it is time to shoot the engineer and ship the damn thing.
Spaznetz
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Fri Mar 09, 2018 4:42 pm

Re: Scripting AI unit spawn/behavior at particular location?

Post by Spaznetz »

dalfrede wrote:
Spawning won't work, the AI is mindless. :D

The key is to place units with triggers.
The unit appears when the trigger is activated.
Set AI behavior to:
'Attacker' or
'move to' , and set AI zone to where you choose to retake.
These units can be placed somewhat randomly, the last option on Unit Params.
The trigger can be randomized as well, such as 50% chance of unit appearing on trigger.


The second way is to place units into a zone.
Add Scenario Param script:
Add trigger.
Add script 'Set All units in zone X to' . . .
These units sit in place and can be attacked/destroyed before they are triggered.
Thanks for the info, dalfrede. I'm fumbling in the dark here :)

Would it be possible to combine the 2 methods? Make a zone that would be set to 'attack' initially but has no units in it at the start of the scenario and then have units spawn on a later turn when triggered?
dalfrede
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1462
Joined: Wed Mar 15, 2017 7:48 pm

Re: Scripting AI unit spawn/behavior at particular location?

Post by dalfrede »

Spaznetz wrote: Would it be possible to combine the 2 methods? Make a zone that would be set to 'attack' initially but has no units in it at the start of the scenario and then have units spawn on a later turn when triggered?
If you set run count on your script to 99, it would set any unit in the zone to attacker for the first 99 turns.

If you place the unit with a 'Move To' order, it will fight it's way to the given zone when it appears.
The 'Attacker' order does not direct a unit to a specific area, just attack the closest enemy unit or flag.

You may want to do a search for trigger or script to find previous discussions of similar topics.

such as:
Rudankort wrote: AI zone is mandatory for the following 5 AI orders:

Move To. The unit will move to the nearest hex in AI zone, then next nearest and until the zone is exhausted. Then its behavior will reset to Default.
Random Move To. The unit will select random hex from AI zone and move there. Then its behavior will reset to Default.
Patrol. The unit will move to the nearest hex in AI zone, then next nearest etc. untis the zone is exhausted, then it will start from the first hex again etc. in a loop.
Random Patrol. On every turn the unit will choose a random hex from AI zone and move there.
Disembark. The unit will choose a random hex from AI zone and will move and then disembark there. Then its behavior will reset to Default. This behavior is similar to "Random Move To", only disembark action is added in the end.

All the other AI behaviors do not use AI zone setting.
There comes a time on every project when it is time to shoot the engineer and ship the damn thing.
captainjack
Brigadier-General - 15 cm Nblwf 41
Brigadier-General - 15 cm Nblwf 41
Posts: 1908
Joined: Thu Sep 13, 2012 7:42 am

Re: Scripting AI unit spawn/behavior at particular location?

Post by captainjack »

You can pre-programme a unit to stay put in the unit editor. This means you don't have to give instructions after deployment.

Here's what I've learned so far about random deployments.
If you give each unit a random chance to appear the the check is run individually.
If you want the units to hang around as a blocking force if a small group, you can either deploy them into a zone or give them a name (eg "4th Panzer"). Then run a check to count number of units in zone x or with name "4th Panzer" if 5 or more, change orders to move to or attack.
You can script the AI to deply units on a specific trigger so they all appear at once.
If you want to make a whole group of units appear randomly (so all appear or none appear) you can create a random trigger to create a tag (4Panzer). All units with trigger "4Panzer" appear when the tag exists, but if the chance never comes off they all stay away.
If you want to deploy them in partly random locations, you can specify a radius around a specified hex (or where the unit is placed on the map) in the editor. If you want a different approach you can create a zone which contains many more hexes than there are units. The units appear dispersed around the zone. This is good for minefields and similar obstacles like well entrenched AT guns, as you can guess where they are likely to be without being sure exactly where.

These provide quite a lot of variety, but I'm sure there's others.
Spaznetz
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Fri Mar 09, 2018 4:42 pm

Re: Scripting AI unit spawn/behavior at particular location?

Post by Spaznetz »

Thanks, dalfrede & captainjack.

There's a lot more going on with scripting than I have the skill to make use of right now, but I appreciate all the help and information.
Loamshire
Corporal - 5 cm Pak 38
Corporal - 5 cm Pak 38
Posts: 34
Joined: Mon Jun 04, 2012 9:54 pm

Re: Scripting AI unit spawn/behavior at particular location?

Post by Loamshire »

Not quite sure what's meant by spawning, but it’s certainly nice to introduce a few random chance appearances in a scenario. That way enemy units are not the same every time, or in the same place. But using just random chance scripts can produce unbalanced results - all, some or none of the units can turn up and so upset the balance of the game. This is a basic script I use to ensure that only one out of three possible units turns up.
Its basic foundations are;

Unit 1 and Unit 2 are present – Unit 1 is deleted
Unit 2 and Unit 3 are present – Unit 2 is deleted
Unit 1 and Unit 3 are present – Unit 3 is deleted
If only one unit is present – no action is needed
If all three units are present - the same two are arbitrarily deleted each time
If no units are present –the same one is arbitrarily added each time

https://drive.google.com/file/d/1K6oq9L ... sp=sharing An image of the Scenario Parameters top screen

1. Each of the three units is given a tag number when they appear. Via Unit Scripts these units have unique names (which are used in the triggers; Map Condition and Unit Action). They have a random chance of coming on (eg set to 35%) and are set to appear for only the single turn.
2. Should all three tags be generated a further tag is needed and created.
3. Should all three tags be generated this Remove Tag prevents all further combinations of tags 1 to 3 being created.
4. This is an arbitrary unit deletion of two units for when all three units do appear. Using the Scenario Parameters Unit Action with strength set to zero.
5. These tags are all the combinations of the two out of the three possible units appearing, each combination leaves a different unit in place via the Unit Action script at the end of the turn.

If none of the three key units come on (they come on by chance eg 35%) further script can be written to ensure an arbitrary arrival if none appear.

When the three units are key-units for reinforcements. The three groups of reinforcements which are each scheduled to arrive, each have a different key-unit as their trigger, and are set to do so on the next turn, but of course only one group will appear because of the scripting.

I realise my explaining could perhaps be clearer and there’s things I’ve not explained fully here. I’m understanding why the scenario editor manual may be a little sparse – one thing just leads into another. Also, there’s certainly more than one way to do things.
Post Reply

Return to “Panzer Corps : Scenario Design”