• 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.

Library Ideas

Status
Not open for further replies.
AI system is by far the most difficult system to make IMO...

I have managed to create it though...not finished

But most likely, this is a pet system...

JASS:
library FollowUserHero

globals
    private constant hashtable                        HASH = InitHashtable() //Do not touch this!
    private constant integer                       SHOOTID = 852119 //Custom based attack only (Chain Lightning)      
    private constant real                       AOE_FOLLOW = 4000 //AOE range on which user nit it will follow
    private constant real                    AOE_ITEM_PICK = 400 
    private constant real                         INTERVAL = 3 //The delay time when AI will follow or pick up item
    private constant real                          AOE_ATK = 1000
    private constant integer                 MAX_ITEM_TYPE = 3 //Should be match on how many item types created
    private constant boolean          ENABLE_CUSTOM_ATTACK = true //This is for the SHOOTID only
    private constant boolean           ENABLE_PICK_UP_ITEM = true
    private constant boolean      ENABLE_PICK_UP_ITEM_TYPE = true //Set to false to pick only item types
    private constant boolean            ENABLE_FOLLOW_HERO = true //set to true to follow hero
    private rect R
    private integer array ITEM_TYPE
endglobals

private struct FUH
    unit comp
    real atk
    real pick
    
    static integer DATA
    
    static method onPickItem takes nothing returns boolean
        local thistype fol = DATA
        local item it = GetFilterItem()
        local integer i = 0
        if ENABLE_PICK_UP_ITEM_TYPE then 
            loop
                set i = i+1
                if GetItemTypeId(it)==ITEM_TYPE[i] then
                    call IssueTargetOrder(fol.comp, "smart", it)
                endif
                exitwhen i >= MAX_ITEM_TYPE
            endloop
        else
            call IssueTargetOrder(fol.comp, "smart", it)        
        endif
        set it = null
        return false
    endmethod
    
    static method onAtk takes nothing returns boolean
        local thistype fol = DATA
        local unit u = GetFilterUnit()
        local boolean b = IsUnitEnemy(u, GetOwningPlayer(fol.comp)) and GetWidgetLife(u) > 0.405
        set u = null
        return b
    endmethod
    
    static method onFollow takes nothing returns boolean
        local thistype fol = DATA
        local unit u = GetFilterUnit()
        local real x
        local real y
        local real offset = GetRandomReal(100, 250)
        local real angle = GetRandomReal(0, 360)
        if not IsUnitEnemy(u, GetOwningPlayer(fol.comp)) and IsUnitType(u, UNIT_TYPE_HERO) and GetWidgetLife(u) > 0.405 and GetPlayerController(GetOwningPlayer(u))==MAP_CONTROL_USER then
            set x = GetUnitX(u)+offset*Cos(angle)
            set y = GetUnitY(u)+offset*Sin(angle)
            call IssuePointOrder(fol.comp, "move", x, y)  
        endif      
        set u = null
        return false
    endmethod
    
    static method enumerate takes nothing returns nothing
        local timer t = GetExpiredTimer()        
        local thistype fol = LoadInteger(HASH, GetHandleId(t), 1)
        local real x = GetUnitX(fol.comp)
        local real y = GetUnitY(fol.comp)
        local unit first
        set DATA = fol
        
        if ENABLE_FOLLOW_HERO then
            call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, AOE_FOLLOW, function thistype.onFollow)
        endif
        
        if ENABLE_PICK_UP_ITEM then
            set fol.pick = fol.pick+1.0
            if fol.pick>=2.0 then
                set fol.pick=0
                set R = Rect(-AOE_ITEM_PICK, -AOE_ITEM_PICK, AOE_ITEM_PICK, AOE_ITEM_PICK)
                call MoveRectTo(R, x, y)
                call EnumItemsInRect(R, function thistype.onPickItem, null)
            endif
        endif
        
        if ENABLE_CUSTOM_ATTACK then 
            set fol.atk = fol.atk+1.0
            if fol.atk>=1.5 then
                call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, AOE_ATK, function thistype.onAtk)
                set first = FirstOfGroup(bj_lastCreatedGroup)
                call IssueTargetOrderById(fol.comp, SHOOTID, first) 
                set fol.atk=0
            endif
        endif
        set first = null
    endmethod
    
    static method create takes unit u returns thistype
        local thistype fol = thistype.allocate()
        local timer t = CreateTimer()
        set fol.comp = u
        set fol.atk = 0
        set fol.pick = 0
        call SaveInteger(HASH, GetHandleId(t), 1, fol)
        call TimerStart(t, INTERVAL, true, function thistype.enumerate)
        set t = null
        return fol
    endmethod
endstruct

private function FH_SetUpItemTypes takes nothing returns nothing
    //IMPORTANT NOTE: if you increase the item types created, you should increase also the MAX_ITEM_TYPE of the globals
    set ITEM_TYPE[1] = 'will' //Default Wand of Illusion
    set ITEM_TYPE[2] = 'woms' //Default Wand of Mana Stealing
    set ITEM_TYPE[3] = 'wlsd' //Default Wand of Lightning Shield
    //set ITEM_TYPE[4] = 'ADDITIONAL ITEM'
    //set ITEM_TYPE[5] = 'ADDITIONAL ITEM'
endfunction

function FH_GetUnit takes unit comp returns nothing
    call FH_SetUpItemTypes()
    call FUH.create(comp)
endfunction

endlibrary

TESTING:
  • TEST
    • Events
      • Time - Elapsed game time is 3.00 seconds
    • Conditions
    • Actions
      • Custom script: set udg_unit = CreateUnit(Player(0), 'Hmkg',0,0,0)
      • Custom script: call FH_GetUnit(udg_unit)
 
Level 17
Joined
Jan 21, 2010
Messages
2,111
Great, waiting for the ultis mags, btw, could you add these to the libs:
  1. ai choose to attack creep, but when a hero with low heatlh come, it will prefer to attack the low hp hero first then after the hero die, or it goes too far the creep become the target
  2. ai choose to buy item
  3. ai use item
  4. ai use skill
  5. ai forest swarming
  6. ai attack tower
  7. ai learn skill
  8. ai retreat when their hp is low
  9. ai gank up with their ally
  10. ai aid their ally
  11. ai synergy with their team mate, like in dota
,since here, in thw, we has too many aos maps :D
 
@ McKill:
An AI pet is done by issueing a patrol order on a unit and then creating a buffer that checks if either one is alive to refresh the orders :)
You can also use the smart order ^^
If you want it to be complex, you should create a buffer that checks the state of the master to determine the next action that the pet has to do ^^

edit
Guys the thing is, an AI system requires several other libraries like a "Player State Library"
No, not like gold/lumer, I mean like:
- "InNeedOfGold"
- "InNeedOfLumber"
- "MustGoFarming"
- "Merciful"
- "NeedsToAvoidEnemyContact"

etc..

I'll code those first, but this library isn't going to be "engined", you can set the player state whenever you want.
It's similar to the "Event". It's not going to fire those events, you should ;)

Don't worry, the thing is going to be "engined" within the functions of the AI system.

edit

Guys, I'm also coding an Anti-Spam System :)
That'll stop those 'people' from ruining your games with endless message spamming ;)
 
Last edited:
Status
Not open for further replies.
Top