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

Help whith charge ability

Status
Not open for further replies.
Hi, i'm making a little charge ability for a map of mine but I'm encountering some problems regarding passing information through a function called by a timer.

I guess it sounds a bit fancy, but have a look at this code:
JASS:
function moveUnit takes nothing returns nothing
local location loc = GetUnitLoc(u)
local location p
local group g = CreateGroup()
local unit temp
local real length = 0
if length<300
//Move
set loc = GetUnitLoc(u)
call SetUnitAnimation( u, "stand ready" )
set p = PolarProjectionBJ(GetUnitLoc(u), 20, AngleBetweenPoints(GetUnitLoc(u), targ))
if IsTerrainPathable(GetLocationX(p), GetLocationY(p)) then
call SetUnitPositionLoc(u, p)
call RemoveLocation(p)
endif
set length = length+20
//Bash
call GroupEnumUnitsInRangeOfLoc(g, loc, 60., null)
set temp = FirstOfGroup(g)
if IsUnitEnemy(temp, GetOwningPlayer(u)) then 
call CreateUnitAtLoc(GetOwningPlayer(u), 'h000', loc, 0.)
call UnitAddAbility(GetLastCreatedUnit(), 'a001')
call IssueTargetOrder( GetLastCreatedUnit(), "thunderbolt", temp)
call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 2.00 )
else 
//Clean up
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
call RemoveLocation(loc)
call DestroyGroup(g)
set g = null
set loc = null
set temp = null
set p = null
    //return
endfunction

function chargeAura2 takes unit u returns nothing
    local timer t = CreateTimer()
    call TimerStart(t, 0.03, true, function moveUnit())
    //return
endfunction

Now, this script is not complete; though i want to know how to pass the variables - that would say the target point and casting unit - to the function, before i complete it. I have a version that uses TriggerSleepAction, but that works really awkward with such short intervalls.
I really don't want to use H2I here either, since the new patch is coming.
What do i need to make this work?

EDIT: I realize many things in this code simply doesen't make sense since i mostly copied it from the other code i did. Don't worry about the uninitialized variables and so on.
 
Level 11
Joined
Oct 13, 2005
Messages
233
If you don't want the spell to be MUI, just use a few global variables. However, if you need it to be MUI, things become more fun:

You have a few options. I recommend using H2I/GetHandleId and either gamecache, a hashtable, or a timer stack in order to attach the data. The timer stack approach would require a script such as TimerUtils which is available at wc3c and requires the NewGen Pack in order to work.

As for gamecache + return bug/hashtable + GetHandleId, this is the second approach I would recommend if you are not willing to use the NewGen pack. Keep all your patch-dependent JASS code in one section so that only that section will need to be updated to work with the new patch.

The third approach, which is easily the most annoying to implement, would require global arrays for every data type being stored and a stack to keep track of unused indexes in these global arrays. When the caster starts the spell, retrieve an unused index and attach it to the unit with SetUnitUserData and add the unit to a global group of units that are currently under the effects of the spell. When the effect for a unit ends, reset the UnitUserData to 0 and remove the unit from the global group. The alternative for using UnitUserData and a unit group would be to use a global array to keep track of units under the effect of the spell and some smart indexing to keep things in order.

Of these approaches, if you can use JassHelper in the NewGen pack, I recommend using structs with TimerUtils. This uses H2I, but a 1.24+ version is also supplied on the site to allow quick updating when the patch is released. I hope you're able to find a solution that fits your needs.
 
If you don't want the spell to be MUI, just use a few global variables. However, if you need it to be MUI, things become more fun:

You have a few options. I recommend using H2I/GetHandleId and either gamecache, a hashtable, or a timer stack in order to attach the data. The timer stack approach would require a script such as TimerUtils which is available at wc3c and requires the NewGen Pack in order to work.

As for gamecache + return bug/hashtable + GetHandleId, this is the second approach I would recommend if you are not willing to use the NewGen pack. Keep all your patch-dependent JASS code in one section so that only that section will need to be updated to work with the new patch.

The third approach, which is easily the most annoying to implement, would require global arrays for every data type being stored and a stack to keep track of unused indexes in these global arrays. When the caster starts the spell, retrieve an unused index and attach it to the unit with SetUnitUserData and add the unit to a global group of units that are currently under the effects of the spell. When the effect for a unit ends, reset the UnitUserData to 0 and remove the unit from the global group. The alternative for using UnitUserData and a unit group would be to use a global array to keep track of units under the effect of the spell and some smart indexing to keep things in order.

Of these approaches, if you can use JassHelper in the NewGen pack, I recommend using structs with TimerUtils. This uses H2I, but a 1.24+ version is also supplied on the site to allow quick updating when the patch is released. I hope you're able to find a solution that fits your needs.

I'm kind of cowaring for that indexing system, my own idea was to use a struct (just trying to learn vJass now) that handles all the variables, and then attatch the struct to the units custom value. Thing is i'm still very new to vJass, and don't completely know how how to do that in a proper way, so if someone could give me some advice that would be nice.

(and yes, i have done the tutorials on thehelper.net)
 
Status
Not open for further replies.
Top