Staredit Network > Forums > Modding Discussion > Topic: Defining AI commands and functions
Defining AI commands and functions
Jun 21 2017, 8:49 pm
By: Pr0nogo
Pages: < 1 2 3

Jul 23 2017, 9:14 am Neiv Post #41

You place it after attack_add, so it will multiply the attack force you've already defined.


Aug 11 2017, 1:54 pm Nekron Post #42

Edit: Last 3 commands

wait_secure - Either does nothing (it's honestly hard to tell since the way to test it seems to be running a multirun that builds defense structures) or waits until all (?) regions are defended with static defense structures. Works for all races. Ignores build_bunkers/turrets execution if it's being run while there are already enough defences, so I figure it's unrelated.

implode - Seems to act as "placeguard_clear" - guard units aren't being rebuilt after calling it. Might be wrong, as this was the result I was expecting, so I'm really biased.

region_size (byte) (block) -
Jump to block %2 if the map's region tile count is below 32 times %1. Can be used to check for map size.

Post has been edited 2 time(s), last time on Aug 23 2017, 4:33 pm by Nekron.

Aug 23 2017, 11:06 pm Pr0nogo Post #43

Updated the OP with a link to Nekron's documentation for AI commands in google doc form. Also updated the collapsable boxes with some additional info, but refer to the google doc for more in-depth and complete information.

Does `expand` get delayed by other loops/commands, or does the number value that comes after it relate to priority as opposed to number of towns?

In this script, the zerg AI is given the following orders in a multirun:

allies_watch(2, TB5D 0011)
try_townpoint(1, TB5D 0009)

Shortly afterwards, this occurs in the main script (not a multirun):

try_townpoint(1, TB5D 0010)
expand(1, TB5D 0011)
goto(TB5D 0012)

0010 leads to the following:

expand(2, TB5D 0011)

This is 0011 (the block called by all these expand/allies_watch functions):

build(1, Zerg Hatchery, 80)
wait_build(1, Zerg Hatchery)

However, only the allies_watch code seems to function properly. Expand(1; 2; 3; etc) don't do anything. Expand(99, 0011) works properly to make the AI expand several times. Is this a syntax error or is something else in the code the culprit?

Post has been edited 1 time(s), last time on Aug 23 2017, 11:57 pm by Pr0nogo.

Aug 24 2017, 6:28 pm Pandut Post #44

Wow, these are great. Thank you so much for the doc, I've always wanted to get back into AI scripting haha. Awesome that you're making a reference for script terms :).

Also dumb question here, how does one actually get an AIscript to work with SCR? Do I drop it in the patch_rt file or?


Aug 24 2017, 6:52 pm Nekron Post #45

Yes, you can use them with SCR, and since Blizz never bothered touching them they're still in patch_rt. The Blizzard app scans your gamefiles after every time you close the game, so you'd need to make a .bat file or w/e for this to be convenient at all (if you won't swap files/change names somehow immediately after the process closes, your changed patch_rt will get deleted). Maybe you can avoid this by launching SC with the -launch parameter, but I haven't gotten around to testing this yet
Edit: Launch the Starcraft.exe through a shortcut with the parameter -launch, and you can avoid using the Blizz client for a month - and thus, rechecking files. You have to log in once a month to prove to Blizz you still have an internet connection or something, idk, or else you lose RM graphics until you re-log.

Post has been edited 1 time(s), last time on Aug 24 2017, 8:25 pm by Nekron.

Aug 29 2017, 11:55 pm Pandut Post #46

Yarr, that did it. Been fiddling around with AI scripts all day now, thanks! :)


Sep 24 2017, 10:10 am Nekron Post #47

Last two missing commands added to the doc, courtesy of Neiv

implode (takes no parameter) -
Quote from Neiv
Implode changes the state of ai regions: Any region which has state 0,1,2 or 3, and at least two of its neighbouring regions also have state < 4, the regions state is changed to 4. (So depending which regions are checked first the regions which change to 4 differ)

(more or less accurate list of region states)
0x0 Nothing,
0x1 = Attack?,
0x2 = Attacking,
0x3 = Town under attack and can't defend? Or just enemy seen there, Can't repair,
0x4 = Near main building? Future town?,
0x5 = Town? Also with Value area higher script,
0x6 = Defending,
0x7 = Chase away?,
0x8 = Moving to attack?,
0x9 = Moving to attack 2?

After some testing, it's hard to really find any uses for this one. It's basically something somewhat similar to capt_expand, but it's more "aggressive", while also being way more inconsistent

wait_secure (takes no parameter)-
Quote from Neiv
wait_secure seems to have the script wait until AI trains defense, but it's a global thing so it may be difficult to use. And if the AI doesn't have to train defense, the script seems to hang? Maybe it's meant to use in a child thread which starts to do something once there's a reason to train def?
Seems completely useless, the condition's either inconsistent or really easy to achieve, so it basically always forwards the script execution seamlessly. And if it doesn't, it will probably hang your script xD

Sep 26 2017, 1:52 am Heinermann Post #48

SDE, BWAPI owner, hacker.

Where did I write that post? Was it on the BroodwarAI forum?

Sep 26 2017, 6:59 am Nekron Post #49

Nope, it were the StarcraftAI forums.
BroodwarAI forums were down already when I started looking for more commands, I think 5? or 4 years ago

Oct 2 2017, 5:47 pm Pandut Post #50

How does region_size work? Like, example-wise. Mostly, I'd like to include a script in my AI code that's jumped to when the map size is 64x64/96x96/small. Don't know how it works, tho.


Oct 2 2017, 7:16 pm Nekron Post #51

Edit: See post below

Post has been edited 1 time(s), last time on Oct 3 2017, 5:58 pm by Nekron.

Oct 3 2017, 4:33 am Heinermann Post #52

SDE, BWAPI owner, hacker.

Here's region_size:

Basically, if the walkable tiles for all the town's pathable areas is below 32*value, it jumps to block.

Some use cases:
- Determine the rough size of the map. Larger value means you may need to execute a more long distance strategy.
- Determine the size of an island that an expansion is on. If it is a small island, there may be certain structures you don't want to build.

Also, groundmap_jump will check if any opponent structure is accessible from where the script was run. You can call it multiple times, for example to determine whether the player has lifted and moved to an island.

region_size can also be used to determine if you're on an island, and may be preferable in some cases because it is town-based, and groundmap is script-based.

Quote from Neiv
- `allies_watch`. The first argument is a index of the base location (I don't think there are any tools to determine the index), and second is a script position. If the base location has resources remaining, *something* happens.
Looks like it expands (calls AI_ExpandAt), using the block for the new expansion.

I'm not sure what it does *takes a look*. So it isn't really useful. The only values assigned to it are:
0 = AI script town was not started
1 = AI town was started (start_town or start_areatown)

It gets compared to 2 somewhere in the code but it doesn't actually get set to 2 anywhere.

If the if_diff value is 0, meaning the AI script town was not started, then it calls AttackAdd with %1 count of %2 unit.

Post has been edited 2 time(s), last time on Oct 3 2017, 6:18 am by Heinermann.

Oct 21 2017, 1:45 pm Nekron Post #53

A few requests/questions if anybody would have the time to answer them:

Normal priority:
- a clarification of clear_combatdata's function - does it only remove units from attacks, or maybe it doesn't even do that? Are the units properly reutilised if it does?
- accurate description of wait_secure's condition - obviously pretty relevant if the command were to ever be used, since without an accurate description it's hard to predict when will the script continue
- does check_transports literally only affect the number of transports the AI keeps around? Mostly asked because I've seen it used in zerg-only scripts

Low priority:
- confirmation whether harass_location has no actual in-game functions, not even obscure
- double check to see whether wait_bunkers and wait_turrets do in fact wait for build_bunkers/turrets to end, and do nothing more both commands do nothing
- a confirmation of capt_expand's functions: since every bit of knowledge on it is currently based solely on in-game observations.
List of presumed functions (for campaign scripts) right now:
* If default_min is greater than 0: Keeps first defensebuild_gg and _aa units as guards (?) in locations along the edges of defended regions
* Expands the area it defends, more with every next use of capt_expand
* Enables the usage of defensebuild_ga and defenseuse_ga commands
usage confirmed and mostly documented

Really low priority:
- a confirmation whether target_expansion flag has no effects on campaign scripts (used by Blizz in a campaign script once) (presumably requires going through attack logic?) long testing did not show any attack-related changes
- a check to see when exactly does panic crash the game: seems to happen most often when empty (start locations sans resources) resareas exist on the map
- accurate list of things affected by set_randomseed (since they supposedly do exist) randomseeds seem to not work properly outside of replays?
- a description of default_min force distribution (clearly not actually (byte) per every region, ignores some regions) and an exact description of AI's defense mechanism, including special cases (such as the 700-800 max_force regions in the town center) researched and documented in the doc
- why was kill_thread supposed to "never by used" according to old SCAI threads? does it cause any performance hits/crashes? can cause request log issues, needs more testing

Post has been edited 2 time(s), last time on Nov 5 2017, 2:56 pm by Nekron.

Oct 30 2017, 10:35 pm Pandut Post #54

Honestly, in all instances I've used wait_turrets/bunkers, I've never seen the AI wait. I usually just have to put in a wait(whatevertime) and just go from there. Maybe it has function in Campaign scripts, but certainly not Skirmish scripts.


Oct 31 2017, 11:39 am Nekron Post #55

Yeah, it could be the case. I can't decompile commands myself, so I can't really tell whether something has a start_campaign caveat: Also, I don't think I've tested these too accurately, to be honest D:

Otherwise, I added lots of new info to the doc that can probably be of use to you, especially the region stuff.

I tried writing two melee scripts recently, and my biggest problem seems to be that it's hard to make a non-linear script that doesn't get absolutely retarded because of requests: I frequently end up with 60 + unit requests to fill which murders the AI completely :I Also being limited to 21->12 workers/base on Fighting Spirit (12 after expanding) is pretty annoying

Pages: < 1 2 3
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[08:14 am]
KrayZee -- I don't get it. When a video game is unreasonably criticized harshly, I have fun playing those games. When a game is overhyped, I can't enjoy it for some reason. Bah.
[07:25 am]
NudeRaider -- Vrael
Vrael shouted: lil-Inferno lil-Inferno don't worry I'll probably finish before Starcraft 6
"probably" :lol:
[03:00 am]
RIVE -- xd
[02:35 am]
O)FaRTy1billion[MM] -- xd
[02:33 am]
Moose -- xd
[01:40 am]
lil-Inferno -- xd
[10:42 pm]
RdeRenato -- xd
[09:50 pm]
zsnakezz -- KrayZee
KrayZee shouted: Although I refuse to acknowledge the posts I made is mine.
i can relate
[09:49 pm]
zsnakezz -- double mmm with a twist
[09:48 pm]
zsnakezz -- mmm
Please log in to shout.

Members Online: Roy, jun3hong, Pascorell