• 🏆 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!

[JASS] GetTriggerUnit and timers

Status
Not open for further replies.
Level 7
Joined
Mar 24, 2008
Messages
184
so, i wanted to try and make a spell in vJASS after reading some tutorials (i wanted to do that like 2-3 months ago but only now i have time since i'm done with uni exams) but i'm having some problems with timers

JASS:
library Shadowloop

   public function slicedice takes nothing returns nothing
        local loopthingie stru=GetUnitUserData(GetTriggerUnit())
        local unit SliceAndDiceCaster=stru.owner
        local unit SliceAndDiceTarget=stru.target
        //stuff
    endfunction
    
struct loopthingie
    public boolean attack=true
    public unit owner
    public unit target
    public timer loopy = CreateTimer()
    public integer in = 0
    public real angle1 
    public real angle2
    
    method onDestroy takes nothing returns nothing
        call PauseTimer(this.loopy)
        call DestroyTimer(this.loopy)
    endmethod

endstruct

private function Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A02O')== true
endfunction

private function Actions takes nothing returns nothing
    local loopthingie stru = GetUnitUserData(GetTriggerUnit())
    call TimerStart(stru.loopy, GetRandomReal(0.10, 0.27), true, function slicedice)
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger Shadowloop = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Shadowloop, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(Shadowloop, Condition( function Conditions))
    call TriggerAddAction(Shadowloop, function Actions)
endfunction
endlibrary

The spell works this way, there's a unit that creates 4 clones and they all attack moving around the target, this is the part that's supposed to control each clone (the main spell puts the created unit and the target unit in the struct in the variables owner and target, and attaches it to the unit, then when it's needed, orders the units to use the ability to activate this trigger)
Actually i do know what the problem is, the GetTriggerUnit of the function slicedice doesn't get anything. i've tried passing the unit with a global variable and it worked, but i'm pretty sure there's a better way to do this, i just can't think anything to make it work (why oh why i can't use variables with arguments on timers code? there are some silly limits in the WE imho)
 
Last edited:
Level 7
Joined
Mar 24, 2008
Messages
184
So, i have to use Captain Griffen's Attach Timer function, very smart using the timer itself to move values, i wonder why i haven't thought of that :smile:

Still, using vJASS, there isn't any other way to do that? I mean, i feel like i'm missing something about structs
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You can either use vJass or use the H2I bug which is a bit less stable and quite slower (in a programmers view).
An example for H2I usage is Katana's Handle Local Vars which I can't seem to find anymore in wc3c.

Of course there is always the ol' Game Cache if speed isn't important.
 
Level 7
Joined
Mar 24, 2008
Messages
184
i'm learning vJASS just because i've been told that it can do what Game Cache and Handle vars do (though i'm not sure of what theese two systems do, altough i read about them in many tutorials).
Well, i have time to learn, at least unitl september

I've seen the H2I function with the double return, it returns the handle id as integer if i got it right.

What i still don't understand (forgive me for my dumbness :cry: ) is what i have to do with vJASS, or at least if there's another way to do it other than the attach timer function (i haven't tried it yet, since i'm going out at the moment, but it's always better to know more than one way to do something, in case one doesn't work )
 
Status
Not open for further replies.
Top