• 🏆 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] Hashtables

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I've just learned how to use hashtables and I made a simple spell. But, as always, it isn't working and I'm posting it here so someone can tell me what's wrong with it.

JASS:
scope Mind initializer Init

globals

    private constant integer SPELL_ID = 'A000'
    private constant integer BUFF_ID = 'B000'
    private constant integer SLOW_ID = 'A001'
    private constant integer DUMMY_ID = 'h000'
    private constant real TIME = 10.00
    private hashtable h = InitHashtable()

endglobals

private function DMG takes integer lvl returns real
    return I2R(lvl * 5 + 5)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit c = LoadUnitHandle(h, 0, GetHandleId(t))
    local unit u = LoadUnitHandle(h, 1, GetHandleId(t))
    local integer i = LoadInteger(h, 2, GetHandleId(t))
    if GetUnitAbilityLevel(u, BUFF_ID) > 0 then
        call UnitDamageTarget(c, u, DMG(i), false, true, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    endif
    set t = null
    set c = null
    set u = null
endfunction

private function Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit c = GetTriggerUnit()
    local unit u = GetSpellTargetUnit()
    local unit d = CreateUnit(GetOwningPlayer(c), DUMMY_ID, GetUnitX(u), GetUnitY(u), 0.00)
    call UnitApplyTimedLife(d, 'BTLF', 3.00)
    call SaveUnitHandle(h, 0, GetHandleId(t), u)
    call SaveUnitHandle(h, 1, GetHandleId(t), c)
    call SaveInteger(h, 2, GetHandleId(t), GetUnitAbilityLevel(c, SPELL_ID))
    call UnitAddAbility(d, SLOW_ID)
    call IssueTargetOrder(d, "cripple", u)
    call TimerStart(t, 1.00, true, function Callback)
    call TriggerSleepAction(TIME)
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    set c = null
    set u = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction

endscope

Thanks in advance.
 
SaveStringBJ because blizzard had forgott the native xD

A BJ is just a bunch of other (or one) native(s) usually.
But a BJ cannot provide functionality that could not be achieved with natives.
Look at the contents of SaveStringBJ, it shows you what the native equivalent is.

JASS:
function SaveStringBJ takes string value, integer key, integer missionKey, hashtable table returns boolean
    return SaveStr(table, missionKey, key, value)
endfunction

I've just learned how to use hashtables and I made a simple spell. But, as always, it isn't working and I'm posting it here so someone can tell me what's wrong with it.

It would be helpful if you could elaborate on what is not working, because it could be hundreds of different things.
Anyways, AFAIK the error is coming from you destroying the timer. Don't pause it, or destroy it and make it non-periodic.
 
Level 8
Joined
Jul 28, 2008
Messages
211
But I pause and destroy the timer after 10 seconds. That shouldn't be the problem.

The spell does nothing. But, the dummy does cast the ability (you can see the effect).

EDIT: I just added BJDebug messages and the timer is ok. The problem is in the hashtables. I did something wrong. The callback trigger does happen, but the unit is never damaged.

EDIT 2: Problem solved. I was saving the caster unit and loading it as the target.
 
Status
Not open for further replies.
Top