S&d ai

Dasslokk

New Member
Reaction score
9
Does anyone know how to make a "search and destroy" AI?
(for anyone wondering I mean an AI where units will walk around looking for the enemy)
 

Azlier

Old World Ghost
Reaction score
461
I threw this together. The best part, it's totally untested! Requires NewGen.

JASS:
scope SnD initializer Init
//Requires NewGen.
globals
    private constant group AIGroup = CreateGroup()
    //No touchie the group.
    private constant player AIPlayer = Player(12)
    //Whatever player this should run for. 
    //(In JASS, Player 0 is red. So, blue is Player 1, and so on,
    //Player 12 is Neutral Hostile.)
    private constant rect AIRect = bj_mapInitialPlayableArea
    //The region they will search inside. It is currently Playable Map Area.
    private constant integer Helpers = 3
    //The amount of reinforcements a unit call when attacked.
    private constant real HelpRange = 1000
    //The distance from which reinforcements can be called.
    private boolexpr True
    //No touchie the boolexpr.
    private constant real MinX = GetRectMinX(AIRect)
    //No touchie.
    private constant real MaxX = GetRectMaxX(AIRect)
    //No touchie.
    private constant real MinY = GetRectMinY(AIRect)
    //No touchie.
    private constant real MaxY = GetRectMaxY(AIRect)
    //No touchie.
    private unit array EnumUnits
    //NO TOUCHIE.
endglobals

private constant function TrueFunc takes nothing returns boolean
    return true
endfunction

private function AIAct takes nothing returns nothing
    local unit EnumUnit
    local unit TrigUnit = GetTriggerUnit()
    local integer i = 0
    local integer loopint = 0
    local real X = GetUnitX(TrigUnit)
    local real Y = GetUnitY(TrigUnit)
    call GroupEnumUnitsInRange(AIGroup, X, Y, HelpRange, True)
    loop
        set EnumUnit = FirstOfGroup(AIGroup)
        exitwhen EnumUnit == null
        set EnumUnits<i> = EnumUnit
        set i = i + 1
        call GroupRemoveUnit(AIGroup, EnumUnit)
    endloop
    loop
        exitwhen loopint &gt; Helpers
        call IssuePointOrder(EnumUnits[GetRandomInt(0, i)], &quot;attack&quot;, X, Y)
        set loopint = loopint + 1
    endloop
    set EnumUnit = null
    set TrigUnit = null
endfunction

private function RunAI takes nothing returns nothing
    local unit EnumUnit
    call GroupEnumUnitsOfPlayer(AIGroup, AIPlayer, True)
    loop
        set EnumUnit = FirstOfGroup(AIGroup)
        exitwhen EnumUnit == null
        if OrderId2String(GetUnitCurrentOrder(EnumUnit)) == &quot;none&quot; then
            call IssuePointOrder(EnumUnit, &quot;attack&quot;, GetRandomReal(MinX, MaxX), GetRandomReal(MinY, MaxY))
        endif
        call GroupRemoveUnit(AIGroup, EnumUnit)
    endloop
    set EnumUnit = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local timer tr = CreateTimer()
    local integer i = 0
    set True = Filter(function TrueFunc)
    call TimerStart(tr, 0.01, true, function RunAI)
    call TriggerRegisterPlayerUnitEvent(t, AIPlayer, EVENT_PLAYER_UNIT_ATTACKED, True)
    call TriggerAddAction(t, function AIAct)
endfunction

endscope</i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top