Call of Duty 4: SP - Color Groups

From COD Modding & Mapping Wiki
Revision as of 12:00, 23 February 2012 by Ingram (talk | contribs) (Simplify codes and make more readable)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

By Bloodlust

Friendly Chains are obsolete! CoD4 includes a new way of moving your friendly AI which is very simple to setup, and infinitely more flexible. It's called Color Groups.

To use this:

In Radiant, make a trigger_multiple. then lay down a line of cover nodes where you want them. you dont have to connect the cover nodes to eachother. now select all the cover nodes and the trigger_multiple and press Shift + G.

A box will appear with 7 colors: red, orange, yellow, green, teal, blue, and purple.

Select a color for your group and click Add. just choose Red for now. then under that where it says Name: script_color_allies click OK.

You have just setup your very first color group! Keep repeating this step till you have your AI movement setup the way you want it.

Sounds alot like friendly chains, doesn't it? Why should you bother with this new way of moving your AI, you may ask... I'll tell you why!

Go back to your first group of color nodes that you made. Make a new line of cover nodes, but dont make a new trigger. Now select the new line of cover nodes and the first trigger_multiple that you made.

if you look at the Enities properties for the trigger, you will see it has a key/value pair of:


Now hold Shift and press G, and select Green for your color, then click Add, then click OK by the Name box. deselect everything, then select only the trigger. you will see in the Entities box that its key of script_color_allies now has a value of r0 g0.

what this does is when this trigger is triggered, it will send any AI with a script_forceColor value of "r" to the red color group and any AI with a script_forceColor value of "g" to the green color group.

you can effectively have two seperate squads of AI use this one trigger to go to two seperate areas in your map and take cover. or you could just have two seperate triggers, one red and one green do the same thing.

now to make this work, you have to assign these values to your AI in Radiant:

r (to use the red nodes)


g (to use the green nodes)

Or you can just grab a group of AI and assign them to a color group manually through script as explained below.

Lets take it another step:

Say you just assigned everyone to the red color group in Radiant to start off with, but there's a crossroads you want to split your squad at, and have the two seperate groups move independantly of eachother, now using both the red AND the green color groups.

In Radiant you will have to already have your cover nodes setup where you want them, assigned to the two seperate colors as described above. at the place you want to split the squad you can do this either way, assuming it took 12 movements to get to the crossroads:

  1. Have one trigger_multiple with a key of script_color_allies and a value of r12 g12
  2. Have two seperate triggers one with script_color_allies / r12 and one with script_color_allies / g12

Number 1 would be the easiest way to do it. you can also make it to where the trigger lays in a choke point that will definetly be triggered or you can just trigger it manually through script, the choice is yours.

Now at this point, all of your squad is still set to the red color group, even though you've just activated the green color group. so now you have to manually assign the guys you want to split off and get on the green group:

	// assuming you do it manually and have given the split point trigger a targetname of "split_squad"
	trigger = getEnt("split_squad", "targetname");
	trigger notify("trigger");

	// get all of your Allies in the squad
	guys = getAiArray("allies");

	// now split them up
	for(i = 0; i <= guys.size/2; i++)
		if(isAlive(guys[i])) // make sure the guy is still alive first!
			guys[i].script_forceColor = "g"; // set them to green

Now half of your AI will be set to red and continue on the red color group nodes, and the other half will start to follow the green color group nodes.

Just a little bit more info, then we're done!

Lets say the purpose of splitting the squad was to intentionally kill off a few of them. if you are using reinforcements, you will need to stop the AI's reinforcements BEFORE you kill them, otherwise their reinforcement will take their place after they are dead, and when that reinforcement dies, another reinforcement will take their place, and so on. so just before you would want to kill, say, the green guys, do this:

// you are now at this point in your level's script
guys = getAiArray("allies");

for(i = 0; i < guys.size; i++)
	if(isDefined(guys[i].script_forceColor) && guys.script_forceColor == "g")
		guys[i] disable_ai_color();
		guys[i] disable_replace_on_death();

	waittillframeend; // be sure he completes the functions

Now lets say you have an AI you placed in your level to do a vignette, like opening a gate or something. if you dont want to just kill this guy off, but would rather he join the squad on whatever color group you want, all you have to do is this, assuming you gave him a targetname of "gate_keeper":

guy = getEnt("gate_keeper", "targetname");

if(isSentient(guy)) // make sure you didnt grab the spawner instead of the guy
	guy enable_ai_color();
	guy.script_forceColor = "r"; // set them to red

be sure to include maps/_utilty.gsc to your script for all this to work. add this to the very top of your script:

#include maps\_utility;

To set up color group reinforcements, place a friendly AI in your map where you would want the reinforcements to spawn from. on this AI, check the Spawner and Undeleteable boxes. now make a trigger_multiple and give it a targetname of "friendly_respawn_trigger". do NOT check the trigger_spawn box! now connect the trigger to the spawner by first selecting the trigger then the AI spawner and pressing W. do NOT target more than one AI with this trigger or it won't work.

That's all there is to it. you can now copy the trigger and connected AI and paste it anywhere in the map you would want to be able to spawn in reinforcements.