Some More Scripting Questions

Modding, Map Editor, IES Scripting and Other Questions
Seven243
Posts: 31
Joined: 02 Nov 2022, 21:41
Has thanked: 4 times

Some More Scripting Questions

Post by Seven243 »

I'm working on a few scenarios and I have several script functions I can't figure out.
I'm trying to get the AI to just keep its ground units where they are when the mission starts, but I don't know how and SetAIInstantRallying(false) doesn't work.

In more than one scenario I'm trying to get a group of ground units to periodically spawn for the AI, but I can't figure out what they're called in the script. I've tried CreateGroupedUnitInArea("Mounted_Slinger"), ("LightCalvalry"), ("LightMounted"), ("LightMounted1"), and I can't figure out what the correct name is.

And does anyone know how I can make a new group of units spawn when the player captures a specific building?

User avatar
Dr.MonaLisa
High Representative
Posts: 8800
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 118 times

Re: Some More Scripting Questions

Post by Dr.MonaLisa »

According to: viewtopic.php?t=5589

You're supposed to type the unit name type, the same as the one visible in db.zip/db/units/*.ddf files.

The SetAIInstantRallying also accepts the player ID as argument, not just "false". Also "true" would actually make different behavior.

However, I think only pausing the AI player can help. In most of my scanarios I called the:

Code: Select all

void PausePlayerAI(int in_iPlayerID, bool bPaused)
For spawning units periodically, you can lookup my scripts:
viewtopic.php?p=23673#p23673

Pirates & Planes scenarios should have it.

I think there's no better way to learn how these functions work than looking at the actual working code used in different scenarios.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Seven243
Posts: 31
Joined: 02 Nov 2022, 21:41
Has thanked: 4 times

Re: Some More Scripting Questions

Post by Seven243 »

Thank you I'm Finally getting some of this stuff to work. But now I'm trying to spawn some extra units for the AI after a few minutes pass, and instead it just starts spawning infinite copies of the units.
Here's the script:

RULE SpawnHorde1 PERIODICITY 90
if ((NumUnitsInGroup("Horde") <3))
then SpawnHorde
END_RULE

ACTION SpawnHorde
SCRIPT WORLD
DoDelay(30);
STEP
CreateGroupedUnitInArea(2, "LightMounted1", false, "Horde", "Tur_spawn");
CreateGroupedUnitInArea(2, "HeavyMounted1", false, "Horde", "Tur_spawn");
CreateGroupedUnitInArea(2, "HeavyInfantry1", false, "Horde", "Tur_spawn");
END_SCRIPT
END_ACTION

and I want the group to respawn if it gets killed off. Any ideas what's wrong?
User avatar
Dr.MonaLisa
High Representative
Posts: 8800
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 118 times

Re: Some More Scripting Questions

Post by Dr.MonaLisa »

When using PERIODICITY rules, it's important to use an additional boolean to prevent ACTION from being executed multiple times.

As in my Pirates Scenario example:

Code: Select all

DEFINITIONS
bool PiratesDead
...

INITIALIZATION
PiratesDead = true;
...
END_INITIALIZATION
...
RULE NewShips PERIODICITY 5
if ((NumUnitsInGroup("Pirates") < HarderLvl) && PiratesDead && NotMore)
  then NewShips
END_RULE
ACTION NewShips
SCRIPT WORLD
PiratesDead = false;
HarderLvl = HarderLvl + 7;
PlayVoiceOver("Fx_Bld_Coastal_Defense.mp3");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "FightingSail",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Galleon",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates1");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates2");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates3");
CreateGroupedUnitInArea(1, "Frigate",
"Pirates", false, "NewPirates3");
DoDelay(1);
STEP
SelectGroup("Pirates");
SetSelectionStance(kStanceType_Aggressive);
SetSelectionFormation("StaggeredLine");
SearchAndDestroyWithSelection();
PiratesDead = true;
END_SCRIPT
END_ACTION
...
As you can see, "PiratesDead" is set to "false" on ACTION start, and then back to "true" at the end of the action.
Ignore the incorrect naming. "PiratesDead" is actually not really representing the actual status. It's just faster to create variable names randomly when scripting big scenarios.

This makes sure that the action is only executed 1 time.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
These users thanked the author Dr.MonaLisa for the post:
Seven243
Seven243
Posts: 31
Joined: 02 Nov 2022, 21:41
Has thanked: 4 times

Re: Some More Scripting Questions

Post by Seven243 »

Is there a way I can make a group only spawn if you or the AI has below a certain population capacity? Or make the group respawn once all of the units in it have been killed (or when say, all but three have been killed)? And also prevent the group from spawning if the player is at their population capacity. I'll also post some of these scenarios when I'm done with them (or get tired of working on them).
User avatar
Dr.MonaLisa
High Representative
Posts: 8800
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 118 times

Re: Some More Scripting Questions

Post by Dr.MonaLisa »

According to: viewtopic.php?t=5589

You could use the "GetPlayerPopulation" function.

You can make units respawn when killed using exactly the same method as the one I posted above from my Pirates scenario: "if ((NumUnitsInGroup("Pirates") < HarderLvl)".

So the entire syntax would be:
if((GetPlayerPopulation(X) < ExpectedPopulation) && (NumUnitsInGroup("Pirates") < HarderLvl)) then Action.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Seven243
Posts: 31
Joined: 02 Nov 2022, 21:41
Has thanked: 4 times

Re: Some More Scripting Questions

Post by Seven243 »

I can't understand this and I don't know what expectedpopulation is supposed to do. Thanks, but you're probably getting tired of trying to help me and I doubt I'll be able to do this.

Added after 25 minutes 3 seconds:
Here's the incomplete scenarios I was working on
Attachments
WWII Idk.scn
(1.29 MiB) Downloaded 29 times
WW2 Script.ies
(8.2 KiB) Downloaded 30 times
Nomad Invasion.scn
(1.42 MiB) Downloaded 30 times
Nomad Invasion Script.ies
(9.69 KiB) Downloaded 33 times
User avatar
Dr.MonaLisa
High Representative
Posts: 8800
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 118 times

Re: Some More Scripting Questions

Post by Dr.MonaLisa »

Expected population would be a defined int number. I put it in variable for easier understanding. So this could be anything, like "300" or "600", depending on what population should be max for new units to respawn.

But IES scripting is annoying and I avoid it after the last scenario I made. It's too much testing.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Seven243
Posts: 31
Joined: 02 Nov 2022, 21:41
Has thanked: 4 times

Re: Some More Scripting Questions

Post by Seven243 »

The createunit command sort of works how I intended, but it doesn't work for a second player. I also somehow got objectives to work in another version of that scenario, but I'm not sure how to make the scenario end when they're completed.
Attachments
Nomad- Turk Script.ies
(9.21 KiB) Downloaded 17 times
Nomad Invasion - Turks.scn
(1.43 MiB) Downloaded 16 times
User avatar
Dr.MonaLisa
High Representative
Posts: 8800
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 118 times

Re: Some More Scripting Questions

Post by Dr.MonaLisa »

Winning conditions in the map editor should be set to: Script Says So (or something like this), and then a simple WinScanario function call (hope I remember it correctly).
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Post Reply

Return to “Questions”