- Joined
- May 12, 2018
- Messages
- 145
Is there a way to end or stop AI of eliminated CPU player? Infinite loop of functions such as TierConditionLoop-CampaignDefenderEx of annihilated player's AI seems to cause crashes on my map.
here's my code.
[/CODE]
www.hiveworkshop.com
I wrote this referred to Nowow's AI tutorial.
Hall's tiers are checked with the other triggers that detects halls destroyed, built, upgraded. and then send the command integer.
here's my code.
JASS:
globals
player MyVictim = Player(2) // This is the player 3
integer Tier = 3
constant integer UNIT_BLOODELF_WORKER = 'nhew'
constant integer UNIT_BLOODELF_FOOTMAN = 'hhes'
constant integer UNIT_BLOODELF_ARCHER = 'hhes'
constant integer UNIT_BLOODELF_GLAIVE = 'e000'
constant integer UNIT_BLOODELF_TROOPER = 'nbel'
constant integer UNIT_BLOODELF_PHOENIX = 'h009'
constant integer UNIT_BLOODELF_GOLEM = 'n02H'
constant integer UNIT_BLOODELF_PRIEST = 'hmpr'
constant integer UNIT_BLOODELF_SORCERESS = 'hsor'
constant integer UNIT_BLOODELF_BREAKER = 'h01R'
constant integer UNIT_BLOODELF_HAWKRIDER = 'h01S'
constant integer UNIT_BLOODELF_ASSAULT = 'nws1'
constant integer BUILD_BLOODELF_HALL1 = 'h001'
constant integer BUILD_BLOODELF_HALL2 = 'h002'
constant integer BUILD_BLOODELF_HALL3 = 'h003'
constant integer BUILD_BLOODELF_FARM = 'nefm'
constant integer BUILD_BLOODELF_BARRACKS = 'nheb'
constant integer BUILD_BLOODELF_LUMBERMILL = 'h00B'
constant integer BUILD_BLOODELF_BLACKSMITH = 'h015'
constant integer BUILD_BLOODELF_ALTAR = 'h016'
constant integer BUILD_BLOODELF_TOWER = 'negt'
constant integer BUILD_BLOODELF_TOWER_AG = 'negf'
constant integer BUILD_BLOODELF_TOWER_AA = 'negm'
constant integer BUILD_BLOODELF_SANCTUM = 'h601'
constant integer BUILD_BLOODELF_OBSERVATORY = 'haro'
constant integer BUILD_BLOODELF_SHOP = 'h01Q'
constant integer BUILD_BLOODELF_AVIARY = 'h01A'
constant integer HERO_BLOODELF_RANGER = 'Hjnd'
constant integer UPG_BLOODELF_PACK = 'R024'
constant integer UPG_BLOODELF_LUMBERING = 'Rhlh'
constant integer UPG_BLOODELF_ARMOR_STRUCTURE = 'R01G'
constant integer UPG_BLOODELF_WEAPON_MELEE = 'Rhme'
constant integer UPG_BLOODELF_WEAPON_MAGIC = 'R001'
constant integer UPG_BLOODELF_ARMOR_MELEE = 'Rhar'
constant integer UPG_BLOODELF_ARMOR_RANGE = 'Rhla'
constant integer UPG_BLOODELF_DEFEND = 'Rhde'
constant integer UPG_BLOODELF_ARCHER_RANGE = 'R003'
constant integer UPG_BLOODELF_GLAIVE_RANGE = 'R022'
constant integer UPG_BLOODELF_ARCHER_DAMAGE = 'R023'
constant integer UPG_BLOODELF_SENTRY = 'Rhse'
constant integer UPG_BLOODELF_BREAKER_CONTROL = 'Rhss'
constant integer UPG_BLOODELF_TRAIN_PRIEST = 'Rhpt'
constant integer UPG_BLOODELF_TRAIN_SORCERESS = 'Rhst'
constant integer UPG_BLOODELF_MAGICDEFEND = 'R01O'
constant integer UPG_BLOODELF_PHOENIX_LIFE = 'R01N'
constant integer UPG_BLOODELF_GOLEM_SILENCE = 'R01H'
constant integer UPG_BLOODELF_GOLEM_ARMOR = 'R02M'
constant integer UPG_BLOODELF_TRAIN_HAWK = 'R002'
constant integer UPG_BLOODELF_ANIMAL_LIFE = 'R01Y'
constant integer AID_RANGER_DISARM = 'A063'
constant integer AID_RANGER_FIRSTAID = 'A05W'
constant integer AID_RANGER_COMMANDAURA = 'A062'
constant integer AID_RANGER_FROSTARROW = 'ANfa'
endglobals
function CampaignDefenses takes nothing returns nothing
if Tier > -1 then
call CampaignDefenderEx( 4,4,4, UNIT_BLOODELF_FOOTMAN )
call CampaignDefenderEx( 3,3,3, UNIT_BLOODELF_ARCHER )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_GLAIVE )
if Tier > 1 then
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_SORCERESS )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_PRIEST )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_BREAKER )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_PHOENIX )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_TROOPER )
call CampaignDefenderEx( 2,2,2, UNIT_BLOODELF_HAWKRIDER )
endif
if Tier > 2 then
call CampaignDefenderEx( 4,4,4, UNIT_BLOODELF_ASSAULT )
call CampaignDefenderEx( 4,4,4, UNIT_BLOODELF_GOLEM )
endif
endif
endfunction
function BuildOrder takes nothing returns nothing
if Tier > -1 then
call SetBuildUnitEx( 1,1,1, UNIT_BLOODELF_WORKER)
if Tier >= 0 and Tier < 2 then
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_HALL1)
endif
call SetBuildUnitEx( 5,5,5, UNIT_BLOODELF_WORKER)
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_BARRACKS)
call SetBuildUnitEx( 2,2,2, BUILD_BLOODELF_FARM)
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_ALTAR)
call SetBuildUnitEx( 13,13,13, UNIT_BLOODELF_WORKER)
call SetBuildUnitEx( 5,5,5, BUILD_BLOODELF_FARM)
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_LUMBERMILL)
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_BLACKSMITH)
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_SHOP)
call SetBuildUnitEx( 9,9,9, BUILD_BLOODELF_FARM)
call SetBuildUnitEx( 2,2,2, BUILD_BLOODELF_BARRACKS)
if Tier == 1 then
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_HALL2)
endif
if Tier >= 2 then
call SetBuildUnitEx( 2,2,2, BUILD_BLOODELF_SANCTUM)
call SetBuildUnitEx( 2,2,2, BUILD_BLOODELF_OBSERVATORY)
call SetBuildUnitEx( 2,2,2, BUILD_BLOODELF_AVIARY)
endif
if Tier == 2 then
call SetBuildUnitEx( 1,1,1, BUILD_BLOODELF_HALL3)
endif
endif
endfunction
function ConfigureAI takes nothing returns nothing
call SetSlowChopping( false )
call SetPeonsRepair( true )
call SetHeroesTakeItems(false)
call SetHeroesBuyItems(true)
call SetTargetHeroes(false)
call SetUnitsFlee(false)
call SetHeroesFlee(false)
call SetGroupsFlee(false)
call SetSmartArtillery( true )
endfunction
function TierCondition takes nothing returns nothing
if CommandsWaiting() > 0 then
set Tier = GetLastCommand()
call PopLastCommand()
call InitBuildArray()
call InitDefenseGroup()
call BuildOrder()
call CampaignDefenses()
endif
endfunction
function ConditionLoop takes nothing returns nothing
call TierCondition()
call StaggerSleep(1,5)
loop
call TierCondition()
call Sleep(5)
endloop
endfunction
function main takes nothing returns nothing
call CampaignAI( BUILD_BLOODELF_FARM, null)
call ConfigureAI( )
call DoCampaignFarms(true)
call BuildOrder()
call CampaignDefenses()
set campaign_gold_peons = 5
set campaign_wood_peons = 8
call SetCaptainHome(DEFENSE_CAPTAIN,5418,4481)
call SetCaptainHome(ATTACK_CAPTAIN,5418,4481)
call StartThread(function ConditionLoop)
endfunction
[CODE=JASS]
Creating AI workflow
Or How I Learned to Stop Worrying and Read AI This tutorial serves one primary purpose: teaching you how to learn ai by yourself. In order to achieve that we'll go through two steps: First, we'll read through an ai script from one of blizzard's campaign maps and use it to understand how ai...

Hall's tiers are checked with the other triggers that detects halls destroyed, built, upgraded. and then send the command integer.