• 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.

[JASS] vJASS non-periodic timer, attaching a unique id

Status
Not open for further replies.
Level 6
Joined
Jul 25, 2005
Messages
221
Yo, I was going over the vJASS way of MUI'ing spells, but one tutorial I have yet to see, is an equivalent to the H2I method which was(is)
JASS:
function H2I takes handle h returns integer
       return h
       return 0
endfunction

function I2U takes integer i returns unit
       return i
       return 0
endfunction

function executeonce takes nothing returns nothing
local gamecache gc = udg_gamecache
local string uniqueMS = I2S(H2I(GetExpiredTimer() ) )
local unit u = I2U(GetStoredInteger(gc, "unit", uniqueMS) )
//actions

endfunction

function InitSomeTrig takes nothing returns nothing
local gamecache gc = udg_gamecache
local timer t = CreateTimer()
local string uniqueMS = I2S(H2I(t))
local unit u = CreateUnit( blabla )
        call StoreInteger(gc, uniqueMS, "unit", H2I(u) )
        call TimerStart( t, 5.00, false, function executeonce)
endfunction
Here I store a unit, u, then it is transferred over to the executeonce function using the timer's unique id as a missionkey.

Similarly I tried using it with structs, but no-one has explained how to access one instance from all instances available. Anyone care to explain or do you want me to elaborate a little?

Three spells are cast, with 1 second apart from each cast.
After 5 seconds of each cast, an action takes place.

So, the order of each action would be at seconds:
5, 6, 7.

So, how do I know which timer that fired if the instances used where like 4, 7 and 2?

This is what I tried

JASS:
    struct Spell_Data
        unit currenttarget
        real targetX
        real targetY
        
        unit u
        real uX
        real uY
        
        timer atimer 
        integer uniqueid = 0
        boolean timeron = false
    endstruct

    globals
        Spell_Data array Spell_Data_Array
        integer TOTAL_INSTANCES = 0
        timer TIMER = CreateTimer() // this timer is another timer used for a movement test that works splendidly...
        
        integer TYPE = 'h001'
    endglobals

function H2I takes handle h returns integer
       return h
       return 0
endfunction

function ExecuteMovement takes nothing returns nothing
    local Spell_Data sd
    local integer i = 0
    
    loop
        exitwhen i >= TOTAL_INSTANCES
            set sd = Spell_Data_Array[i]
                if( sd.uniqueid != 0 ) then
                    set sd.timeron = true
                    call ResetUnitAnimation(sd.u)
                    call DestroyTimer( sd.atimer )
                endif
        set i = i +1
    endloop
    endfunction

function Initiate takes unit u returns nothing
    local Spell_Data sd = Spell_Data.create()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local integer angle = GetRandomInt(1,360)
    local integer i = 0
    local real newx = x + 150*Cos(angle*(bj_PI/180) )
    local real newy = y + 150*Sin(angle*(bj_PI/180) )
    local real facing = AngleBetweenPointsXY( newx, newy, x, y )
    local unit u = CreateUnit( GetOwningPlayer(u), TYPE, newx,newy, facing)
        set sd.atimer = CreateTimer()
        set sd.currenttarget = u
        set sd.u = u
        set sd.uniqueid = H2I(sd.atimer)
        call TimerStart( sd.atimer, 5, false, function ExecuteMovement )   
        set TOTAL_INSTANCES = TOTAL_INSTANCES + 1
        set Spell_Data_Array[TOTAL_INSTANCES-1] = sd
    endfunction
But, then again, I had no clue what to do, because as I said, I have yet to see a tutorial about this...

My educated guess, would be to set the instance number to the handle, but I thought this new way would make the H2I functions obsolete, 'cause I really hate using gamecache so this is why I jumped with joy when I heard about the new method

Ah, this is hard to explain, I hope you understand what I'm trying to convey here... :hohum:
 
Level 6
Joined
Jul 25, 2005
Messages
221
Ah, good good, precisely what I was looking for! Even though I searched the Wc3Campaign site a minute ago, I couldn't find it. I noticed Vexorian mentioned it in another tutorial and I was confused. Anyway, thanks!
 
Level 5
Joined
Jul 18, 2007
Messages
110
Well I have a spell like:
  • Then - Actions
    • Set temp_group = (Units in (Playable map area) matching (((Matching unit) is owned by Player 1 (Red)) Equal to (==) True))
    • Unit Group - Pick every unit in temp_group and do (Actions)
      • Loop - Actions
        • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Human\Resurrect\ResurrectCaster.mdl
        • Unit - Add Enchantment (Damage) to (Picked unit)
        • Unit - Add Enchantment (Armor) to (Picked unit)
    • Wait 3.00 seconds
    • Unit Group - Pick every unit in temp_group and do (Actions)
      • Loop - Actions
        • Unit - Remove Enchantment (Damage) from (Picked unit)
        • Unit - Remove Enchantment (Armor) from (Picked unit)
        • Special Effect - Destroy (Last created special effect)
    • Custom script: call DestroyGroup (udg_temp_group)
And I need a JASS timer for it I think to work, since it doesn't remove the abilities. So was wondering how/what would I implement..? My friend helped me with the code in vJASS as well, so I have that in case I can't just throw it in the raw script.
 
Status
Not open for further replies.
Top