• 🏆 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] Help with converting spell to latest patch

Status
Not open for further replies.
Level 3
Joined
Mar 29, 2008
Messages
59
Help, I'm using an imported spell that uses LocalHandleVariables and I don't now how to convert it to the next patch. Its really important, so could someone help me with it?
JASS:
function Trig_Tunnel_Conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A02J'
endfunction

function TunnelDig takes nothing returns nothing
   local timer t = GetExpiredTimer()
   local unit u = GetHandleUnit(t,"u")
   local real z = GetHandleReal(t,"z")
   local real ang = GetHandleReal(t,"ang")
   local real dist = GetHandleReal(t,"dist")
   local real fxdist = GetHandleReal(t,"fxdist")
   local real x = GetUnitX(u)
   local real y = GetUnitY(u)
   local real newx = x + 20 * Cos(ang)
   local real newy = y + 20 * Sin(ang)
   local real newZ = GetXYZ(newx,newy)
   if  dist <= 10 or newZ > z+5  then
       call FlushHandleLocals(t)
       call DestroyTimer(t)	
   else
       if fxdist <= 0 then
          call AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",newx,newy)
       else
          call SetHandleReal(t,"fxdist",fxdist-20)
       endif
       call SetUnitPosition(u,newx,newy)
       call SetHandleReal(t,"dist",dist-20)
   endif
   set t = null
   set u = null
endfunction

function Trig_Tunnel_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local location loc =  GetSpellTargetLoc()
    call SetHandleHandle(t,"u",GetTriggerUnit())
    call SetHandleReal(t,"z",GetLocationZ(loc))
    call SetHandleReal(t,"ang",A2PXY(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),GetLocationX(loc),GetLocationY(loc))*3.14159/180)
    call SetHandleReal(t,"dist",D2PXY(GetLocationX(loc),GetLocationY(loc),GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit())))
    call SetHandleReal(t,"fxdist",100)
    call TimerStart(t,0.05,true,function TunnelDig)
    call RemoveLocation(loc)
    set loc = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Tunnel takes nothing returns nothing
    set gg_trg_Tunnel = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Tunnel, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Tunnel, Condition( function Trig_Tunnel_Conditions ) )
    call TriggerAddAction( gg_trg_Tunnel, function Trig_Tunnel_Actions )
endfunction
Thanks in advance.
Also, how do you stop subscribing from every thread you post in?
 
Level 11
Joined
Feb 22, 2006
Messages
752
Use GetHandleId() on a unit. It's the same thing as H2I. Since each unit (technically each handle object) has a unique handle id, you can use a unit's id as a key for the hashtable. So to "attach" something to a unit, just get the unit's handle id, then save whatever you want to attach to the hashtable using the handle id as the key. Then when you want to retrieve whatever you attached, just reference the unit's handle id as the key.
 
Level 2
Joined
Feb 13, 2009
Messages
20
the new hash table natives:
native StringHash takes string returns integer
native GetHandleId takes handle returns integer

native InitHashtable takes nothing returns hashtable

native SaveInteger takes hashtable table, integer parentKey, integer childKey, integer value returns nothing
native SaveReal takes hashtable table, integer parentKey, integer childKey, real value returns nothing
native SaveBoolean takes hashtable table, integer parentKey, integer childKey, boolean value returns nothing
native SaveStr takes hashtable table, integer parentKey, integer childKey, string value returns boolean
native SavePlayerHandle takes hashtable table, integer parentKey, integer childKey, player whichPlayer returns boolean
native SaveWidgetHandle takes hashtable table, integer parentKey, integer childKey, widget whichWidget returns boolean
native SaveDestructableHandle takes hashtable table, integer parentKey, integer childKey, destructable whichDestructable returns boolean
native SaveItemHandle takes hashtable table, integer parentKey, integer childKey, item whichItem returns boolean
native SaveUnitHandle takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean
native SaveAbilityHandle takes hashtable table, integer parentKey, integer childKey, ability whichAbility returns boolean
native SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean
native SaveTriggerHandle takes hashtable table, integer parentKey, integer childKey, trigger whichTrigger returns boolean
native SaveTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey, triggercondition whichTriggercondition returns boolean
native SaveTriggerActionHandle takes hashtable table, integer parentKey, integer childKey, triggeraction whichTriggeraction returns boolean
native SaveTriggerEventHandle takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean
native SaveForceHandle takes hashtable table, integer parentKey, integer childKey, force whichForce returns boolean
native SaveGroupHandle takes hashtable table, integer parentKey, integer childKey, group whichGroup returns boolean
native SaveLocationHandle takes hashtable table, integer parentKey, integer childKey, location whichLocation returns boolean
native SaveRectHandle takes hashtable table, integer parentKey, integer childKey, rect whichRect returns boolean
native SaveBooleanExprHandle takes hashtable table, integer parentKey, integer childKey, boolexpr whichBoolexpr returns boolean
native SaveSoundHandle takes hashtable table, integer parentKey, integer childKey, sound whichSound returns boolean
native SaveEffectHandle takes hashtable table, integer parentKey, integer childKey, effect whichEffect returns boolean
native SaveUnitPoolHandle takes hashtable table, integer parentKey, integer childKey, unitpool whichUnitpool returns boolean
native SaveItemPoolHandle takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean
native SaveQuestHandle takes hashtable table, integer parentKey, integer childKey, quest whichQuest returns boolean
native SaveQuestItemHandle takes hashtable table, integer parentKey, integer childKey, questitem whichQuestitem returns boolean
native SaveDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey, defeatcondition whichDefeatcondition returns boolean
native SaveTimerDialogHandle takes hashtable table, integer parentKey, integer childKey, timerdialog whichTimerdialog returns boolean
native SaveLeaderboardHandle takes hashtable table, integer parentKey, integer childKey, leaderboard whichLeaderboard returns boolean
native SaveMultiboardHandle takes hashtable table, integer parentKey, integer childKey, multiboard whichMultiboard returns boolean
native SaveMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey, multiboarditem whichMultiboarditem returns boolean
native SaveTrackableHandle takes hashtable table, integer parentKey, integer childKey, trackable whichTrackable returns boolean
native SaveDialogHandle takes hashtable table, integer parentKey, integer childKey, dialog whichDialog returns boolean
native SaveButtonHandle takes hashtable table, integer parentKey, integer childKey, button whichButton returns boolean
native SaveTextTagHandle takes hashtable table, integer parentKey, integer childKey, texttag whichTexttag returns boolean
native SaveLightningHandle takes hashtable table, integer parentKey, integer childKey, lightning whichLightning returns boolean
native SaveImageHandle takes hashtable table, integer parentKey, integer childKey, image whichImage returns boolean
native SaveUbersplatHandle takes hashtable table, integer parentKey, integer childKey, ubersplat whichUbersplat returns boolean
native SaveRegionHandle takes hashtable table, integer parentKey, integer childKey, region whichRegion returns boolean
native SaveFogStateHandle takes hashtable table, integer parentKey, integer childKey, fogstate whichFogState returns boolean
native SaveFogModifierHandle takes hashtable table, integer parentKey, integer childKey, fogmodifier whichFogModifier returns boolean
native SaveAgentHandle takes hashtable table, integer parentKey, integer childKey, agent whichAgent returns boolean
native SaveHashtableHandle takes hashtable table, integer parentKey, integer childKey, hashtable whichHashtable returns boolean


native LoadInteger takes hashtable table, integer parentKey, integer childKey returns integer
native LoadReal takes hashtable table, integer parentKey, integer childKey returns real
native LoadBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
native LoadStr takes hashtable table, integer parentKey, integer childKey returns string
native LoadPlayerHandle takes hashtable table, integer parentKey, integer childKey returns player
native LoadWidgetHandle takes hashtable table, integer parentKey, integer childKey returns widget
native LoadDestructableHandle takes hashtable table, integer parentKey, integer childKey returns destructable
native LoadItemHandle takes hashtable table, integer parentKey, integer childKey returns item
native LoadUnitHandle takes hashtable table, integer parentKey, integer childKey returns unit
native LoadAbilityHandle takes hashtable table, integer parentKey, integer childKey returns ability
native LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer
native LoadTriggerHandle takes hashtable table, integer parentKey, integer childKey returns trigger
native LoadTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey returns triggercondition
native LoadTriggerActionHandle takes hashtable table, integer parentKey, integer childKey returns triggeraction
native LoadTriggerEventHandle takes hashtable table, integer parentKey, integer childKey returns event
native LoadForceHandle takes hashtable table, integer parentKey, integer childKey returns force
native LoadGroupHandle takes hashtable table, integer parentKey, integer childKey returns group
native LoadLocationHandle takes hashtable table, integer parentKey, integer childKey returns location
native LoadRectHandle takes hashtable table, integer parentKey, integer childKey returns rect
native LoadBooleanExprHandle takes hashtable table, integer parentKey, integer childKey returns boolexpr
native LoadSoundHandle takes hashtable table, integer parentKey, integer childKey returns sound
native LoadEffectHandle takes hashtable table, integer parentKey, integer childKey returns effect
native LoadUnitPoolHandle takes hashtable table, integer parentKey, integer childKey returns unitpool
native LoadItemPoolHandle takes hashtable table, integer parentKey, integer childKey returns itempool
native LoadQuestHandle takes hashtable table, integer parentKey, integer childKey returns quest
native LoadQuestItemHandle takes hashtable table, integer parentKey, integer childKey returns questitem
native LoadDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey returns defeatcondition
native LoadTimerDialogHandle takes hashtable table, integer parentKey, integer childKey returns timerdialog
native LoadLeaderboardHandle takes hashtable table, integer parentKey, integer childKey returns leaderboard
native LoadMultiboardHandle takes hashtable table, integer parentKey, integer childKey returns multiboard
native LoadMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey returns multiboarditem
native LoadTrackableHandle takes hashtable table, integer parentKey, integer childKey returns trackable
native LoadDialogHandle takes hashtable table, integer parentKey, integer childKey returns dialog
native LoadButtonHandle takes hashtable table, integer parentKey, integer childKey returns button
native LoadTextTagHandle takes hashtable table, integer parentKey, integer childKey returns texttag
native LoadLightningHandle takes hashtable table, integer parentKey, integer childKey returns lightning
native LoadImageHandle takes hashtable table, integer parentKey, integer childKey returns image
native LoadUbersplatHandle takes hashtable table, integer parentKey, integer childKey returns ubersplat
native LoadRegionHandle takes hashtable table, integer parentKey, integer childKey returns region
native LoadFogStateHandle takes hashtable table, integer parentKey, integer childKey returns fogstate
native LoadFogModifierHandle takes hashtable table, integer parentKey, integer childKey returns fogmodifier
native LoadHashtableHandle takes hashtable table, integer parentKey, integer childKey returns hashtable

native HaveSavedInteger takes hashtable table, integer parentKey, integer childKey returns boolean
native HaveSavedReal takes hashtable table, integer parentKey, integer childKey returns boolean
native HaveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
native HaveSavedString takes hashtable table, integer parentKey, integer childKey returns boolean
native HaveSavedHandle takes hashtable table, integer parentKey, integer childKey returns boolean

native RemoveSavedInteger takes hashtable table, integer parentKey, integer childKey returns nothing
native RemoveSavedReal takes hashtable table, integer parentKey, integer childKey returns nothing
native RemoveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns nothing
native RemoveSavedString takes hashtable table, integer parentKey, integer childKey returns nothing
native RemoveSavedHandle takes hashtable table, integer parentKey, integer childKey returns nothing

native FlushParentHashtable takes hashtable table returns nothing
native FlushChildHashtable takes hashtable table, integer parentKey returns nothing
 
Last edited:
Level 2
Joined
Feb 13, 2009
Messages
20
given the following globals

hashtable tunnelhash = InitHashtable()
integer u = StringHash("u")
integer z = StringHash("z")
integer ang = StringHash("ang")
integer dist = StringHash("dist")
integer fxdist = StringHash("fxdist")

then:

JASS:
function Trig_Tunnel_Conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A02J'
endfunction

function TunnelDig takes nothing returns nothing
   local timer  exptimer = GetExpiredTimer()
   local integer t = GetHandleId(exptimer)
   local unit tu = LoadUnitHandle(tunnelhash, t,u)
   local real tz = LoadReal(tunnelhash,t,z)
   local real tang = LoadReal(tunnelhash,t,ang)
   local real tdist = LoadReal(tunnelhash,t,dist)
   local real tfxdist = LoadReal(tunnelhash,t,fxdist)
   local real x = GetUnitX(tu)
   local real y = GetUnitY(tu)
   local real newx = x + 20 * Cos(tang)
   local real newy = y + 20 * Sin(tang)
   local real newZ = GetXYZ(newx,newy)
   if tdist <= 10 or newZ > tz+5 then
       call FlushChildHashtable(tunnelhash,t)
       call DestroyTimer(exptimer)
   else
       if tfxdist <= 0 then
          call AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",newx,newy)
       else
          call SaveReal(tunnelhash, t,fxdist,tfxdist-20)
       endif
       call SetUnitPosition(tu,newx,newy)
       call SaveReal(tunnelhash,t,dist,tdist-20)
   endif
endfunction

function Trig_Tunnel_Actions takes nothing returns nothing
    local timer newtimer = CreateTimer()
    local integer t = GetHandleId(newtimer)
    local location loc = GetSpellTargetLoc()
    call SaveUnitHandle(tunnelhash,t,u,GetTriggerUnit())
    call SaveReal(tunnelhash,t,z,GetLocationZ(loc))
    call SaveReal(tunnelhash,t,ang,A2PXY(GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),GetLocationX(loc),GetLocationY(loc))*3.14159/180)
    call SaveReal(tunnelhash,t,dist,D2PXY(GetLocationX(loc),GetLocationY(loc),GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit())))
    call SaveReal(tunnelhash,t,fxdist,100)
    call TimerStart(newtimer,0.05,true,function TunnelDig)
    call RemoveLocation(loc)
    set loc = null
    set newtimer = null
endfunction

//===========================================================================
function InitTrig_Tunnel takes nothing returns nothing
    set gg_trg_Tunnel = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Tunnel, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Tunnel, Condition( function Trig_Tunnel_Conditions ) )
    call TriggerAddAction( gg_trg_Tunnel, function Trig_Tunnel_Actions )
endfunction
 
Level 4
Joined
Jul 9, 2008
Messages
88
Slightly off topic---
Can hashtables be reloaded like a filetype like gamecache?
e.g. it saves unit, a different game it loads the unit from the players PC
 
Status
Not open for further replies.
Top