Detecting a structs instance

dudeim

New Member
Reaction score
22
Hey,

I'm making a system which places a debuff on a unit, but I have a little issue with it because:

Unit A casts a debuff A on Unit B with a 10 sec duration
5 seconds later
Unit A casts a debuff A on Unit B (again)

For example the debuff is a dot the dot will not stack or remove the other dot it will overlap (dunno if this is the correct word), anyway they both tick at their own time.
So how can I know if a unit that is targeted already has the same dot that is being cast this time by the targeting unit

Thanks!
 

luorax

Invasion in Duskwood
Reaction score
67
Create a hashtable and save the instance in it.

JASS:
struct ABC
    static hashtable ht
    static method create takes unit u, integer buffcode returns thistype
        local thistype this = 0
        if HaveSavedInteger(thistype.ht, GetHandleId(u), buffcode) then
            set this = LoadInteger(thistype.ht, GetHandleId(u), buffcode)
        else
            set this = thistype.allocate()
            call SaveInteger(thistype.ht, GetHandleId(i), buffcode, this)
        endif
        return this
    endmethod
    static method getInstance takes unit u, integer buffcode returns thistype
        if HaveSavedInteger(thistype.ht, GetHandleId(u), buffcode) then
            return thistype( LoadInteger(thistype.ht, GetHandleId(u), buffcode) )
        endif
        return 0
    endmethod
    private static method onInit takes nothing returns nothing
        set thistype.ht = InitHashtable()
    endmethod
endstruct
 

dudeim

New Member
Reaction score
22
Hey thanks this is what I needed;)
Also have 3 questions
1. Never seen a static variable any diffrence with them from normals?
2. Can't I do InitHashtable() at the "static hastable ht" line?
3. Can't I just make the hashtable global isn't that easier?
 

Laiev

Hey Listen!!
Reaction score
188
static hashtable ht, means that this hashtable will be created just one time (because we have one type of this struct)

if i use a normal variable hashtable to do it, i'll reach the limit of hashtable fast


3 - yes, will be the same
 

dudeim

New Member
Reaction score
22
Ok
I ran into another problem. Say 2 different units (the player doesn't matter) use the same dot on the same unit right after another, they should both tick seperatly as the dots both are from another unit. So I should know the caster and the targets (handle)id so I know if I need to make it 1 dot or 2 dots?
I hope you get what I mean don't think it's written that clearly but best I could come up with now:p
 

luorax

Invasion in Duskwood
Reaction score
67
Well, I understood what you said, i ran to the same problem. So, I used 1 instance per buff per unit, and used arrays to store the players' heroes' informations.
 

dudeim

New Member
Reaction score
22
Well I want it so that every unit can use it not just heroes, so I think that complicates stuff.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
What I do is use an indexing system and keep a buff list assigned to the unit's index. If it seems a bit complicated to do, then I recommend that you use BuffStruct, as it will greatly simplify buff creation and management. =)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top