• 🏆 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] How to attach anything to timers

Status
Not open for further replies.
Level 7
Joined
Aug 31, 2006
Messages
132
I just don't get it and worse, can find no help. To make a simple JASS knockback, i had to resort to using a timer and have to transfer the local variables to the function it calls. The problem is, i can't. I searched in the JASS help section, but that is the only what i found.

function Cond takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction

function Knockback takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit caster = GetHandleUnit(t, "caster")
local unit target = GetHandleUnit(t, "target")
local real x1 = GetUnitX(caster)
local real y1 = GetUnitY(caster)
local real x2 = GetUnitX(target)
local real y2 = GetUnitY(target)
local real angle = GetAngleBetweenPoints(x1,y1,x2,y2)
local real dist = GetDistanceBetweenPoints(x1,y1,x2,y2)
call SetUnitPosition(target, PolarProjectionX(x2, dist+10.00, angle), PolarProjectionY(y2, dist+10.00, angle))

set t = null
set caster = null
set target = null
endfunction

function Knockback takes nothing returns nothing
local timer t = CreateTimer()
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
call SetHandleHandle(t, "caster", caster)
call SetHandleHandle(t, "target", target)
call TimerStart(t, 0.035, true, function Knockback)
call TriggerSleepAction(0.5)
call FlushHandleLocals(t)
call DestroyTimer(t)
set t = null
set caster = null
set target = null
endfunction

function InitTrig_trigger takes nothing returns nothing
local trigger Knocky
set Knocky = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( Knocky, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Knocky, Condition(function Cond))
call TriggerAddAction(Knocky, function Knockback)
endfunction

Not only does my WE not allow it, I couldn't find some of the functions it uses in JC and it seems either outdated, or in need of additional code which i could not download. (The link lead to wc3sear.ch)

(The code comes from Advanced JASS tips in the The Hive Workshop JASS/AI Scripts Tutorials)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
call SetHandleHandle(t, "caster", caster)
call SetHandleHandle(t, "target", target)

You are obviously using the dated HANDLEVARS system.
Please use hashtables instead as they are faster and more robust.

Anyway, the idea for efficiency is to use a highlevel system for knockback whereby you simply add the units to it and the system does the rest. I am sure I have seen dozens of those before and whats good about them is they are MUI to 8000 odd knockbacks at one time and do not store anything in a funky system and so just loop through all instances of knockback performing the actions.

Anyway, like I said dont use handlevars and use hashtables instead.
 
Status
Not open for further replies.
Top