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 havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Dismiss Notice
  6. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    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.

Simple Toggleable Spell System 0.0.1

Submitted by iam20842
This bundle is marked as pending. It has not been reviewed by a staff member yet.
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.


Code (vJASS):

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


Code (vJASS):

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


Code (vJASS):

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)