Combo Point System; Was Working, Now Fails

WolfieeifloW

WEHZ Helper
Reaction score
372
I have no idea what changed that could have wrecked this system.
It was working completely fine, and now it doesn't.

What's supposed to happen:
A unit uses a certain spell (Mangle or Claw) and gets a 'combo point'.
Combo points range from 0-5.
So, I made 6 spells with different icons/descriptions/models to represent these combo points.

When the hero uses Mangle/Claw, it's combo points get increased by 1 up to a maximum of 5.
The system removes the current combo point ability, and gives it the next rank (Again, up to 5).

The problem?
On the first attack, it just stays with the 0 ability.
On the second attack, it keeps the 0 ability, AND gives the hero the 1 ability.
On the third, it keeps 0, 1, and gives the hero the 2 ability.

However, according to the BJDebug's, it should be working perfectly:
JASS:
scope ComboPoints initializer CPInit

    globals
        integer array combo
    endglobals    

    private function Conditions takes nothing returns boolean
        local unit u
        local integer ud
        
        call BJDebugMsg("Running")        
        if (GetUnitTypeId(GetTriggerUnit()) == feralDruid and GetSpellAbilityId() == mangle or GetSpellAbilityId() == claw) then
            call BJDebugMsg("Passed")
            set u = GetTriggerUnit()
            set ud = GetUnitUserData(u)
            call BJDebugMsg("Before UD- " + I2S(ud))
            if (ud != 5) then
                call BJDebugMsg("Passed2")
                call UnitRemoveAbility(u, combo[ud])
                call SetUnitUserData(u, ud + 1)
                call BJDebugMsg("After UD- " + I2S(GetUnitUserData(u)))
                call UnitAddAbility(u, combo[ud])
            endif
        endif
        set u = null
        return false
    endfunction

    private function CPInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer index = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope

The outcome of the debugs for the first cast are:
Running
Passed
Before UD- 0
Passed2
After UD- 1
And for the second cast:
Running
Passed
Before UD- 1
Passed2
After UD- 2
And so on.
According to these, it should be removing the current ability, and replacing it with the next one up, which it's not.
 

Solmyr

Ultra Cool Member
Reaction score
30
And where is your array filled?
JASS:
set combo[1] = 'A000'
set combo[2] = 'A001'
set combo[3] = 'A002'
set combo[4] = 'A003'
set combo[5] = 'A005'

or anything similar to that?
 

luorax

Invasion in Duskwood
Reaction score
67
JASS:
if (ud != 5) then
    call BJDebugMsg("Passed2")
    call UnitRemoveAbility(u, combo[ud])
    call SetUnitUserData(u, ud + 1)
    call BJDebugMsg("After UD- " + I2S(GetUnitUserData(u)))
    call UnitAddAbility(u, combo[ud])
endif


should be:
JASS:
if (ud != 5) then
    call BJDebugMsg("Passed2")
    call UnitRemoveAbility(u, combo[ud])
    call SetUnitUserData(u, ud + 1)
    call BJDebugMsg("After UD- " + I2S(GetUnitUserData(u)))
    call UnitAddAbility(u, combo[ud+1])
endif


What happened? You changed the unit's user data. It's good, but as array index, you used a local variable (ud) which remained the same.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Ah, yes..
JASS:
scope ComboPoints initializer CPInit

    globals
        integer array combo
    endglobals    

    private function Conditions takes nothing returns boolean
        local unit u
        local integer ud
        
        call BJDebugMsg("Running")        
        if (GetUnitTypeId(GetTriggerUnit()) == feralDruid and GetSpellAbilityId() == mangle or GetSpellAbilityId() == claw) then
            call BJDebugMsg("Passed")
            set u = GetTriggerUnit()
            set ud = GetUnitUserData(u)
            call BJDebugMsg("Before UD- " + I2S(ud))
            if (ud != 5) then
                call BJDebugMsg("Passed2")
                call UnitRemoveAbility(u, combo[ud])
                call SetUnitUserData(u, ud + 1)
                call BJDebugMsg("After UD- " + I2S(GetUnitUserData(u)))
                call UnitAddAbility(u, combo[GetUnitUserData(u)])
            endif
        endif
        set u = null
        return false
    endfunction

    private function CPInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer index = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope

That works fine now :)

My damage trigger for the combo point user spell doesn't work either though..
I've looked over it and can't find why..
JASS:
scope FerociousBite initializer FBnit

    private function Chance takes integer level returns integer
        return level * 2
    endfunction

    private function Damage takes integer level returns real
        return (level * 0.5) + 0.5
    endfunction
    
    private function Conditions takes nothing returns boolean
        local real fbDamage
        local unit u
        local integer ud
        
        if (GetSpellAbilityId() == ferociousBite and GetUnitUserData(u) > 0) then
            set u = GetTriggerUnit()
            set ud = GetUnitUserData(u)
            set fbDamage = (GetHeroAgi(u, true) * Damage(ud))
            call UnitDamageTarget(u, GetSpellTargetUnit(), fbDamage, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            call UnitRemoveAbility(u, combo[ud])
            if (GetRandomInt(1, 100) <= Chance(GetUnitAbilityLevel(u, ferociousBite)) and ud >= 4) then
                call SetUnitUserData(u, ud - 3)
            else
                call SetUnitUserData(u, 0)
            endif
            call UnitAddAbility(u, combo[GetUnitUserData(u)])
        elseif (GetSpellAbilityId() == ferociousBite and ud <= 0) then
            call IssueImmediateOrder(u, "stop")
            call SimError(GetOwningPlayer(u), "You need at least one combo point!")
        endif
        set u = null
        return false
    endfunction

    private function FBnit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer index = 0
        
        loop    
            call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope

It's based off 'Channel', but again, it worked before and now it doesn't.
 

Magthridon96

Member
Reaction score
2
Don't use SetUnitUserData, only GetUnitUserData.
Using SetUnitUserData would break a lot of systems like AIDS, UnitIndexer, UnitIndexer GUI, etc...
 

Romek

Super Moderator
Reaction score
963
You'll almost certainly end up using some sort of indexing system, or a resource which uses some sort of indexing.
I too, would strongly recommend using AIDS and an array instead of UnitUserData, and saving yourself the trouble of converting everything later. ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top