Week 7
Advanced Triggers - What, You Expect Some Weird Catchphrase Everytime?
So we've already looked at some basic triggers in week 3 (the two time triggers and the one player left trigger). But those triggers are boring. So what other kinds of triggers are there? Lots, it turns out!
Building Count Trigger - This trigger counts ALL buildings of any type owned by a specified player and compares them to some value.
CreateBuildingCountTrigger(enable, one-time, player number, number to compare to, comparison type, "Trigger Function");
// Example:
CreateBuildingCountTrigger(1, 1, 0, 10, cmpGreaterEqual, "PlayerHasAtLeastTenBuildings");
Valid comparison types:
cmpEqual
cmpLower
cmpGreater
cmpLowerEqual
cmpGreaterEqual
Those should be pretty self-explanitory. Get to know them since you'll use them in a lot of triggers.
Vehicle Count Trigger - Same thing as above, but counts vehicles instead of structures.
CreateVehicleCountTrigger(enable, one-time, player number, number to compare to, comparison type, "Trigger Function");
Count Trigger - This is probably the most useful of the three count triggers as you can specify which type of unit we want to count.
CreateCountTrigger(enable, one-time, player number, unit to count, unit's cargo, number to compare to, comparison type, "Trigger Function");
// Example:
CreateCountTrigger(1, 1, 0, mapLynx, mapLaser, 7, cmpGreaterEqual, "HaveAtLeastSevenLaserLynx");
Attacked Trigger - This trigger fires when a unit group has been attacked. We'll go into more detail about unit groups later.
CreateAttackedTrigger(enabled, one-time, Unit Group, "Trigger Function");
// Example:
// Create some units
TethysGame::CreateUnit(AILynx1, mapLynx, LOCATION(x, y), mapMicrowave, 1, 0);
...
// Setup the group
FightGroup AI_MicrowaveLynxGroup;
// Add the units to the group
AI_MicrowaveLynxGroup.TakeUnit(AILynx1);
...
CreateAttackedTrigger(1, 1, AI_MicrowaveLynxGroup, "AttackedAI");
Damaged Trigger - Fires after a group has taken a certain amount of damage? (I haven't really experimented with this trigger, but it would probably be useful for getting an AI unit to repair damaged structures.)
CreateDamagedTrigger(enabled, one-time, Unit Group, Damage Taken, "Trigger Function);
// Example:
CreateDamageTrigger(1, 0, AI_Tokamaks, 250, "RepairTokamaks");
Escape Trigger - Despite the name, all this checks is if you have X amount of units carrying Y amount of Z cargo in some location.
CreateEscapeTrigger(enabled, one-time, Player Number, Upper left corner of location (X), Upper left corner of location (Y), Location Width, Location Height, Number of Units Required, Unit Type, Cargo Type, Cargo Amount, "Trigger Function");
// Examples
CreateEscapeTrigger(1, 1, 0, 10+31, 7-1, 5, 5, 7, mapTiger, mapThorsHammer, 1, "Bring seven Thor's Hammer Tigers to the upper left corner of the map");
CreateEscapeTrigger(1, 0, 0, 58+31, 58-1, 6, 6, 3, mapCargoTruck, (map_id)truckFood, 3000, "Bring Cargo Trucks carrying 3000 units of food to the lower right corner of the map");
Evac Trigger - Use this to create a "Have enough Evacuation Transports for your population." trigger.
CreateEvacTrigger(enable, one-time, Player Number, "Trigger Function");
// Example
CreateEvacTrigger(1, 0, 0, "Player1HasEnoughETs");
Kit Trigger - Checks if you have a structure kit of the specified type (in factory storage or in a ConVec).
CreateKitTrigger(enabled, one-time, Player Number, Structure Kit Type, Minimum Amount Needed, "Trigger Function");
// Example
CreateKitTrigger(1, 0, 0, mapCommandCenter, 1, "Have a Command Center kit in storage.");
Midas Trigger - Used to create a victory condition for the Midas multiplayer gametype (duh).
CreateMidasTrigger(enabled, one-time, Game Time Limit, "Trigger Function");
// Example
CreateMidasTrigger(1, 1, 25000, "Have the more ore in storage by mark 250."); // I'm pretty sure time is in ticks...
One Player Left Trigger - Used for a standard Last One Standing victory condition.
See Week 3 Tutorial for more info.
Operational Trigger - This trigger fires if X amount of structure Y is active (meaning neither Disabled nor Idled).
CreateOperationalTrigger(enabled, one-time, Player Number, Structure Type, Comparison Number, Comparison Type, "Trigger Function");
// Example:
CreateOperationalTrigger(1, 0, 0, mapCommandCenter, 0, cmpEqual, "PlayerHasNoActiveCommandCenter");
Point Trigger - Detects whether a unit (any unit) owned by the specified player exists at the specified coordinates.
CreatePointTrigger(enabled, one-time, Player Number, X-Position, Y-Position, "Trigger Function");
// Example:
CreatePointTrigger(1, 1, 0, 50+31, 60-1, "UnitAtPoint");
Rect Trigger - Don't use this. Use the Escape trigger instead; it gives you more control over what makes the trigger fire.
Research Trigger - Fires if the specified player researches the specified technology.
CreateResearchTrigger(enabled, one-time, Tech ID, Player Number, "Trigger Function");
// Example
CreateResearchTrigger(1, 1, 3851, 0, "MobileWeaponsPlatform_Researched");
Resource Trigger - Compares the player's resources to a specified value.
CreateResourceTrigger(enable, one-time, Resource Type, Comparison Amount, Player Number, Comparison Type, "Trigger Function");
// Example
CreateResourceTrigger(1, 0, resKids, 52, 0, cmpGreaterEqual, "Have at least 52 children");
// Valid Resource Types
resFood
resCommonOre
resRareOre
resKids
resWorkers
resScientists
resColonists
Time Triggers have already been covered extensively. Refer to Weeks 3 and 4 if you need to review.
Special Target - Marks the specified unit as special and lets OP2 know that another unit can park next to it and do something to it (scan it, steal wreckage, hijack an RLV, etc.).
CreateSpecialTarget(enabled, one-time, Unit Handle, Unit Type to Interact With, "Trigger Function");
// Example
Unit Eden_Spaceport;
Trigger Steal_RLV;
TethysGame::CreateUnit(Eden_Spaceport, mapSpaceport, LOCATION(42+31, 5-1), 1, mapNone, 0);
Eden_Spaceport.SetFactoryCargo(0, mapRLV, mapNone);
Steal_RLV = CreateSpecialTarget(1, 1, Eden_Spaceport, mapSpider, "StealEdenRLV");
// Note: In the trigger function, I'd be sure to call Eden_Spaceport.ClearSpecialTarget();
Set Trigger - This is a fun one. It lets you combine several triggers into one mega-trigger.
CreateSetTrigger(enabled, one-time, Total Triggers, Triggers Needed Before Set Trigger Fires, "Trigger Function", Subtrigger 1, Subtrigger 2, Subtrigger ...);
// Example
// Define a bunch of triggers here
Trigger WeaponsResearched, AttackTimeReached, PlayersDiscovered;
// ...
// Now create a set trigger that will fire if two of three conditions are met.
// Conditions: Players have researched weapons; Self-imposed attack mark has expired; Any player unit has been spotted
CreateSetTrigger(1, 1, 3, 2, "StartAttackingPlayers", WeaponsResearched, AttackTimeReached, PlayersDiscovered);
I think that's it! It wasn't a particularly exciting lesson, but we'll need all of this for next week's lesson:
Your First Land Rush!
And if people ask, I'll post some mini examples. Until then, see you next week.