Simple Toggleable Spell System 0.0.1

This bundle is marked as pending. It has not been reviewed by a staff member yet.
  • Like
Reactions: Mythic
Simple Toggleable Spell System V.0.0.1

This system allow you create a toggleable spell. A toggleable spell is a spell that can have two possible values or states like ON/OFF, ACTIVE/INACTIVE or FIRE/ICE. This state can have it own tooltip, extended tooltip and icon!

The system have a CALLBACK like behaviour, were you can check the change of the state and do some
functions.



How it works?

1. Create the globals variable for your base spell. In the system i use channel based ability
- LIBRARY trigger -

2. Create the variables with the tooltip, extended tooltip and the iconpath for the spell ON state and OFF state.
- TOGGLEABLES trigger -

3. Create the toggleable spell.
- TOGGLEABLES trigger -

4. Manage the cast of the spell and the callback
- CAST trigger -

5. Enjoy



Pending


1. More than two states


Triggers


1. Find the library and the function.


JASS:
globals
    hashtable toggleableSpells = InitHashtable()
    integer TEST_SPELL = 'A000'
    integer STRENGTH_SPELL = 'A001'

endglobals

library STSS

   //  * onTOoff: you have the ON state, description have turn off
   //  * offTOon: you have the OFF state, description have turn on

   function CreateToggleableSpell takes integer spell, string onTOoffT, string onTOoffET, string onTOoffI, string offTOonT, string offTOonET, string offTOonI returns nothing
      call SaveBoolean(toggleableSpells, spell, 0, false)
      call SaveStr(toggleableSpells, spell, 1, onTOoffT)
      call SaveStr(toggleableSpells, spell, 2, onTOoffET)
      call SaveStr(toggleableSpells, spell, 3, onTOoffI)
      call SaveStr(toggleableSpells, spell, 4, offTOonT)
      call SaveStr(toggleableSpells, spell, 5, offTOonET)
      call SaveStr(toggleableSpells, spell, 6, offTOonI)
   endfunction

   function ToggleSpell takes unit u, integer spell returns boolean
       local integer spellLevel = GetUnitAbilityLevel(u, spell) - 1
       local boolean currentState = LoadBoolean(toggleableSpells, spell, 0)
       local string tooltip
       local string eTooltip
       local string icon

       if (currentState == true) then
           set currentState = false
           call SaveBoolean(toggleableSpells, spell, 0, currentState)
           set tooltip = LoadStr(toggleableSpells, spell, 4)
           set eTooltip = LoadStr(toggleableSpells, spell, 5)
           set icon = LoadStr(toggleableSpells, spell, 6)

       else
           set currentState = true
           call SaveBoolean(toggleableSpells, spell, 0, currentState)
           set tooltip = LoadStr(toggleableSpells, spell, 1)
           set eTooltip = LoadStr(toggleableSpells, spell, 2)
           set icon = LoadStr(toggleableSpells, spell, 3)

       endif

       call BlzSetAbilityTooltip(spell, tooltip, spellLevel)
       call BlzSetAbilityExtendedTooltip(spell, eTooltip, spellLevel)
       call BlzSetAbilityIcon(spell, icon)

       return currentState
   endfunction
endlibrary

2. Find example of creation of the toggleable spell


JASS:
function tgca takes nothing returns nothing

    local integer spell
    local string onTOoffT
    local string onTOoffET
    local string onTOoffI
    local string offTOonT
    local string offTOonET
    local string offTOonI

    // HELP
    //  spell tooltip and icon need be per default: OFF
    //  in this case Sell is green icon, and hire is red
    //  * onTOoff: here you need the ON icon and tooltip
    //  * offTOon: here you need the OFF icon and tooltip

    // CONFIGURATION START HERE
    set spell = 'A000'
    set onTOoffT = "TURN SPELL |cffff0000OFF|r"
    set onTOoffET = "HotKey [|cffffff00Q|r]|nCURREN STATE: |cff00ff00ON|r"
    set onTOoffI = "ReplaceableTextures\\CommandButtons\\BTNSell.blp"
    set offTOonT = "TURN SPELL |cff00ff00ON|r"
    set offTOonET = "HotKey [|cffffff00Q|r]|nCURREN STATE: |cffff0000OFF|r"
    set offTOonI = "ReplaceableTextures\\CommandButtons\\BTNHire.blp"
    call CreateToggleableSpell(spell, onTOoffT, onTOoffET, onTOoffI, offTOonT, offTOonET, offTOonI)
    // CONFIGURATION END HERE

    // CONFIGURATION START HERE
    set spell = 'A001'
    set onTOoffT = "Rest"
    set onTOoffET = "HotKey [|cffffff00W|r]|nCURREN STATE: |cff00ff00ON|r"
    set onTOoffI = "ReplaceableTextures\\CommandButtons\\BTNSleep.blp"
    set offTOonT = "Get More Strength"
    set offTOonET = "HotKey [|cffffff00W|r]|nCURREN STATE: |cffff0000OFF|r"
    set offTOonI = "ReplaceableTextures\\CommandButtons\\BTNSerpentWard.blp"
    call CreateToggleableSpell(spell, onTOoffT, onTOoffET, onTOoffI, offTOonT, offTOonET, offTOonI)
    // CONFIGURATION END HERE

    call BJDebugMsg("|cffffff00Simple Toggleable Spell System|r By Allknowledge aka iam20842")
    call BJDebugMsg("1, Create a dummy spell like the example in  |cff00ffffobject editor|r")
    call BJDebugMsg("2. Save the raw code in global variable |cff00fffflibrary|r trigger")
    call BJDebugMsg("3. Create the toggleable spell |cff00fffftoggleables|r trigger")
    call BJDebugMsg("3.1 Needs on\\off tooltip")
    call BJDebugMsg("3.2 Needs on\\off extended tooltip")
    call BJDebugMsg("3.3 Needs on\\off icon")
    call BJDebugMsg("4. Manage the \"callback\", |cff00ffffcast|r trigger")
    call BJDebugMsg("5. Done")

endfunction

//===========================================================================
function InitTrig_TOGGLEABLES takes nothing returns nothing
    local trigger tg = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( tg, 0.00 )
    call TriggerAddAction( tg, function tgca )
endfunction


3. Find example of casting/managing the toggleable spell


JASS:
function tga takes nothing returns nothing
    local unit u
    local integer sp
    local boolean cs

    if ( GetSpellAbilityId() == TEST_SPELL) then

        set u = GetSpellAbilityUnit()
        set sp = GetSpellAbilityId()
        set cs = ToggleSpell(u, sp)

        if (cs == true) then
            call BJDebugMsg("Spell is on")
 
        else
            call BJDebugMsg("Spell is off")
        endif
    endif

    if ( GetSpellAbilityId() == STRENGTH_SPELL) then
        set u = GetSpellAbilityUnit()
        set sp = GetSpellAbilityId()
        set cs = ToggleSpell(u, sp)

        if (cs == true) then
            call BlzSetUnitIntegerField(u, UNIT_IF_STRENGTH, 9999)
        else
            call BlzSetUnitIntegerField(u, UNIT_IF_STRENGTH, 14)
        endif
    endif
    set u = null
 
 

endfunction

//===========================================================================
function InitTrig_CAST takes nothing returns nothing
    local trigger tg = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( tg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( tg, function tga )
endfunction
Contents

Simple Toggleable Spell System 0.0.1 (Map)

Top