Hashtable help/questions

afisakov

You can change this now in User CP.
Hello, I am very new to using hashtables
some Hopefully quick questions
1) does "RemoveSavedHandle" remove the unit like it sounds, or only destroy the reference and leave unit itself intact
2) does LoadItemHandle truly load/create something that needs to be removed? or is it more similar to referencing a variable
e.g. can I use SetUnitPosition(LoadUnitHandle(1,2), x, y) or do I need to use
Code:
set dummy= LoadUnitHandle(1,2)
call SetUnitPosition(dummy, x, y)
set dummy= null
 

GFreak45

I didnt slap you, i high 5'd your face.
Hashtables are extremely similar to variables with a few key differences and similarities:

Similarly:
Loading handles can replace the use of a variable of the same type
Setting null is the equivelant to removing a saved handle, however, the saved handle is not scope restricted, so it should be released when the handle is destroyed rather than at the end of a function etc

Differences (aka Efficiency vs Utility):
As everyone knows variables are relatively limited as far as array max size and global definitions etc, this is where hashtables are wonderfull... They are like a seemingly endless nested array that can use text values instead similar to json key value pairs etc.

Where hashtables fall short is their efficiency... while they have almost the same exact uses as variables it is less efficienct to save and load them than it is to access a variable, making them more usefull for thinks like long term storage. Typically if values are to be used more than once in a single function they are loaded at the beginning, and set to a local variable.
 

afisakov

You can change this now in User CP.
Can someone take a look at my trigger and see if I did this right?
I already tested that it functions in-game, but wanted to check thtat did not miss any leaks/cleanups, especiailly in regards to hashtables.

The spell creates ice pillars around target point, then they push inwards, compressing any units inside, deals damage and applies debuff at very end.

Activation
Code:
globals
   location array PillarSpot
   hashtable Pillars= InitHashtable()
endglobals

function Trig_Ice_Pillars_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A098'
endfunction

function Trig_Ice_Pillars_Actions takes nothing returns nothing
local integer pid= GetPlayerId(GetOwningPlayer(GetTriggerUnit())) + 1
local integer i=0
local unit u
local real x
local real y
local real angle
local real range= (240+80*GetUnitAbilityLevel(GetTriggerUnit(),'A098') )*(1.+ BoostValue[pid]*.5)
   set PillarSpot[pid]=GetSpellTargetLoc()
   set x= GetLocationX(PillarSpot[pid])
   set y= GetLocationY(PillarSpot[pid])
   loop
       exitwhen i>7
       set angle=bj_PI * 2 * i / 8.
       set u= CreateUnit(Player(15), 'e0xe', x + range*Cos(angle), y + range*Sin(angle), bj_UNIT_FACING)
       call UnitApplyTimedLife(u, 'BTLF', 10)
       set bj_lastCreatedEffect = AddSpecialEffectTarget("Doodads\\Icecrown\\Rocks\\IceBlock\\IceBlock3.mdl", u, "origin")
       call SaveEffectHandle(Pillars, pid, i+8, bj_lastCreatedEffect)
       call SaveUnitHandle(Pillars, pid, i, u)
       set u= null
       set i= i+1
   endloop
   call EnableTrigger(gg_trg_Ice_Pillars_Periodic)
endfunction

//===========================================================================
function InitTrig_Ice_Pillars takes nothing returns nothing
    set gg_trg_Ice_Pillars=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Ice_Pillars, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Ice_Pillars, Condition(function Trig_Ice_Pillars_Conditions))
    call TriggerAddAction(gg_trg_Ice_Pillars, function Trig_Ice_Pillars_Actions)
endfunction
Effect
Code:
function Trig_Ice_Pillars_Periodic_Actions takes nothing returns nothing
local integer i=0
local integer i2
local unit dummy
local unit target
local boolean activeCasts=false
local real boost
local real dist
local real angle
local real x
local real y
local group innerG
local group outerG
local real jump= 9
local real dmg
loop
   exitwhen i > 8
   set x=GetLocationX(PillarSpot[i])
   set y=GetLocationY(PillarSpot[i])
   if x!=0 then
//
   set boost= 1. +BoostValue[i]
   set dummy= LoadUnitHandle(Pillars, i, 0)
   set dist= SquareRoot( (GetUnitX(dummy)-x)*(GetUnitX(dummy)-x) + (GetUnitY(dummy)-y)*(GetUnitY(dummy)-y) )
   set dummy= null
   if dist > 160 then
       set outerG=GetUnitsInRangeOfLocMatching(dist * boost, PillarSpot[i], Condition(function ishostileUnit))
       set dist= dist -jump
       set innerG=GetUnitsInRangeOfLocMatching(dist , PillarSpot[i], Condition(function ishostileUnit))
       set activeCasts=true
       set i2= 0
       loop //move dummy effects
           exitwhen i2>7
           set angle= bj_PI *2 *i2 / 8.
           call SetUnitPosition(LoadUnitHandle(Pillars, i, i2), x +dist*Cos(angle), y +dist*Sin(angle) )
           set i2=i2+1
       endloop
   
       set dist=dist*.9
       loop //move outlier units inward
           set target=FirstOfGroup(outerG)
           exitwhen target == null
           call GroupRemoveUnit(outerG, target)
           if IsUnitInGroup(target, innerG)==false then
               set angle=Atan2((GetUnitY(target)-y), (GetUnitX(target)-x))
               call SetUnitPosition(target, x +dist*Cos(angle), y +dist*Sin(angle) )
               call SetUnitPathing(target, false)
           endif
           set target=null
       endloop
       call DestroyGroup(outerG)
       set outerG= null
       call DestroyGroup(innerG)
       set innerG= null
   else
       set i2=0
       loop
           exitwhen i2>7
           call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", GetUnitX(LoadUnitHandle(Pillars, i, i2)), GetUnitY(LoadUnitHandle(Pillars, i, i2)) ))
           call DestroyEffect(LoadEffectHandle(Pillars, i, i2+8))
           call RemoveUnit(LoadUnitHandle(Pillars, i, i2))
           set i2= i2+1
       endloop
       call FlushChildHashtable(Pillars,i)
       call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", PillarSpot[i] ))
       set outerG=GetUnitsInRangeOfLocMatching(dist * boost, PillarSpot[i], Condition(function ishostile))
       call RemoveLocation(PillarSpot[i])
       set dmg= GetHeroInt(udg_PlayersCharacter[i],true)*GetUnitAbilityLevel(udg_PlayersCharacter[i],'A098')*boost
       loop // damage at the end
           set target=FirstOfGroup(outerG)
           exitwhen target == null
           call GroupRemoveUnit(outerG, target)
           call SetUnitPathing(target, true)
           call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", GetUnitX(target), GetUnitY(target)))
           if GetUnitAbilityLevel(target, 'B01G')>0 then
               call UnitDamageTargetBJ(udg_PlayersCharacter[i], target, dmg*1.5*boost, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC)
               call IssueTargetOrder(CreateDummyWithAbilityCoord(GetOwningPlayer(udg_PlayersCharacter[i]) , 'A0DS' , R2I(3*boost) , GetUnitX(target), GetUnitY(target)), "thunderbolt", target)
           else
               call UnitDamageTargetBJ(udg_PlayersCharacter[i], target, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC)
               call IssueTargetOrder(CreateDummyWithAbilityCoord(GetOwningPlayer(udg_PlayersCharacter[i]) , 'A0DS' , R2I(2*boost) , GetUnitX(target), GetUnitY(target)), "thunderbolt", target)
           endif
           set target=null
       endloop
       call DestroyGroup(outerG)
       set outerG= null
   endif
//
   endif
   set i=i + 1
endloop

if activeCasts == false then
   call DisableTrigger(gg_trg_Ice_Pillars_Periodic)
endif
endfunction

//===========================================================================
function InitTrig_Ice_Pillars_Periodic takes nothing returns nothing
    set gg_trg_Ice_Pillars_Periodic=CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_Ice_Pillars_Periodic, 0.03)
    call TriggerAddAction(gg_trg_Ice_Pillars_Periodic, function Trig_Ice_Pillars_Periodic_Actions)
endfunction

Thank you in advance
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • C Cherry.Grove:
    So what's the whole reforged situation? Do we have to run the classic version bootleg now?
  • C Cherry.Grove:
    My boyfriend is super into Bethesda modding so I'm probably going to join him in that for a bit, then move on to making mobile/browser games.
  • C Cherry.Grove:
    I mostly just want to look at my old projects because I know I posted uploads on here somewhere.
  • C Cherry.Grove:
    My one game was basically Among Us but you sabotaged an entire medieval city simulated drastically inefficiently with dynamic NPCs :S
  • C Cherry.Grove:
    of course I never finished it x D
  • jonas jonas:
    xD
  • jonas jonas:
    I think you can still run the original game, just there's a chance your map won't work with the newer patches
  • jonas jonas:
    what development framework have you been looking at for mobile development?
  • jonas jonas:
    I'm currently creating (as a hobby) a space invaders like game for mobile using Xamarin, after starting a few larger projects that I also may not have finished :rolleyes::p
  • The Helper The Helper:
    Awesome! you should look at the Atari VCS platform it does not have a huge user base but the one it has is super active at around 11k and they have no games in there store
  • The Helper The Helper:
    basically it is linux
  • The Helper The Helper:
    OMG it is BanLord as Blackveiled on the forum
  • The Helper The Helper:
    what is up buddy
  • jonas jonas:
    thanks for the tip, that sounds cool. Never heard about the VCS before but seems like it should be a good match
  • tom_mai78101 tom_mai78101:
    The winter vacation left a toll on me. I missed staying up late and sleeping in late.
  • C Cherry.Grove:
    i haven't looked into it yet
  • C Cherry.Grove:
    If I could use something Python compatible it would save me some learning
  • C Cherry.Grove:
    But Unity might be easiest
  • C Cherry.Grove:
    looking at old posts here makes me happy. Makes me be all like "wow I was pretty smart in 2009"
  • C Cherry.Grove:
    mostly failing at life through adulthood really demotivated me for a while
  • C Cherry.Grove:
    ....what I don't get is why the fuck they would force us to permanently convert to a version of the game everyone fucking hated : \
  • C Cherry.Grove:
    Raid Shadow Legends texture pack smh
  • jonas jonas:
    Most people fail at life throughout their adulthood. Sometimes we get to learn from it. Usually it just feels like crap.
  • The Helper The Helper:
    What does not kill you makes you stronger is what they say

    Members online

    Affiliates

    Hive Workshop NUON Dome
    Top