• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] One Hash

Status
Not open for further replies.
How would you like to have One Stackable Hash on your map?, well try this...
instead of using ID of your caster/target, thus if used again it'll overwrite the previous...it gets a unique ID...
instead of destroying timers, use a recyable unitID...
this is an alternate to normal hashing and easy to use...

For GUI and JASS (no vJass) users...

JASS:
//OneHashtable!
//by Mckill2009

//How this works:
//- Works by taking the ID of a unit from the Group and recycles it after
//- This was heavily inspired by my MuiDummyCasters snippet

//Required Variables:
//- FOG_Hash (hashtable)
//- FOG_TakeGroup (group)

//Instructions:
//- Just copy and paste this code to your map header

function FOG_RecycleDummy takes unit dummy, group g returns nothing
    call GroupRemoveUnit(g, dummy)
    call GroupAddUnit(udg_FOG_TakeGroup, dummy)
    call FlushChildHashtable(udg_FOG_Hash, GetHandleId(dummy))    
endfunction

function FOG_TakeDummy takes group g returns integer
    local integer ID
    local unit dummy
    if FirstOfGroup(udg_FOG_TakeGroup)== null then
        call BJDebugMsg("dummy created") //for testing purposes only
        //========================================================
        set dummy = CreateUnit(Player(15), 'hpea', 0, 0, 0) 
        call ShowUnit(dummy, false)
        call UnitAddAbility(dummy, 'Aloc')
        call PauseUnit(dummy, true)
    else
        //if group is not empty then it will pick the first dummy in the group
        set dummy = FirstOfGroup(udg_FOG_TakeGroup)
        call GroupRemoveUnit(udg_FOG_TakeGroup, dummy)    
    endif
    call GroupAddUnit(g, dummy)
    set ID = GetHandleId(dummy)    
    set dummy = null
    return ID
endfunction

Demo:
  • OneHash
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Custom script: set udg_ID = FOG_TakeDummy(udg_Grp1)
      • Set Loc = (Position of (Triggering unit))
      • Unit - Create 1 Footman for (Triggering player) at Loc facing Default building facing degrees
      • Set Dummy = (Last created unit)
      • Custom script: call RemoveLocation(udg_Loc)
      • Hashtable - Save 10.00 as 1 of ID in FOG_Hash
      • Hashtable - Save Handle OfDummy as 2 of ID in FOG_Hash
      • Set Index = (Index + 1)
      • Trigger - Turn on OneHashLooper <gen>
  • OneHashLooper
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Grp1 and do (Actions)
        • Loop - Actions
          • Set ID = (Key (Picked unit))
          • Set Timer = (Load 1 of ID from FOG_Hash)
          • Set Dummy = (Load 2 of ID in FOG_Hash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Timer Greater than 0.00
            • Then - Actions
              • Hashtable - Save (Timer - 1.00) as 1 of ID in FOG_Hash
              • Floating Text - Create floating text that reads (String(Timer)) above Dummy with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Set the velocity of (Last created floating text) to 100.00 towards 90.00 degrees
              • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
            • Else - Actions
              • Unit - Kill Dummy
              • Custom script: call FOG_RecycleDummy(GetEnumUnit(), udg_Grp1)
              • Set Index = (Index - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Index Equal to 0
                • Then - Actions
                  • Game - Display to (All players) the text: TRIG OFF
                  • Game - Display to (All players) the text: (String(Index))
                  • Trigger - Turn off (This trigger)
                • Else - Actions


BTW: I may need testers on this, thanks!

EDIT: I should have posted this into the snippet section XD...
 

Attachments

  • OneHash.w3x
    18.3 KB · Views: 78
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
a question, if i use a unit id, then i cant use 1 hashtable for more than 1 spell right?
but if i use timers then i can use just slower a bit coz of destroy/start timers so more timer same time, but i can use different intervals so example 1 ability with 0.5 sec, another with 2sec interval and stored to same hashtable.

overall i am curios if only players can use the triggered spells, then visible the speed difference between 12*x timer with invidual timer loops where u start and destroy the timers, or 1 timer where u use group enum?
 
@Bribe
yes it will, the Dummy is the footman, not the recycled one, and yes there
are many recycling systems out there but do not use handle of a unit, also
they are in vJass, this system is for GUI and Jass only or normal WE...

@shadowvzs
you can use 1 hashtable for ALL spell, but if you place it under the same ID, it
will definitely bug, try creating an effect with a handle of TriggeringUnit then
cast another, the previous effect cant be removed...
this system is similar to timers, but it recycles the dummies, not killing them
unlike timers that you destroy in Jass...

overall i am curios if only players can use the triggered spells, then visible the speed difference between 12*x timer with invidual timer loops where u start and destroy the timers, or 1 timer where u use group enum?

In vJass, we have TimerUtils which uses recycling timers, T32, CTL which
uses one timer, but in GUI/Jass uses enum, although Jass can use recyable
timers, I have that one but preffer this one coz nobody uses like this before...


TEST MAP ATTACHED
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
@shadowvzs
you can use 1 hashtable for ALL spell, but if you place it under the same ID, it
will definitely bug, try creating an effect with a handle of TriggeringUnit then
cast another, the previous effect cant be removed...
this system is similar to timers, but it recycles the dummies, not killing them
unlike timers that you destroy in Jass...
i dont really used yet the unit handle id's, so if i have 2 spell then trigger unit id is same or different if it is different spell and time but same caster?

checked the map, seems u need 1 unit group and periodic trigger for every spell what got different interval (so 0.02,0.3,0.5,1 this will be 4 periodic trigger right? i understand it is faster than for every cast a different timer but worth that much group enum + variable and hash[if i want cast 2 thing with same unit then i thought it will be use another hash, like hash 2 if hash 1 not empty]?)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Which is why you use a single hashtable with a system unique identifier as the one index and the unit hash as the other to attach an integer. This integer then points at a more complex data structure like a vJASS struct (a series of arrays).

This is faster to as the hashtable natives are not that fast compared to array lookups.
 
Status
Not open for further replies.
Top