- Joined
- Dec 12, 2008
- Messages
- 7,385
I'm out of ideas for stuff I'm going to code.. Can anyone help me out here?
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
I won't recommend anything in its place as any recommendation from me would be too hard for you ; p