- Joined
- Aug 17, 2009
- Messages
- 33
Hello,
I am currently trying to create a Spell which by chance creates little objects randomly placed around a hero (with a certain ability/buff) when attacking another unit. When the hero comes in contact with these objects (which disappear after 10 seconds) he will get healed for a certain amount, consuming the object.
I could successfully create a piece of code which creates these objects (here I call them Healing Spheres) how I want them with a 1/3 chance upon every auto-attack the hero performs. They are placed within a rectangle with a width and height of 600 centered around the hero.
Thanks to the local variables I can have multiple identical heroes perform attacks and each create these spheres on their own.
With a simple GUI I pick every healing sphere every second of game time and subtract one hitpoint (from their starting 10) with kills them after 10 seconds.
This only leaves me with the consumption of the spheres missing. I basically want the hero (or any hero with the necessary buff to create them) to be able to walk over to a live healing sphere and as soon as they come "in contact/within a certain range" consume the sphere and receive healing. Though I don't know how I am supposed to approach this.
I know you can create an event which triggers as soon as any unit comes within a certain range of a certain unit, but since I create these spheres in-game there is no global variable I can use to refer to any of the spheres. What I think I would need is an event which triggers as soon as any unit comes within a certain range of any other unit and be able to refer to these units as unit1 and unit2 so I can check unit1 for the buff and unit2 if it is a sphere. Then I could kill unit2 and gives healing to unit1.
I thought creating an array of units to temporarily store the spheres in may be impractical since I don't want to have an upper arbitrary limit on them.
I hope I was able to bring my idea across. Any help is appreciated, thank you.
I am currently trying to create a Spell which by chance creates little objects randomly placed around a hero (with a certain ability/buff) when attacking another unit. When the hero comes in contact with these objects (which disappear after 10 seconds) he will get healed for a certain amount, consuming the object.
I could successfully create a piece of code which creates these objects (here I call them Healing Spheres) how I want them with a 1/3 chance upon every auto-attack the hero performs. They are placed within a rectangle with a width and height of 600 centered around the hero.
Code:
function Trig_Healing_Spheres_Conditions takes nothing returns boolean
if ( not ( UnitHasBuffBJ(GetAttacker(), 'B000') == true ) ) then
return false
endif
return true
endfunction
function Trig_Healing_Spheres_Actions takes nothing returns nothing
local unit u = GetAttacker()
local location l = GetUnitLoc(u)
local location randomLocation = GetRandomLocInRect(RectFromCenterSizeBJ(GetUnitLoc(GetAttacker()), 600.00, 600.00))
if (GetRandomInt(0, 2) == 0) then
call CreateUnitAtLoc(GetOwningPlayer(u), 'u000', randomLocation, 0)
endif
endfunction
//===========================================================================
function InitTrig_Healing_Spheres takes nothing returns nothing
set gg_trg_Healing_Spheres = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Healing_Spheres, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Healing_Spheres, Condition( function Trig_Healing_Spheres_Conditions ) )
call TriggerAddAction( gg_trg_Healing_Spheres, function Trig_Healing_Spheres_Actions )
endfunction
Thanks to the local variables I can have multiple identical heroes perform attacks and each create these spheres on their own.
With a simple GUI I pick every healing sphere every second of game time and subtract one hitpoint (from their starting 10) with kills them after 10 seconds.
This only leaves me with the consumption of the spheres missing. I basically want the hero (or any hero with the necessary buff to create them) to be able to walk over to a live healing sphere and as soon as they come "in contact/within a certain range" consume the sphere and receive healing. Though I don't know how I am supposed to approach this.
I know you can create an event which triggers as soon as any unit comes within a certain range of a certain unit, but since I create these spheres in-game there is no global variable I can use to refer to any of the spheres. What I think I would need is an event which triggers as soon as any unit comes within a certain range of any other unit and be able to refer to these units as unit1 and unit2 so I can check unit1 for the buff and unit2 if it is a sphere. Then I could kill unit2 and gives healing to unit1.
I thought creating an array of units to temporarily store the spheres in may be impractical since I don't want to have an upper arbitrary limit on them.
I hope I was able to bring my idea across. Any help is appreciated, thank you.