• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Timers =O

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright so lately I've been delving into jass, I've been learning pretty fast but I'm kind of stuck on the subject of timers. Basicaly, when a unit is attacks with the ability Frost Master it has a 20% chance to freeze the target in a block of ice. When a unit is frozen its animation speed is set to 0 and color tinted blue, all of this I did successfully but I'm having trouble returning it to normal.

So what I want to do is create a timer every time a unit is frozen that when it finishes calls a function that 'un-blues' the unit. The problem being how do I refer back to the correct unit =/.

I was reading somewhere about H2I timers that do something like this but it didn't quite explain it nor did it have the actual code. So if anyone could help here it would be awesome.
 
Level 11
Joined
Apr 6, 2008
Messages
760
ill give you an (crappy) example.

JASS:
globals
     group Unit_Stack = CreateGroup()
     real array Time_Left
     integer Total = 0
     timer Time = CreateTimer()
endglobals

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

function Loop takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local integer Index
    
    call GroupAddGroup(Unit_Stack,g)
    
    loop
        set u = FirstOfGroup(g)
        exitwhen g == null
        call GroupRemoveUnit(g,u)
        set Index = (H2I(u)-0x100000)
        set Time_Left[Index] = Time_Left[Index] - 0.25 //- whatever the interval on you timer is
        if Time_Left[Index] <= 0. then
            //action to reverse the effect
            call GroupRemoveUnit(Unit_Stack,u)
            set Total = Total - 1
        endif
    endloop
    
    if Total == 0 then
        call PauseTimer(Time)
    endif
    
    call DestroyGroup(g)
    set g = null
    
endfunction

function Action takes nothing returns nothing
//do what u did but add this
call GroupAddUnit(Unit_Stack,"Unit") //change "Unit" to your Var
set Time_Left[H2I("Unit")-0x100000] = 5. //to how long it gonna

if Total == 0 then
    call TimerStart(Time,0.1,true,function Loop)
endif

set Total = Total + 1
endfunction
 
Level 10
Joined
Jan 21, 2007
Messages
576
The only thing about that code that I am unsure of what it is doing is the function H2I, and then in conjunction with that:

JASS:
set Index = (H2I(u)-0x100000)

What is that doing lol, so you're subtracting 0x100000 (which is 0......?) from H2I(u)? If you could explain what that part is doing that would help a lot.

EDIT: All of this going by your code btw, just trying to perfect this as a model that I understand so I can learn from it and build my own.
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
H2I would in any normal programming language be called type casting, which means that you make a type of variable "act" like another type.

A small C++ example would be to write
Code:
int i = (int)(1.3847);
Which would make the number 1.3847 act like an integer and thus "i" would be equal to 1.
The same in Jass would be R2I (real to integer).

Anyhow, H2I abuses a bug which is that the compiler only checks your last "return" statement so you can basically type cast any type to any type you want (as long as you know what you're doing, unless you want to probably crash warcraft).

So, we get the integer that represents an handle ID, we remove 0x100000 which is NOT 0 multiplied by 100000, since multiplication is *.
0x means that this is a Hexadecimel number, and 100000 is the Hex number that most of the handles start with, so to get their "real" value you reduce that number and tadam, you have the integer that represents the ID of your handle.
 
Status
Not open for further replies.
Top