Kitti
  • Kitti
  • 51.5% (Neutral)
  • Private Topic Starter
17 years ago
็Hi, all.

I'm a newbie here.

I had modify a map from official map (China Tank General). There are airfield and war factory I placed.I have build a team already, and use some scripts. AI had create a team as I wish, but they're stand still. I had try other script to make them move or attack other. So I think I must something basically.

So this is my question

1. How will I make AI attack others?
2. How will AI build unit or team continuously?

Thank for any suggestion in advance.
Sponsor
Phe0n1x
  • Phe0n1x
  • 100% (Exalted)
  • Administrator
17 years ago
Please take a look at C&C Generals: Zero Hour: World Builder: Basic Tutorial  it may help.

What you are specifically asking is how to script the AI. That can be found at the bottom of the previous linked tutorial (Adding Players to the Map & Setting up the Computer AI ). Don't forget to add skirmish players to your map as well.


UserPostedImage
Drummin
17 years ago
Yes as PheNo1x said, the basic steps in making a map would be to add the skirmish player's and make the base layout with areas and pathways. If you've done this and haven't added any new scripts to the player folders, the map and AI should work fine.

If you're wishing to do more than this, as in having the AI build custom teams that move along a pathway and attack the enemy etc, there is much more to do.

*First you would need to load AI scripts into your map. I can't upload a copy here but there are copies elswhere in this forum.
Here's a link to a Zero Hour copy. [url="http://www.cncgeneralsworld.com/public/files/Drummin/AI_Scripts.zip"]ZH AI Scripts[/url]

After you've imported these default AI scripts you can script many things for the AI player. Keep in mind that this type of scripting would need to be done in all AI folders and all team names would need to be unique. Also depending on what you wish to do you would probably need to make copies for each start location.

There are many ways to script this. I'll give you a sample.

Make a condition script that would active the creation script.

*Script Name: StartDefenderP1
The settings for this script would be [ns A D].

*** IF ***
Player '' starting position is 1 .
Player '' has Greater Than or Equal To 1 unit or structure of type 'Barracks'
*** THEN ***
Enable Script 'P1CreateDefender'.
Add 1 to counter 'P1DefenderCount'
Enable Script 'P1CheckDefenderCount'.

NOTE: You would need to import the "Set Object List" scripts if you want to use a generic term like 'Barracks' in your scripts. Otherwise you would need to change this generic term to a specific building for each faction.


The next script will check the defender count and reactivate the first script.

*Script Name: P1CheckDefenderCount
The settings for this script would be [ns na D].

*** IF ***
Counter 'P1DefenderCount' IS Less Than 5
*** THEN ***
Enable Script 'StartDefenderP1'.

So now we have a pinging action between these two scripts that would stop when the count has reached the number set in the second script.

***
The following scripts will create your units and control their actions. All these scripts will be subroutines.

The first subroutine script is the trigger script that creates the unit.

*Script Name: P1CreateDefender
The settings for this script would be [S na D].

*** IF ***
True.
*** THEN ***
Null operation. (Does nothing.)

The next script is the pathway script that tells the team to follow it when they're created.

*Script Name: P1DefenderPath
The settings for this script would be [S A nd].

*** IF ***
True.
*** THEN ***
Have Team '' wander along Waypoint Path 'P1DefenderPath'

Note:
Because you don't know where and the AI will build their Barracks, just start your path inside the innerperimeter and lay out your pathway. I'd suggest making a zig-zag path just inside the combat zone. If you make the pathway double-back on itself the unit movement will look more random. IMPORTANT: Make a loop by working your way back to the beginning of your pathway and making a connection. This way units will go around again.

The next script is the hunting script that tells the team to attack if they see the enemy.

*Script Name: P1DefenderHunt
The settings for this script would be [S A nd].

*** IF ***
True.
*** THEN ***
Team '' begins hunting.

You could change this script to whatever works best for you. Have your team defend an Area etc.

We need one more script to modify the defender count if a unit is lost.

*Script Name: P1SubtractDefenderCount
The settings for this script would be [S A nd].

*** IF ***
True.
*** THEN ***
Subtract 1 from counter 'P1DefenderCount'

That's it on the scripts for player one. Now, if you put all these scripts in a folder you can then export this single folder and import it back into each AI folder. Before you do the export though, you might want to copy each script and change the "P1" to "P2" for player's starting in start location two etc. Be sure to also modify lines within each script accordingly.

***
The last thing to do is make the teams.
Go to Edit/Edit Teams...
You should see a long list of teams for each faction.

Start with USA and create a new team. Remember that all names need to be unique so I'd use the faction name and position identifier we used in the scripts. For example, we'd have names like,
USA P1Defender
USA P2Defender
Etc.

I'd set the Maximum Quantity to say 100 and the Priority to 500.
In the Production condition area, select the creation subroutine script you made (P1CreateDefender). Select your unit type and make one unit at a time. Let the second script you made determin the number or size of the team.

At the top of this window you'll see a number of tabs, select the Behavior tab. Here is where you set each of the other subroutine scripts you made.

On Create: P1DefenderPath

Enemy Spotted: P1DefenderHunt
All Clear: P1DefenderPath

Idle: P1DefenderPath

Unit Lost: P1SubtractDefenderCount

That should do it for position one. Copy this team and modify the name and scripts for each.
***
I'm sure some of you would do things differently but I've used these script combinations before and it has worked fine. The only thing I did different on my map was also add a timer delay of 5 seconds between activating the create script so units would be more spaced apart.
Kitti
  • Kitti
  • 51.5% (Neutral)
  • Private Topic Starter
17 years ago
Thank you for all of your reply. Espeacially Drummin.

It is my mistake. I should tell here earlier that I had succeed skirmish map making. My problem is try my new custom map and have problem as above.So I think I will read more WB tutorial carefully.

Anyway, Thank again for Drummin's reply is obvious answer. I just clear in mind that I have to do more complex scripts. I will try to learn more.

For now, I had a new question in my head.

Can we put skirmish player and custom player (AI controlled)?

If it's possible, I think can do something with it more.