Nerzhul
New Member
- Reaction score
- 7
I Mean, I need to attach lot of data for EACH creep in the map but with many variables with big arrays it cause corruption.Is there a way with AIDS to solve that?
Cool! That what I wanted to know ^^Set array size to 0, you can still use all the indices up to 8191.
In AIDS, you do not need to have the "[LJASS]unit source[/LJASS]" member, as AIDS provides you with a member: [LJASS].unit[/LJASS]. This is the unit for which the struct exists.I'm creating an aggro system and I was wondering if the following snippet correctly assigns an index and setup up aggro-related stuff for a unit:
I would not use unit attaching at all for this. What you need is a stand-alone struct, with a trigger (which you register for when that unit casts a spell) and you need to attach the casting unit to that trigger (by attaching the struct). Destroy the struct and the trigger after x seconds using a timer (timer system of some sort). Hope you get what I mean.Also, I have a spell that bestows a debuff on an enemy unit. Everytime the enemy unit casts a spell it takes damage. However, I have to know the source of the spell (the caster) to properly deal damage so that the source gets the bounty for the kill, if the target dies.
Would you then use the index of the unit as an index for a specific array of structs that the spell uses?
Just to be clear, this is what you mean:I would not use unit attaching at all for this. What you need is a stand-alone struct, with a trigger (which you register for when that unit casts a spell) and you need to attach the casting unit to that trigger (by attaching the struct). Destroy the struct and the trigger after x seconds using a timer (timer system of some sort). Hope you get what I mean.
just curious, why is triggersleepaction used instead of a timer like from KT2? is it just because doing so would complicate the code further?You mean...
?JASS:struct CreepRevival extends array //! runtextmacro AIDS() private trigger t private real x private real y private integer utype private static method OnDeath takes nothing returns nothing local thistype d=thistype[GetTriggerUnit()] // Because the struct may be destroyed before the wait finishes. local trigger t=d.t local real x=d.x local real y=d.y local integer utype=d.utype set d.t=null call TriggerSleepAction(3.0) call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE),utype,x,y,0) call DestroyTrigger(t) set t=null endmethod private static method AIDS_filter takes unit u returns boolean return GetOwningPlayer(u)==Player(PLAYER_NEUTRAL_AGGRESSIVE) endmethod private method AIDS_onCreate takes nothing returns nothing set this.utype=GetUnitTypeId(this.unit) set this.x=GetUnitX(this.unit) set this.y=GetUnitY(this.unit) set this.t=CreateTrigger() call TriggerAddAction(this.t,function thistype.OnDeath) call TriggerRegisterUnitEvent(this.t,this.unit, EVENT_UNIT_DEATH ) endmethod endstruct
I kinda had to. For each unit owned by neutral hostile, that will store its x/y/type, and on death wait 3.0 seconds and then spawn a new unit of that type at that original x and y, regardless where it died. Change 3.0 to your liking. This is why I made AIDS... It makes map-wide unit data systems sooo easy to code. <_<
Edit: I may add something called Locks (which won't break anything currently made) which will stop an index from being freed (and hence all AIDS structs on it) until the same number of Unlocks have been called.
... So, you'd be able to attach the struct to a timer, and not worry about it getting destroyed, because it won't be until the timer unlocks it after its callback... (Which is what I should've done here, not that it matters.)
Edit again:
In answer to your question, I'd recommend you give your map AIDS.
So for Renendaru, here's a AIDS/KT version of a simple creep respawn system. You could even add an AIDS_onDestroy so if creeps were REMOVED from the game, they'd STILL respawn. XD
PS. The previous version leaked trigger actions, I forgot. lol.JASS:struct CreepRevival extends array //! runtextmacro AIDS() private trigger t private real x private real y private integer utype private static method Callback takes nothing returns boolean local thistype this=KT_GetData() call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE),this.utype,this.x,this.y,0) call this.AIDS_removeLock() return true endmethod private static method OnDeath takes nothing returns boolean local thistype this=thistype[GetTriggerUnit()] call this.AIDS_addLock() // So the struct can't disappear before the timer ticks. call KT_Add(function thistype.Callback,this,3.0) call DestroyTrigger(this.t) set this.t=null return false endmethod private static method AIDS_filter takes unit u returns boolean return GetOwningPlayer(u)==Player(PLAYER_NEUTRAL_AGGRESSIVE) endmethod private method AIDS_onCreate takes nothing returns nothing set this.utype=GetUnitTypeId(this.unit) set this.x=GetUnitX(this.unit) set this.y=GetUnitY(this.unit) set this.t=CreateTrigger() call TriggerAddCondition(this.t,Condition(function thistype.OnDeath)) call TriggerRegisterUnitEvent(this.t,this.unit, EVENT_UNIT_DEATH ) endmethod endstruct
and..."PS. The previous version leaked trigger actions, I forgot. lol."Don't worry, I made this version just to confuse the frak out of innocent JASSers like yourself!
It's a few posts down, and is much better...
These locks?The main complication is AIDS struct locking (something AutoIndex lacks to the best of my knowledge ).
Locks just
// put off AIDS struct destruction in case you wish to attach to a timer
// or something which must expire before the struct data disappears.
// Hence, not freeing all locks will leak the struct (and index).
Some limitations caused by the need of an array struct like not possible to have array members, maybe ?Hrm. I was sure I had some point I wanted to say, but I forgot it.
Done. Now uses [LJASS]GetWorldBounds()[/LJASS] and checks that the unit's userdata is 0. (Version 1.0.4 released.)>But since it's possible to fix it, in a reasonable efficient and easy way, you should do it.
Absolutely. As said, will be in next update. Be patient with me, I have limited WC3 time. It will be done.![]()
Hm. I'll use a struct initialiser then, and release an update.The relative order between different struct initializers depends on the location they are found in the map script, therefore they actually depend on things like libraries as well (A struct initializer inside a library will run before the initializers inside other libraries that require it and also before initializers inside scopes).