- Joined
- Mar 9, 2023
- Messages
- 43
Hello!
I really thought I was decent at hashtables, but I have an issue where a repeated function continuously identifies the ability 'A0CO' (dummy) from a unit saved in a hashtable, even if the ability is removed.
Here are the relevant functions:
What it does is creating a hashtable for a repeating timer for a specific unit, which is then increasing or resetting one of the hero's abilities depending on the hero's position.
It's linked to a jump which changes the position of the hero, thus resetting the level to 1. However, I am trying to make an optional condition which if true, prevents the lvl from resetting during the jump.
I've cleaned out my failed attempts at removing the ability. During the repeating timer I can add the 'A0CO' ability via an outside trigger, but not remove it. Is it possible to do without refreshing the SniperExposure(u) function?
Edit:
Solved! Here are the two working functions:
I really thought I was decent at hashtables, but I have an issue where a repeated function continuously identifies the ability 'A0CO' (dummy) from a unit saved in a hashtable, even if the ability is removed.
Here are the relevant functions:
JASS:
function Sniper_Exposure takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer t_id = GetHandleId(t)
local unit u = LoadUnitHandle(HASH, t_id, 'Snip')
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local integer lvl = GetUnitAbilityLevel(u, 'A0BQ')
local real x2 = LoadReal(HASH, t_id, 'SnpX')
local real y2 = LoadReal(HASH, t_id, 'SnpY')
//call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, "A0CO level: " + I2S(GetUnitAbilityLevel(u, 'A0CO')))
if GetUnitAbilityLevel(u, 'A0CO') >= 1 then
call SetUnitAbilityLevel(u,'A0BQ',lvl+1)
elseif (x2 == x and y2 == y) then
call SetUnitAbilityLevel(u, 'A0BQ', lvl + 1)
else
call SetUnitAbilityLevel(u, 'A0BQ', 1)
endif
call SaveReal(HASH, t_id, 'SnpX', x)
call SaveReal(HASH, t_id, 'SnpY', y)
set u = null
set t = null
endfunction
function SniperExposure takes unit u returns nothing
local timer t
local integer u_id = GetHandleId(u)
local real interval = 1.55 - (GetUnitAbilityLevel(u,'A04R') * 0.15)
local player p = GetOwningPlayer(u)
if LoadTimerHandle(HASH, u_id, 'SnpT') != null then
call DestroyTimer(LoadTimerHandle(HASH, u_id, 'SnpT'))
endif
if GetUnitAbilityLevel(u,'A04R') >= 1 then
set t = CreateTimer()
call SaveTimerHandle(HASH, u_id, 'SnpT', t)
call SaveUnitHandle(HASH, GetHandleId(t), 'Snip', u)
call TimerStart(t, interval, true, function Sniper_Exposure)
endif
set t = null
set p = null
endfunction
function Trig_SniperLearnExposure_Actions takes nothing returns nothing
local unit u = GetLearningUnit()
call SniperExposure(u)
set u = null
endfunction
What it does is creating a hashtable for a repeating timer for a specific unit, which is then increasing or resetting one of the hero's abilities depending on the hero's position.
It's linked to a jump which changes the position of the hero, thus resetting the level to 1. However, I am trying to make an optional condition which if true, prevents the lvl from resetting during the jump.
I've cleaned out my failed attempts at removing the ability. During the repeating timer I can add the 'A0CO' ability via an outside trigger, but not remove it. Is it possible to do without refreshing the SniperExposure(u) function?
Edit:
Solved! Here are the two working functions:
JASS:
function Sniper_Exposure takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer t_id = GetHandleId(t)
local integer count = LoadInteger(HASH, GetHandleId(t), 'SnpC')
local unit u = LoadUnitHandle(HASH, t_id, 'Snip')
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local integer lvl = GetUnitAbilityLevel(u, 'A0BQ')
local real x2 = LoadReal(HASH, t_id, 'SnpX')
local real y2 = LoadReal(HASH, t_id, 'SnpY')
if sniperMoving then
call SetUnitAbilityLevel(u,'A0BQ',lvl+1)
set count = count + 1
call SaveInteger(HASH, t_id, 'SnpC', count)
if count == 2 then
set sniperMoving = false
set count = 0
call SaveInteger(HASH, t_id, 'SnpC', count)
endif
elseif (x2 == x and y2 == y) then
call SetUnitAbilityLevel(u, 'A0BQ', lvl + 1)
else
call SetUnitAbilityLevel(u, 'A0BQ', 1)
endif
call SaveReal(HASH, t_id, 'SnpX', x)
call SaveReal(HASH, t_id, 'SnpY', y)
set u = null
set t = null
endfunction
function SniperExposure takes unit u returns nothing //remember that this function is called first from a different one
local timer t
local integer u_id = GetHandleId(u)
local integer count
local real interval = 1.55 - (GetUnitAbilityLevel(u,'A04R') * 0.15)
local player p = GetOwningPlayer(u)
if LoadTimerHandle(HASH, u_id, 'SnpT') != null then
call FlushChildHashtable(HASH, GetHandleId(LoadTimerHandle(HASH, u_id, 'SnpT')))
call DestroyTimer(LoadTimerHandle(HASH, u_id, 'SnpT'))
endif
if GetUnitAbilityLevel(u,'A04R') >= 1 then
set t = CreateTimer()
call SaveTimerHandle(HASH, u_id, 'SnpT', t)
set count = LoadInteger(HASH, GetHandleId(t), 'SnpC')
if count == 0 then
call SaveInteger(HASH, GetHandleId(t), 'SnpC', count)
endif
call SaveUnitHandle(HASH, GetHandleId(t), 'Snip', u)
call TimerStart(t, interval, true, function Sniper_Exposure)
endif
set t = null
set p = null
endfunction
Last edited: