【觸發】一鍵移植通用版-電腦英雄自動施放技能
感謝小伙伴“月夜星歌”的分享!
這個系統使得電腦的英雄能夠自動集火敵方英雄并且先手施放技能,適合絕大部分地圖
一鍵移植,用法極其方便,只需直接復制這個觸發到地圖即可,無需修改
支持包括通魔在內的幾乎所有的英雄技能模板
對于自定義通魔技能的話,將基礎命令ID改成常用的英雄技能模板的命令就可以了,例如風暴之錘(單體目標)、戰爭踐踏(無目標)、烈焰風暴(點目標)


觸發腳本如下:
//==================================================================
//電腦英雄自動施放技能系統V1.3 BY 金皮蛋
//使得電腦英雄能夠自動對附近的敵方英雄集火并且使用技能
//支持包括通魔在內的絕大部分英雄技能模板
//一鍵移植,用法極其方便
//==================================================================
library GoldenEggAISettings
globals
public real Range = 1600//AI進攻范圍
public real Ratio = 1//AI技能施放范圍系數
public boolean Lock = true//true為鎖定血量最少的目標,false為不鎖定
public boolean OnlyHero = true//true為只對英雄有效,false為對所有單位有效
public boolean CreepAI = false//true為對野怪玩家有效,false為對野怪玩家無效
public boolean HumanAI = false//true為對人類玩家有效,false為對人類玩家無效
endglobals
endlibrary
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
library HeroSpellSystemAI initializer Init needs GoldenEggAISettings
globals
private integer Top = 0
private boolean AB = false
private unit array Hero
private unit array Htu
private real array Htx
private real array Hty
private integer array LastOI
private integer array OT
private integer array TYPE
private boolean array GUARD
private timer array HT
private group AG = null
private region RR = null
private trigger TE = null
private real Range = 1600
private real Ratio = 1.
private boolean OnlyHero = true
private boolean CreepAI = false
private boolean HumanAI = false
private boolean Lock = true
endglobals
private function DistanceBetweenUnits takes unit u1, unit u2 returns real
return SquareRoot(( GetUnitX(u1)-GetUnitX(u2))*(GetUnitX(u1)-GetUnitX(u2))+(GetUnitY(u1)-GetUnitY(u2))*(GetUnitY(u1)-GetUnitY(u2)))
endfunction
private function IsPlayerComputer takes player p returns boolean
if GetPlayerController(p)==MAP_CONTROL_COMPUTER /*
*/or (GetPlayerController(p)==MAP_CONTROL_USER and HumanAI) /*
*/or (GetPlayerController(p)==MAP_CONTROL_CREEP and CreepAI) then
return true
endif
return false
endfunction
private function IsUnitUseAI takes unit u returns boolean
if IsUnitType(u,UNIT_TYPE_HERO) or OnlyHero==false then
return true
endif
return false
endfunction
private function IsUnitVisibleToEnemy takes unit u returns boolean
local integer i = 0
loop
if IsUnitVisible(u,Player(i)) and IsUnitEnemy(u,Player(i)) then
return true
endif
set i = i + 1
exitwhen i > 15
endloop
return false
endfunction
private function GetHeroId takes unit u returns integer
local integer i = 1
loop
exitwhen i > Top
if u==Hero[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetTimerId takes timer t returns integer
local integer i = 1
loop
exitwhen i > Top
if t==HT[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function IsFree takes integer OI returns boolean
if OI==0 or OI==851972 or OI==851983 or OI == 852128 then
return true
endif
return false
endfunction
private function IS takes unit AU returns boolean
local integer OI = GetUnitCurrentOrder(AU)
if OI == 0/*
*/or OI == 851972/*
*/or OI == 851993/*
*/or OI == 851983/*
*/or OI == 851984/*
*/or OI == 851988/*
*/or OI == 851990/*
*/or OI == 851983/*
*/or OI == 851985/*
*/or OI == 851986/*
*/or OI == 851988/*
*/or OI == 851990/*
*/or OI == 999999 then
return true
endif
return false
endfunction
private function IC takes unit u, integer i returns boolean
if AB==false and GetUnitCurrentOrder(u)!=i and i!=LastOI[GetHeroId(u)] then
return true
endif
return false
endfunction
private function SD takes unit u, integer i returns nothing
local integer id = GetHeroId(u)
set AB = true
set LastOI[id] = i
set OT[id] = 5
endfunction
private function IO takes unit AU, integer AI returns nothing
if IC(AU,AI) then
if IssueImmediateOrderById( AU, AI ) then
call SD(AU,AI)
endif
endif
endfunction
private function IL takes unit AU, integer AI, real x, real y returns nothing
if IC(AU,AI) then
if IssuePointOrderById( AU, AI ,x ,y ) then
call SD(AU,AI)
endif
endif
endfunction
private function IU takes unit AU, integer AI, unit AT returns nothing
if IC(AU,AI) then
if IssueTargetOrderById( AU, AI , AT ) then
call SD(AU,AI)
endif
endif
endfunction
private function SO1 takes unit AU, real R returns nothing//無目標
local real H = GetUnitLifePercent(AU)
call IO( AU, 852129 )
if R<=800*Ratio then
call IO( AU, 852097 )
call IO( AU, 852489 )
call IO( AU, 852126 )
call IO( AU, 852503 )
call IO( AU, 852100 )
call IO( AU, 852528 )
call IO( AU, 852184 )
call IO( AU, 852164 )
call IO( AU, 852180 )
call IO( AU, 852554 )
call IO( AU, 852200 )
call IO( AU, 852594 )
call IO( AU, 852595 )
call IO( AU, 852596 )
call IO( AU, 852667 )
call IO( AU, 852663 )
call IO( AU, 852598 )
call IO( AU, 852599 )
call IO( AU, 852600 )
if H<=50. then
call IO( AU, 852586 )
endif
endif
if R<=400*Ratio then
call IO( AU, 852096 )
call IO( AU, 852086 )
call IO( AU, 852090 )
call IO( AU, 852094 )
call IO( AU, 852127 )
call IO( AU, 852128 )
call IO( AU, 852526 )
call IO( AU, 852181 )
call IO( AU, 852183 )
call IO( AU, 852556 )
call IO( AU, 852217 )
call IO( AU, 852588 )
call IO( AU, 852253 )
call IO( AU, 852246 )
endif
if R<=100*Ratio then
call IO( AU, 852123 )
endif
//激活
call IO( AU, 852174 )
call IO( AU, 852552 )
call IO( AU, 852458 )
call IO( AU, 852656 )
call IO( AU, 852589 )
call IO( AU, 852244 )
call IO( AU, 852578 )
call IO( AU, 852671 )
call IO( AU, 852244 )
call IO( AU, 852602 )
call IO( AU, 852212 )
call IO( AU, 852522 )
call IO( AU, 852150 )
call IO( AU, 852133 )
call IO( AU, 852102 )
call IO( AU, 852249 )
if R<=200*Ratio then
call IO( AU, 852177 )
endif
endfunction
private function SO2 takes unit AU, real x, real y, real R returns nothing//點目標
if R>1200 then
call IL( AU, 852093, x, y )
endif
call IL( AU, 852089, x, y )
call IL( AU, 852488, x, y )
call IL( AU, 852121, x, y )
call IL( AU, 852504, x, y )
call IL( AU, 852125, x, y )
call IL( AU, 852555, x, y )
call IL( AU, 852218, x, y )
call IL( AU, 852224, x, y )
call IL( AU, 852221, x, y )
call IL( AU, 852593, x, y )
call IL( AU, 852592, x, y )
call IL( AU, 852597, x, y )
call IL( AU, 852580, x, y )
call IL( AU, 852238, x, y )
call IL( AU, 852652, x, y )
call IL( AU, 852658, x, y )
call IL( AU, 852669, x, y )
call IL( AU, 852229, x, y )
call IL( AU, 852237, x, y )
call IL( AU, 852560, x, y )
call IL( AU, 852591, x, y )
call IL( AU, 852238, x, y )
if R>800 then
call IL( AU, 852122, x, y )
endif
if R>400 then
call IL( AU, 852525, x, y )
endif
if R<200*Ratio then
call IL( AU, 852664, x, y )
endif
call IL( AU, 852600, x, y )
endfunction
private function SO3 takes unit AU, unit AT, boolean Ally returns nothing//單位目標
// 敵
//if Ally == false then
call IU( AU, 852095, AT )
call IU( AU, 852119, AT )
call IU( AU, 852502, AT )
call IU( AU, 852179, AT )
call IU( AU, 852171, AT )
call IU( AU, 852527, AT )
call IU( AU, 852555, AT )
call IU( AU, 852227, AT )
call IU( AU, 852226, AT )
call IU( AU, 852587, AT )
call IU( AU, 852585, AT )
call IU( AU, 852583, AT )
call IU( AU, 852662, AT )
call IU( AU, 852665, AT )
call IU( AU, 852668, AT )
call IU( AU, 852670, AT )
call IU( AU, 852230, AT )
call IU( AU, 852480, AT )
call IU( AU, 852106, AT )
call IU( AU, 852487, AT )
call IU( AU, 852487, AT )
call IU( AU, 852243, AT )
call IU( AU, 852560, AT )
call IU( AU, 852231, AT )
call IU( AU, 852252, AT )
//else
// 友
call IU( AU, 852501, AT )
call IU( AU, 852225, AT )
//endif
// 任意
call IU( AU, 852092, AT )
call IU( AU, 852222, AT )
call IU( AU, 852274, AT )
call IU( AU, 852600, AT )
endfunction
private function HeroSpell takes integer id returns nothing
local unit hero = Hero[id]
local real r = DistanceBetweenUnits(hero,Htu[id])
if IS(hero) and IsUnitVisibleToEnemy(hero) then
set AB = false
if TYPE[id] == 1 then
call SO3(hero,Htu[id],false)
elseif TYPE[id] == 2 then
call SO2(hero,Htx[id],Hty[id],r)
elseif TYPE[id] == 3 then
call SO1(hero,r)
endif
endif
set hero = null
endfunction
private function GetTargetHero takes integer id returns nothing
local unit u = null
local unit WT = null
local unit hero = Hero[id]
local real HPmin = 10000000000.
local real Dismin = 10000000000.
local real HP = 0.
local real Dis = 0.
local real x = GetUnitX(hero)
local real y = GetUnitY(hero)
local group G = CreateGroup()
local player p = GetOwningPlayer(hero)
local integer OI = GetUnitCurrentOrder(hero)
call GroupEnumUnitsInRange(G,x,y,Range,null)
loop
set u = FirstOfGroup(G)
if IsUnitUseAI(u) then
set HP = GetUnitState(u,UNIT_STATE_LIFE)
if HP > 0. and IsUnitEnemy(u,p) then
if Lock == false then
set Dis = DistanceBetweenUnits(hero,u)
if Dis < Dismin then
set Dismin = Dis
set WT = u
endif
else
if HP < HPmin then
set HPmin = HP
set WT = u
endif
endif
endif
endif
call GroupRemoveUnit(G,u)
exitwhen u==null
endloop
call GroupClear(G)
call DestroyGroup(G)
if WT != null then
set Htu[id] = WT
set Htx[id] = GetUnitX(WT)
set Hty[id] = GetUnitY(WT)
if IsFree(OI) then
if not IssueTargetOrderById( hero, 851983, WT ) or TYPE[id]!=1 then
call IssuePointOrderById( hero, 851983, Htx[id], Hty[id] )
endif
endif
call HeroSpell(id)
endif
set u = null
set WT = null
set hero = null
set p = null
set G = null
endfunction
private function SetGuardPosition takes integer id returns nothing
if IsUnitVisibleToEnemy(Hero[id]) then
if GUARD[id] == false then
call RecycleGuardPosition(Hero[id])
endif
set GUARD[id] = true
else
if GUARD[id] == true then
call RemoveGuardPosition(Hero[id])
endif
set GUARD[id] = false
endif
endfunction
private function TimerLoop takes nothing returns nothing
local integer id = GetTimerId(GetExpiredTimer())
if IsUnitType(Hero[id],UNIT_TYPE_HERO)==false and GetUnitState(Hero[id],UNIT_STATE_LIFE)<=0 then
call DestroyTimer(HT[id])
call GroupRemoveUnit(AG,Hero[id])
set Hero[id] = Hero[Top]
set HT[id] = HT[Top]
set OT[id] = OT[Top]
set TYPE[id] = TYPE[Top]
set GUARD[id] = GUARD[Top]
set Hero[Top] = null
set Top = Top - 1
else
if OT[id] > 0 then
set OT[id] = OT[id] - 1
else
set LastOI[id] = 0
endif
set TYPE[id] = TYPE[id] + 1
if TYPE[id] > 3 then
set TYPE[id] = 0
endif
call SetGuardPosition(id)
call GetTargetHero(id)
endif
endfunction
private function HC takes unit u returns boolean
if IsUnitUseAI(u) /*
*/and IsUnitIllusion(u)==false /*
*/and IsUnitInGroup(u,AG)==false /*
*/and GetUnitAbilityLevel(u,'Aloc')==0/*
*/and IsUnitType(u,UNIT_TYPE_PEON)==false /*
*/and IsUnitType(u,UNIT_TYPE_STRUCTURE)==false /*
*/and IsPlayerComputer(GetOwningPlayer(u)) then
call GroupAddUnit(AG,u)
return true
endif
return false
endfunction
private function Reg takes unit u returns nothing
set Top = Top + 1
set Hero[Top] = u
set HT[Top] = CreateTimer()
set OT[Top] = 0
set TYPE[Top] = 0
set GUARD[Top] = true
call TimerStart(HT[Top],1.11,true,function TimerLoop)
endfunction
private function Trg01 takes nothing returns nothing
local unit u = GetTriggerUnit()
if HC(u) then
call Reg(u)
endif
set u = null
endfunction
private function Init takes nothing returns nothing
local unit u = null
local group g = CreateGroup()
set Range = GoldenEggAISettings_Range
set Ratio = GoldenEggAISettings_Ratio
set OnlyHero = GoldenEggAISettings_OnlyHero
set CreepAI = GoldenEggAISettings_CreepAI
set HumanAI = GoldenEggAISettings_HumanAI
set Lock = GoldenEggAISettings_Lock
set AG = CreateGroup()
set TE = CreateTrigger()
set RR = CreateRegion()
call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,null)
loop
set u = FirstOfGroup(g)
if HC(u) then
call Reg(u)
endif
call GroupRemoveUnit(g,u)
exitwhen u==null
endloop
call GroupClear(g)
call DestroyGroup(g)
call RegionAddRect(RR,bj_mapInitialPlayableArea)
call TriggerAddAction(TE,function Trg01)
call TriggerRegisterEnterRegion(TE,RR,null)
set u = null
set g = null
endfunction
endlibrary
相關攻略秘籍
魔獸攻略秘籍閱讀排行
- 周
- 月
- 總










