1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  5. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  6. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  7. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  8. 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.

Trigger Viewer

HeroSimpleStatesMachine 0.0.1.w3x
Variables
WESTRING_VARIABLESCATEGORY
HSSM
HSSM Help
HSSM Globals
HSSM CreateStates
HSSM SaveHeroTable
HSSM Cast Dummy Spell
HSSM Example
Escribe debajo el código del guión personalizado especial para el mapa. El texto se incluirá en el guión del mapa después de declarar las variables y antes de los códigos de los detonadores.

		
Name Type Is Array Initial Value
CdA_caster unit No
CdA_damage real No
CdA_group group No
HSSM Help
  Events
    Map initialization
  Conditions
  Actions
    Custom script: call SetMapFlag(MAP_CHEATS, false)
    Visibility - Disable fog of war
    Visibility - Disable black mask
    Camera - .Apply. gg_cam_Camera_001 for Player 1 (Red) over 0 seconds
    Game - Display to (All players) for 30.00 seconds the text: Hero Simple Machine State By: |cffffff00allknowledge aka iam20842|r
    Quest - Display to (All players) the Quest Update message: Help Log (|cffffff00F9|r)
    Quest - Create a Required quest titled Help Log with the description Hero Simple Machine State By: |cffffff00allknowledge aka iam20842|rCast a dummy spell over a hero to apply an state while certain duration, using icon path ReplaceableTextures\CommandButtons\BTNAmbushDay.blp
    Quest - Mark (Last created quest) as Discovered
    Quest - Flash the quest dialog button
    Selection - Select Tavern 0000 <gen> for Player 1 (Red)
    Game - Display to (All players) for 30.00 seconds the text: Buy a Hero. Please.
globals

    hashtable heroesTable  = InitHashtable()
    hashtable statesTable = InitHashtable()
    hashtable timersTable = InitHashtable()

    integer STATE_STUN = 0
    integer STATE_POISON = 1
    integer STATE_PARALYSIS = 2
    integer STATE_SLEEP = 3
    integer STATE_BROKEN = 4
    integer STATE_ROOTED = 5
    integer STATE_SLOWED = 6
    integer STATE_DRAINED = 7
    integer STATE_CAPTURE = 8
    integer STATE_FROZEN = 9
    integer STATE_HEALED = 10

    integer SPELL_STATE_STUN = 'A000'
    integer SPELL_STATE_PARALYSIS = 'A001'
    integer SPELL_STATE_SLEEP = 'A002'
    integer SPELL_STATE_BROKEN = 'A003'

    integer SPELL_STATE_CLEAR = 'A006'
    integer SPELL_STATE_CHECK = 'A005'

    integer SPELL_STATE_STORMBOLT = 'A007'
    integer MAX_STATES

endglobals

    //
    // HeroSimpleStateMachine: Add custom temporarily state to an Hero.
    //

    //
    // How the magic happend?
    // 1. Save the state hash in statesTable using CreateState (Find the function explaination in: HSSM Globals Trigger)
    // 1. Create an global variable for the state using integer STATE_YOURCUSTOMSTATE = yourvalue in HSSM Globals Trigger
    // 2. Define a way to see the default value of the heroesTable for an Hero (Find a example in: HSSM SaveHeroTable Trigger)
    // 3. Create your custom spell
    // 3. Add your custom spell id like a global variable like this SPELL_STATE_YOURCUSTOMSTATE in HSSM Globals Trigger
    // 3.1 Use UnitAddState for add an state
    // 3.2 Use UnitRemoveState for remove an state
    // 3.3 Use UnitHasState if you want add an state only if hero already have another state, like sleep to awake
    // 3.4 Use UnitHasStateLeft if you want get the remaining time of an state
    // 3.5 Use UnitHasStateMsg for get a debug message of the state
    // 4. Combine your spells with the power of Hero Simple States Machine to add damage, times, or any bonus, checking if a unit have your custom state . see HSSM Example
   
    //
    // Explaining the HASHTABLES
    //

    //
    // * statesTable: save every custom state
    //
    //  Takes:
    //
    //   Parent: Integer -> state index
    //   Child:  0 -> Integer -> index
    //           1 -> String  -> name
    //           2 -> String  -> description
    //           3 -> Code -> stateCallbackFunction
    //   Value:  the correspondig
    //

    //
    // * heroesTable: save the every state of the hero and their values, default: 0
    //
    // Takes:
    //   Parent: Integer -> unit index
    //   Child:  Integer -> state index
    //  

    //
    // * timersTable: save the timer of the state (duration) for every unit+state
    //
    //  Takes:
    //
    //  Parent: Integer -> timer index
    //  Child:  1 -> Retrieve -> Integer -> unit index
    //          2 -> Retrieve -> Integer -> state index
    //
    //  Parent: Integer -> unit index
    //  Child:  Integer -> stateIndex -> Retrieve -> Timer -> currentTimer

    //
    // Explaining the functions
    //

    //
    // * TimerHandler: Create a timer that manage the duration of state, when it expire the state get zero
    //

    function TimerHandler takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer tid = GetHandleId(t)
        local integer uid = LoadInteger(timersTable, GetHandleId(t), 1)
        local integer sid = LoadInteger(timersTable, GetHandleId(t), 2)
        local string sn = LoadStr(statesTable, sid, 1)

        // CLEAR tid child data.
        call FlushChildHashtable(timersTable, tid)
   
        call SaveInteger(heroesTable, uid, sid, 0)
        call PauseTimer(t)
        call DestroyTimer(t)
        set t = null
       
        // DEBUG msg
        call BJDebugMsg("State: " + sn + " |cffff0000Expired|r")
    endfunction

    //
    // * CreateState: Create a new state.
    //
    //  Takes:
    //   integer i  -> index
    //   string  n  -> name
    //   string  d  -> description
    //
   
    function CreateState takes integer i, string n, string d returns nothing
        call SaveInteger(statesTable, i, 0, i)
        call SaveStr(statesTable,     i, 1, n)
        call SaveStr(statesTable,     i, 2, d)
    endfunction

    //
    // * UnitHasState: Get true or false from check does hero have state?
    //
    //  Takes:
    //   unit u  -> target unit
    //   integer sid -> state index
    //

    function UnitHasState takes unit u, integer s returns boolean
        local integer uid = GetHandleId(u)
        local integer sid = LoadInteger(statesTable, s, 0)
        local integer us = LoadInteger(heroesTable, uid, sid)
        local boolean flag = false

        if (us == 1) then
           set flag = true
        else
           set flag = false
        endif
 
        set u = null

        return flag
    endfunction

    //
    // * UnitHasStateLeft: Get the remaining time of the State from hero.
    //  
    //
    //  Takes:
    //   unit u  -> target unit
    //   integer sid -> state index
    //  Retrieves:
    //   real -> remaining time
     

    function UnitHasStateLeft takes unit u, integer s returns real
        local integer uid = GetHandleId(u)
        local integer sid = LoadInteger(statesTable, s, 0)
        local integer us = LoadInteger(heroesTable, uid, sid)
        local timer t = LoadTimerHandle(timersTable, uid, sid)
        local real tl = TimerGetRemaining(t)
       
        return tl

    endfunction

    //
    // * UnitHasStateMsg: Return a message with the current value of the hero state
    //
    //  Takes:
    //   unit u  -> target unit
    //   integer sid -> state index
    //  Retrieve:
    //   Custom message
    //

    function UnitHasStateMsg takes unit u, integer s returns nothing
        local integer uid = GetHandleId(u)
        local integer sid = LoadInteger(statesTable, s, 0)
        local string sn = LoadStr(statesTable, s, 1)
        local integer us = LoadInteger(heroesTable, uid, sid)
        local timer t = LoadTimerHandle(timersTable, uid, sid)
        local real tl = TimerGetRemaining(t)
       
        if (us == 1) then
           call BJDebugMsg("State: " + sn + " |cff00ff00ON|r" + " left: " + "|cffffff00" + R2S(tl) + "|r seconds" )
        else
           call BJDebugMsg("State: " + sn + " |cffff0000OFF|r")
        endif
        set u = null
    endfunction

    //
    // * UnitAddState: Set ON an state of a Hero
    //
    //  Takes:
    //   unit u  -> target unit
    //   integer sid -> state index
    //   real d  -> duration of the state
    //

    function UnitAddState takes unit u, integer s, real d returns nothing
        local integer uid = GetHandleId(u)
        local integer sid = LoadInteger(statesTable, s, 0)
        local string sn = LoadStr(statesTable, s, 1)

        local timer t = CreateTimer()
        local integer tid = GetHandleId(t)

        // Debug Message
        call BJDebugMsg("State: " + sn + " |cff00ff00ON|r" + " for: " + "|cffffff00" + R2S(d) + "|r seconds" )
     
        // SET hero + state => 1
        call SaveInteger(heroesTable, uid, sid, 1)
     
        // SAVE for hero + state => Timer
        call SaveTimerHandle(timersTable, uid, sid, t)

        // SAVE for timer + 1 => unit index
        call SaveInteger(timersTable, tid, 1, uid)

        // SAVE for timer + 2 => state index
        call SaveInteger(timersTable, tid, 2, sid)

        // START the timer
        call TimerStart(t, d, false, function TimerHandler)

        set u = null
        set t = null

    endfunction

    // * UnitRemoveState: Set OF an state of a Hero
    //
    //  Takes:
    //   unit u  -> target unit
    //   integer sid -> state index
    //

    function UnitRemoveState takes unit u, integer s returns nothing

        local integer sid = LoadInteger(statesTable, s, 0)
        local string sn = LoadStr(statesTable, s, 1)
        local integer uid = GetHandleId(u)

        local timer t = LoadTimerHandle(timersTable, uid, sid)
        local integer tid = GetHandleId(t)

        // Debug Message
        call BJDebugMsg("State: " + sn + " |cffff0000OFF|r")

        // SET hero + state => 0
        call SaveInteger(heroesTable, uid, sid, 0)
     
        // CLEAR tid child data.
        call FlushChildHashtable(timersTable, tid)

        call PauseTimer(t)
        call DestroyTimer(t)
   
        set t = null
        set u = null
        set t = null
    endfunction
 
function CreateStates takes nothing returns nothing
    call CreateState(0, "stun", "you get stunned")
    call CreateState(1, "poison", "you get stunned")
    call CreateState(2, "paralysis", "you get stunned")
    call CreateState(3, "sleep", "you get sleep")
    call CreateState(4, "broken", "you get broken")
    call CreateState(5, "rooted", "you get rooted")
    call CreateState(6, "slowed", "you get slowed")
    call CreateState(7, "drained", "you get drained")
    call CreateState(8, "capture", "you get capture")
    call CreateState(9, "frozen", "you get frozen")
    call CreateState(10, "healed", "you get healed")

    // Remember set the MAX_STATES
    set MAX_STATES = 11
endfunction

//===========================================================================
function InitTrig_HSSM_CreateStates takes nothing returns nothing
    local trigger tg = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( tg, 0.00 )
    call TriggerAddAction( tg, function CreateStates)
endfunction
function HSSM_SaveHeroTable_Actions takes nothing returns nothing
    local unit su = GetSoldUnit()
    local integer uid = GetHandleId(su)
    local integer i = 0
    call ClearTextMessages()
    // Set the default states zero
    loop
        call SaveInteger(heroesTable, uid, i, 0)
        set i = i + 1
        exitwhen i == MAX_STATES
    endloop

    set su = null
   
    call BJDebugMsg("You hero is ready for get custom state!")
    call BJDebugMsg("Use Q and select what state you want apply")
    call BJDebugMsg("Use W to get the current state of the target unit")

    call BJDebugMsg("Use E to get all the states cleared for the target unit")
    call BJDebugMsg("Use R without and with STUN state to see the magic")

endfunction

//===========================================================================
function InitTrig_HSSM_SaveHeroTable takes nothing returns nothing
    local trigger tg = CreateTrigger()
    call TriggerRegisterUnitEvent( tg, gg_unit_ntav_0000, EVENT_UNIT_SELL )
    call TriggerAddAction( tg, function HSSM_SaveHeroTable_Actions )
endfunction

 
function HSSM_Cast_Dummy_Spell_Actions takes nothing returns nothing
    local unit tu = GetSpellTargetUnit()
    local integer s = GetSpellAbilityId()
    local integer i = 0

    // STUN DEMO
    if (GetSpellAbilityId() == SPELL_STATE_STUN) then
        call UnitAddState(tu, 0, 10.0)
    endif

    // PARALYSIS DEMO
    if (GetSpellAbilityId() == SPELL_STATE_PARALYSIS) then
        call UnitAddState(tu, 2, 7.0)
    endif

    // SLEEP DEMO
    if (GetSpellAbilityId() == SPELL_STATE_SLEEP) then
        call UnitAddState(tu, 3, 20.0)
    endif

    // BROKEN DEMO
    if (GetSpellAbilityId() == SPELL_STATE_BROKEN) then
        call UnitAddState(tu, 5, 4.0)
    endif

    // CLEAR DEMO
    if (GetSpellAbilityId() == SPELL_STATE_CLEAR) then
        call ClearTextMessages()
        loop
            call UnitRemoveState(tu, i)
            set i = i + 1
            exitwhen i == MAX_STATES
        endloop
        call BJDebugMsg("All states Cleared")
    endif

    // CHECK DEMO
    if (GetSpellAbilityId() == SPELL_STATE_CHECK) then
        call BJDebugMsg("Current States")
        call ClearTextMessages()
        loop
            call UnitHasStateMsg(tu, i)
            set i = i + 1
            exitwhen i == MAX_STATES
        endloop
    endif

    set tu = null
endfunction

function InitTrig_HSSM_Cast_Dummy_Spell takes nothing returns nothing
    local trigger tg = CreateTrigger()
    local integer i = 0

    call TriggerAddAction(tg, function HSSM_Cast_Dummy_Spell_Actions)

    loop
        call TriggerRegisterPlayerUnitEvent(tg, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    exitwhen i == bj_MAX_PLAYERS
    endloop

endfunction
function HSSM_Example_Actions takes nothing returns nothing
    local unit tu = GetSpellTargetUnit()
    local unit c = GetSpellAbilityUnit()
    local integer s = GetSpellAbilityId()
    local real b = 250.0

    // StormBolt Demo
    if (GetSpellAbilityId() == SPELL_STATE_STORMBOLT) then
        if (UnitHasState(tu , STATE_STUN)) then
             // Pure Damage
            if(GetUnitState(tu, UNIT_STATE_LIFE) <= b) then
                call UnitDamageTarget( c, tu, 1000000000.00, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_ROCK_HEAVY_BASH)
            else
                call UnitDamageTarget( c, tu, b, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_ROCK_HEAVY_BASH)                
            endif
           
            call UnitRemoveState(tu, STATE_STUN)
            call BJDebugMsg("+250 pure damage bonus!")
           
        else
            call BJDebugMsg("Unit dont have STUN, bonus will not apply")
        endif
    endif

    set tu = null
    set c = null
endfunction

function InitTrig_HSSM_Example takes nothing returns nothing
    local trigger tg = CreateTrigger()
    local integer i = 0

    call TriggerAddAction(tg, function HSSM_Example_Actions)

    loop
        call TriggerRegisterPlayerUnitEvent(tg, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    exitwhen i == bj_MAX_PLAYERS
    endloop

endfunction