• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[AI] PLZ PLZ PLZ need help with AI script

Status
Not open for further replies.
Level 1
Joined
Jun 19, 2004
Messages
3
I need some help with my AI script. As for a start I won't be creating anything special. I just need some answers.

I have this script:

Code:
//===========================================================================
//  The Human Alliance (player 10) -- AI Script
//===========================================================================
globals
endglobals

//===========================================================================
//  main
//===========================================================================
function main takes nothing returns nothing
	
	call CampaignAI(HOUSE,null)
	call SetReplacements(0,4,0)

	call CampaignDefenderEx( 0,5,0, RIFLEMAN )
	call CampaignDefenderEx( 0,3,0, FOOTMAN   )
	call CampaignDefenderEx( 0,3,0, KNIGHT )

    loop
	call Sleep( 2.5 )
	call ClearHarvestAI()
	call HarvestGold( 0, 5 )
	call HarvestWood( 0, 3 )
    endloop
endfunction

I don't want the AI do anything, just always keep 5 peasants harvesting gold (1), 3 lumber (2) and replace them if someone kills them (3) plus always have the mentioned campaign defenders (replace them if anyone kills them as well (4)). But the AI messes around, builds tons of farms etc. and that's not in the AI script. How do I make it so that AI does only w(1), (2), (3) and (4)?

thx.[/code]
 
Level 6
Joined
Jun 16, 2004
Messages
237
Have you removed the standard Melee - Start AI scripts for computer players? It might be the reason for the strange AI behavior.

About your script: I don't see your building queue anywhere. CampaignDefendersEx only sets the defense group and isn't really needed if you don't use an attack group. Wouldn't it be really easy to do an AI script you want by using the AI editor? Or don't you have TFT?

Also, place the original guard units in the place where you want them to guard, and the computer fills the guard positions automatically.
 
Level 1
Joined
Jun 19, 2004
Messages
3
Yes, the standard melee AI scripts are removed. Here's the exact situation:

There are 6 peasants when the script is launched. I want the AI build 3 more peasants so that there are 9 in total than send 5 to harvest gold and 3 to harvest lumber and leave one under my command ( I use AI - Ignore unit's guard position for this). And I suppose when a peasant is killed, it will always be replaced. How do I do this? What Build commands are needed?

Thanks.
 
Level 6
Joined
Jun 16, 2004
Messages
237
Add code lines like the ones below to appropriate sections of your code (e.g. local variable declarations to the start, etc.):

Code:
local integer goldpeasants = 0
local integer woodpeasants = 0

call InitBuildArray(  )
call SetBuildAll( BUILD_UNIT, 9, PEASANT, -1 )
call SetBuildAll( BUILD_UNIT, 5, RIFLEMAN, -1 )
call SetBuildAll( BUILD_UNIT, 3, KNIGHT, -1 )
call SetBuildAll( BUILD_UNIT, 3, FOOTMAN, -1 )

loop
  set goldpeasants = GetUnitCountDone(PEASANT)-1

  if goldpeasants < 0 then
    set goldpeasants = 0
  elseif goldpeasants > 5 then
    set goldpeasants = 5
  endif

  set woodpeasants = GetUnitCountDone(PEASANT)-6
  if woodpeasants < 0 then
    set woodpeasants = 0
  elseif woodpeasants > 3 then
    set woodpeasants = 3
  endif

  call HarvestGold( TownWithMine(), goldpeasants)
  call HarvestWood( 0, woodpeasants )
  call Sleep(2)
endloop

I haven't checked the syntax, but I think it's ok! You need to add buildings (e.g. barracks) to the building prioirities list too, if you want them to be rebuilt. You should put troop production buildings on the list before appropriate troops.

Hope this gets you started! :)

Cheers,

Tommi
 
Level 1
Joined
Jun 19, 2004
Messages
3
Yay! It works! Thanks!!! I owe you one.
But there are some important questions that have risen. How exactly does SetBuildAll work? Is it the same SetProduce? Or does it show how many units the player should have AFTER CONSTRUCTION, that is if the player already has those units, do not build more?
 
Level 6
Joined
Jun 16, 2004
Messages
237
Yes. The computer first builds 9 peasants, then 5 riflemen, then 3 knights, and then 3 footmen. They also will be rebuild in this order if they are destroyed. You might want to interlace these units. I wrote this as a brief example.

All these functions are found in common.ai.

I rechecked CampaignDefendersEx and it indeed does build units, unlike what I said before. I think it does the same as SetBuildAll, but also adds the units to the defense group (which essentially does nothing here).

The parameters in SetBuildAll are unit/upgrade (use BUILD_UNIT for units and buildings and BUILD_UPGRADE for upgrades), quantity, unit id, and town (-1 is any town).
 
Level 1
Joined
Jun 6, 2005
Messages
3
I've been reading your AI script and it seems you're missing a code statement:

You script:

//===========================================================================
// The Human Alliance (player 10) -- AI Script
//===========================================================================
globals
endglobals

//===========================================================================
// main
//===========================================================================
function main takes nothing returns nothing

call CampaignAI(HOUSE,null)
call SetReplacements(0,4,0)

call CampaignDefenderEx( 0,5,0, RIFLEMAN )
call CampaignDefenderEx( 0,3,0, FOOTMAN )
call CampaignDefenderEx( 0,3,0, KNIGHT )

loop
call Sleep( 2.5 )
call ClearHarvestAI()
call HarvestGold( 0, 5 )
call HarvestWood( 0, 3 )
endloop
endfunction

Just add "set do_campaign_farms = false" in the main function anywhere and your AI won't build any more farms !
 
Level 2
Joined
Sep 4, 2004
Messages
30
The script you wrote isn't bad but the CampaignAI
function is a very SPECIAL one, that makes creating
a campaign AI easier.
It does all the build queue and harvesting for you.
You only need to set the corresponding variables.
So:

set campaign_gold_peons = 5
set campaign_wood_peons = 3

The default values are actualy also 5 and 3, so you
don't even have to set anything.
Your loop has to be empty except the Sleep function.

The peasants build houses to have enough food,
this is automatical as well because of the
CampaignAI function.

A bit too late but hope helps someone at least :)
 
Status
Not open for further replies.
Top