1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Need help with 2 spells.

Discussion in 'World Editor Help Zone' started by Narg666, Feb 3, 2012.

  1. Narg666

    Narg666

    Joined:
    Aug 30, 2009
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Hello everyone...

    I'm in need of help to make two spells of mine work properly

    First is a nova of lightning with dummies, everything works fine but when
    the dummy touches enemy units, nothing happens. Usually I use variables,
    but I tried to make with Hashtable, wich I'm not very familiar and I'm
    trying to learn it, with variables I would be able to create this spell
    easily, but I want to learn how Hashtables work. The dummy spell is just a purge.

    If someone can help, here goes the script of the first skill:



    Code (vJASS):
    function Trig_Twilight_of_the_Thunder_God_Conditions takes nothing returns boolean
        if ( not ( GetSpellAbilityId() == 'A0YF' ) ) then
            return false
        endif
        return true
    endfunction

    function TotTGCond1 takes nothing returns boolean
        return ( IsUnitAliveBJ(GetFilterUnit()) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false)
    endfunction

    function TotTGAct3 takes nothing returns nothing
            local unit U = LoadUnitHandleBJ(S2I("Caster"), S2I("TotTG"), udg_Hash)
            local unit T = GetEnumUnit()
            local real D = 25.00 + (25.00 * GetUnitAbilityLevel(U, 'A0YF'))
            local group G2 = LoadGroupHandleBJ( S2I("Affected"), S2I("TotTG"), udg_Hash )
            local location L = GetUnitLoc(T)
            if ( UnitHasItemOfTypeBJ(U, 'I03A') == true ) then
                set D = D + 25.00
            endif
            if IsUnitEnemy(T, GetOwningPlayer(U)) then
                call UnitDamageTargetBJ(U, T, D, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC)
                call CreateUnitAtLoc(GetOwningPlayer(U), 'u000', L, 0)
                call UnitAddAbility(GetLastCreatedUnit(), 'A0YG')
                call IssueTargetOrder( GetLastCreatedUnit(), "purge", T )
                call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 1.00 )
            endif
            call GroupAddUnit(G2, T)
            call SaveGroupHandleBJ( G2, S2I("Affected"), S2I("TotTG"), udg_Hash )
            call RemoveLocation(L)
            call DestroyGroup(G2)
            set U = null
            set T = null
    endfunction

    function TotTGAct2 takes nothing returns nothing
            local unit U = LoadUnitHandleBJ(S2I("Caster"), S2I("TotTG"), udg_Hash)
            local unit array D
            local integer I = 1
            local integer E = 18
            local location L1
            local location L2
            local group G
            local group G2 = LoadGroupHandleBJ( S2I("Affected"), S2I("TotTG"), udg_Hash )
            loop
                exitwhen I > E
                set D[I] = LoadUnitHandleBJ(S2I("Dummy") + I, S2I("TotTG"), udg_Hash )
                set L1 = GetUnitLoc(D[I])
                if ( UnitHasItemOfTypeBJ(U, 'I03A') == true ) then
                    set L2 = PolarProjectionBJ(L1, 25 + (5 * GetUnitAbilityLevel(U, 'A0YF')), GetUnitFacing(D[I]))
                else
                    set L2 = PolarProjectionBJ(L1, 15 + (5 * GetUnitAbilityLevel(U, 'A0YF')), GetUnitFacing(D[I]))
                endif
                call SetUnitPosition(D[I], GetLocationX(L2), GetLocationY(L2))
                set G = GetUnitsInRangeOfLocMatching(115.00, L2, Condition(function TotTGCond1))
                call GroupRemoveGroup(G2, G)
                call ForGroup(G, function TotTGAct3)
                set D[I] = null
                set I = I + 1
            endloop
            call SaveGroupHandleBJ( G2, S2I("Affected"), S2I("TotTG"), udg_Hash )
            set U = null
            call RemoveLocation(L1)
            call RemoveLocation(L2)
            call DestroyGroup(G)
            call DestroyGroup(G2)
    endfunction

    function TotTGAct1 takes nothing returns nothing
            local unit U = LoadUnitHandleBJ(S2I("Caster"), S2I("TotTG"), udg_Hash)
            local trigger T = CreateTrigger()
            local unit array D
            local integer I = 1
            local integer E = 18
            local location L = GetUnitLoc(U)
            local group G = CreateGroup()
            call SaveGroupHandleBJ( G, S2I("Affected"), S2I("TotTG"), udg_Hash )        
            loop
                exitwhen I > E
                set D[I] = CreateUnitAtLoc(GetOwningPlayer(U), 'u01C', L, (20 * I))
                call SetUnitScalePercent( D[I], 180.00, 180.00, 180.00 )
                call SetUnitFlyHeight(D[I], 10.00, 0.00)
                call UnitApplyTimedLife(D[I], 'BTLF', 2.50)
                call SaveUnitHandleBJ( D[I], S2I("Dummy") + I, S2I("TotTG"), udg_Hash )
                set D[I] = null
                set I = I + 1
            endloop
            call TriggerRegisterTimerEventPeriodic( T, 0.05 )
            call TriggerAddAction( T, function TotTGAct2 )
            call TriggerSleepAction(2.50)
            call DestroyGroup(G)
            call DestroyTrigger(T)
            set U = null
            call RemoveLocation(L)
    endfunction

    function Trig_Twilight_of_the_Thunder_God_Actions takes nothing returns nothing
            local unit U = GetTriggerUnit()
            call FlushChildHashtableBJ( S2I("TotTG"), udg_Hash )
            call SaveUnitHandleBJ( U, S2I("Caster"), S2I("TotTG"), udg_Hash )
            call TotTGAct1()
            set U = null
    endfunction

    //===========================================================================
    function InitTrig_Twilight_of_the_Thunder_God takes nothing returns nothing
        set gg_trg_Twilight_of_the_Thunder_God = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Twilight_of_the_Thunder_God, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( gg_trg_Twilight_of_the_Thunder_God, Condition( function Trig_Twilight_of_the_Thunder_God_Conditions ) )
        call TriggerAddAction( gg_trg_Twilight_of_the_Thunder_God, function Trig_Twilight_of_the_Thunder_God_Actions )
    endfunction


    And my second spell, I tried to create Dota's Cranium Basher... which is a item that gives a chance for bashing the enemy
    unit with 2 seconds cooldown, 25% chance for melee, 10% for ranged units. I tried to make it without using dummies
    to stun, so it can look much better for ranged units to stun (withou stunning before their projectile hits the enemy) and
    it can stun magic immune units. So I did the following:

    Created a copy of Bash spell, made it 100% chance and renamed it.
    Create the trigger when any unit is attacked and here it goes:

    Code (vJASS):
    function Trig_SmasherStun_Conditions takes nothing returns boolean
        if ( not ( UnitHasItemOfTypeBJ(GetAttacker(), 'I040') == true ) ) then
            return false
        endif
        if ( not ( IsUnitEnemy(GetTriggerUnit(), GetOwningPlayer(GetAttacker())) == true ) ) then
            return false
        endif
        if ( not ( IsUnitInGroup(GetAttacker(), udg_Item_SmasherCooldown) == false ) ) then
            return false
        endif
        return true
    endfunction

    function Trig_SmasherStun_Actions takes nothing returns nothing
            local unit U = GetAttacker()
            local integer chance = 0
            local integer roll = GetRandomInt(1, 100)
            call UnitRemoveAbility(U, 'A0YE')
            if IsUnitType(U, UNIT_TYPE_RANGED_ATTACKER) == true then
                set chance = 10
            elseif IsUnitType(U, UNIT_TYPE_MELEE_ATTACKER) == true then
                set chance = 25
            endif
            if roll <= chance then
                call UnitAddAbility(U, 'A0YE')
                call SetPlayerAbilityAvailable(GetOwningPlayer(U), 'A0YE', false)
                call GroupAddUnit(udg_Item_SmasherCooldown, U)
                call TriggerSleepAction(0.50)
                call UnitRemoveAbility(U, 'A0YE')
                call TriggerSleepAction(1.50)
                call GroupRemoveUnit(udg_Item_SmasherCooldown, U)
            endif
            set U = null
            set chance = 0
            set roll = 0
    endfunction

    //===========================================================================
    function InitTrig_SmasherStun takes nothing returns nothing
        set gg_trg_SmasherStun = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_SmasherStun, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddCondition( gg_trg_SmasherStun, Condition( function Trig_SmasherStun_Conditions ) )
        call TriggerAddAction( gg_trg_SmasherStun, function Trig_SmasherStun_Actions )
    endfunction


    But, the point is... if I remove the TriggerSleepAction, the trigger works but without cooldown, and if I use the SleepAct,
    the trigger fails and nothing works.

    Can someone help me? Thank you.
     
  2. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    First of all you should try to get rid of all the BJ functions, coloured in red.

    Have you initialized the hashtable?
     
  3. Narg666

    Narg666

    Joined:
    Aug 30, 2009
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Yes, I had... I initialized the hashtable in the Main trigger of the map.

    Everything works properly as I said, but when the dummy touches the unit, then... nothing happens!!

    This is a global Hashtable used for more than just one spell... The other spells works just fine, but they are much simple.

    BJ Functions is not my problem now, I will remove them eventually, but for now I need to make this spell work.
     
  4. Narg666

    Narg666

    Joined:
    Aug 30, 2009
    Messages:
    112
    Resources:
    0
    Resources:
    0
    *Bump*
     
  5. Narg666

    Narg666

    Joined:
    Aug 30, 2009
    Messages:
    112
    Resources:
    0
    Resources:
    0
    *Bump*