- Joined
- Jul 26, 2008
- Messages
- 1,009
So I'm trying to build a struct to represent a unit classification in my map. I want "prey" units to be reviveable and respawn at their origin point (x, y).
I figured I could make a trigger on the structs creation that would detect if the unit designated to the struct dies. If they do, it starts a countdown and at the end of that countdown, a new instance of that unit is created.
However, I'm getting the message that I can't use onDeath or reviveAnimal because they're Undefined functions.
I know it's possible to attach the struct to the timer via hashtable and then reference the values that way. But I was hoping I could have a little more versatility with structs and use them in a less rigid and roundabout way.
Is there a simple way to make this work?
Any additional feedback outside of this is welcome, jsut be sure to preface it as separate.
I figured I could make a trigger on the structs creation that would detect if the unit designated to the struct dies. If they do, it starts a countdown and at the end of that countdown, a new instance of that unit is created.
However, I'm getting the message that I can't use onDeath or reviveAnimal because they're Undefined functions.
I know it's possible to attach the struct to the timer via hashtable and then reference the values that way. But I was hoping I could have a little more versatility with structs and use them in a less rigid and roundabout way.
Is there a simple way to make this work?
Code:
struct Prey
public unit animal
public integer animalType
public integer rareType
public player originPlayer
public real originX
public real originY
private rect nativeRect
private timer deathTimer = CreateTimer()
private trigger deathTrigger
private method reviveAnimal takes nothing returns nothing
set .animal = CreateUnit(.originPlayer, .animalType, .originX, .originY, GetRandomReal(0, 360))
endmethod
method onDeath takes nothing returns nothing
call TimerStart(.deathTimer, 120, false, function reviveAnimal)
call DestroyTrigger(.deathTrigger)
endmethod
private method createDeathTrigger takes nothing returns nothing
set .deathTrigger = CreateTrigger()
call TriggerRegisterUnitEvent( .deathTrigger, .animal, EVENT_UNIT_DEATH )
call TriggerAddAction( .deathTrigger, function onDeath)
endmethod
static method create takes unit animal returns Prey
local thistype prey = thistype.allocate()
set prey.animal = animal
set prey.animalType = GetUnitTypeId(animal)
set prey.originX = GetUnitX(animal)
set prey.originY = GetUnitY(animal)
set prey.nativeRect = gg_rct_HeroSelectionArea //Create function to determine Starting Rect
set prey.rareType = 'A000' //Create function to determine Rare unit type based on Rect (or Animal Type)
call prey.createDeathTrigger()
return prey
endmethod
endstruct
Any additional feedback outside of this is welcome, jsut be sure to preface it as separate.
Last edited: