• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Aquiring Abilities with Items

Level 5
Joined
Aug 8, 2007
Messages
112
I want to just submit this, as it was in one of my maps and I think that it can be quite useful to some, useless to others.

This is a system I used to aquire abilities / upgrade abilities through buying items. eg. You buy an item called "Avatar" and you will get it to Level 1 or Level 2 if you already have it.

Here are the variables that you are going to need:
Key:

[*]: Variable wth array the size of the number of players
S_: String Variable
I_: Integer Variable
OA1: Offensive Ability 1
OA2: " " 2
DA1: Defensive Ability 1
DA2: " " 2
S_OA1[*]
S_OA2[*]
S_DA1[*]
S_DA2[*]
I_OA1[*]
I_OA1[*]
I_DA1[*]
I_DA2[*]

The reason why you need strings is because it will show the player what the name of their for example first ability. If S_OA1[1] is Avatar, Avatar is Player 1's first offensive ability.

The reason why you need integers is to how the player their level of the ability. eg. If I_OA1[1] is 6, it means that Player 1's first offensive ability is Level 6.

Okay, unless you have lost me, you are doing well.
PS: The Strings and Integers of he abilities can be shown to a player by using a command such as:

  • Ability Stats
    • Events
      • Player - Player 1 (Red) types a chat message containing -as as An exact match
      • Player - Player 2 (Blue) types a chat message containing -as as An exact match
      • Player - Player 3 (Teal) types a chat message containing -as as An exact match
      • Player - Player 4 (Purple) types a chat message containing -as as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -as as An exact match
      • Player - Player 6 (Orange) types a chat message containing -as as An exact match
      • Player - Player 7 (Green) types a chat message containing -as as An exact match
      • Player - Player 8 (Pink) types a chat message containing -as as An exact match
    • Conditions
    • Actions
      • Cinematic - Clear the screen of text messages for (Player group((Triggering player)))
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: |c0080FF80Ability S...
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: <Empty String>
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: (|c0080FF80Offensive Ability 1: + (S_OA1[(Player number of (Triggering player))] + ( Level + (String(I_OA1[(Player number of (Triggering player))])))))
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: (|c0080FF80Offensive Ability 2: + (S_OA2[(Player number of (Triggering player))] + ( Level + (String(I_OA2[(Player number of (Triggering player))])))))
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: (|c0080FF80Defensive Ability 1: + (S_DA1[(Player number of (Triggering player))] + ( Level + (String(I_DA1[(Player number of (Triggering player))])))))
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: (|c0080FF80Defensive Ability 2: + (S_DA2[(Player number of (Triggering player))] + ( Level + (String(I_DA2[(Player number of (Triggering player))])))))
      • Game - Display to (Player group((Triggering player))) for 25.00 seconds the text: (|c0080FF80Ultimate Ability: + (S_ULTI[(Player number of (Triggering player))] + ( Level + (String(I_ULTI[(Player number of (Triggering player))])))))
That is one way...

Now to the main part, upgrading and setting the abilities.

This may be one way, but I know of many other ways.
Here is the easiest way to do this method:

  • SetAbils
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set I_DA1[(Integer A)] = 0
          • Set I_DA2[(Integer A)] = 0
          • Set I_OA1[(Integer A)] = 0
          • Set I_OA2[(Integer A)] = 0
          • Set S_DA1[(Integer A)] = <Empty String>
          • Set S_DA2[(Integer A)] = <Empty String>
          • Set S_OA1[(Integer A)] = <Empty String>
          • Set S_OA2[(Integer A)] = <Empty String>
This will make all the Variables empty, as it is necessary to keep them empty.

NOTE: The Strings are not set to "<Empty String>", that is what show up when it is copletely blank.

Here is how to upgrade the abilities (In this case, only the Offensive Abilities):

  • Upgrading Offensive
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Stun
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Stun (OA) for (Triggering unit)) Less than 6
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • S_OA1[(Player number of (Owner of (Triggering unit)))] Equal to (Name of (Item being manipulated))
                • Then - Actions
                  • Unit - Set level of Stun (OA) for (Triggering unit) to ((Level of Stun (OA) for (Triggering unit)) + 1)
                  • Set I_OA1[(Player number of (Owner of (Triggering unit)))] = (I_OA1[(Player number of (Owner of (Triggering unit)))] + 1)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • S_OA2[(Player number of (Owner of (Triggering unit)))] Equal to (Name of (Item being manipulated))
                • Then - Actions
                  • Unit - Set level of Stun (OA) for (Triggering unit) to ((Level of Stun (OA) for (Triggering unit)) + 1)
                  • Set I_OA2[(Player number of (Owner of (Triggering unit)))] = (I_OA2[(Player number of (Owner of (Triggering unit)))] + 1)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • S_OA1[(Player number of (Owner of (Triggering unit)))] Equal to <Empty String>
                • Then - Actions
                  • Unit - Add Stun (OA) to (Triggering unit)
                  • Set S_OA1[(Player number of (Owner of (Triggering unit)))] = (Name of (Item being manipulated))
                  • Set I_OA1[(Player number of (Owner of (Triggering unit)))] = (I_OA1[(Player number of (Owner of (Triggering unit)))] + 1)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • S_OA2[(Player number of (Owner of (Triggering unit)))] Equal to <Empty String>
                      • S_OA1[(Player number of (Owner of (Triggering unit)))] Not equal to (Name of (Item being manipulated))
                    • Then - Actions
                      • Unit - Add Stun (OA) to (Triggering unit)
                      • Set S_OA2[(Player number of (Owner of (Triggering unit)))] = (Name of (Item being manipulated))
                      • Set I_OA2[(Player number of (Owner of (Triggering unit)))] = (I_OA2[(Player number of (Owner of (Triggering unit)))] + 1)
                    • Else - Actions
            • Else - Actions
              • Game - Display to (Player group((Owner of (Triggering unit)))) for 15.00 seconds the text: |c00FF0000You canno...
              • Player - Set (Owner of (Triggering unit)) Current lumber to (((Owner of (Triggering unit)) Current lumber) + 1)
        • Else - Actions
This is the stun ability that I had as one of the offensive abilities.

This is the end of the work that is needed to be done. If you want to add moe items for abilities, copy the Stun example and change all of the necessary fields.

To add the DA (Defensive Abilities), you will have to change all the OA variables into DA variables.

I hope this all makes sense as I find it quite easy to understand.

If you would like JASS versions of the the above, here they are:

Typing the -as command:

JASS:
function Trig_Ability_Stats_Actions takes nothing returns nothing
    call ClearTextMessagesBJ( GetForceOfPlayer(GetTriggerPlayer()) )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, "TRIGSTR_067" )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, "TRIGSTR_068" )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, ( "|c0080FF80Offensive Ability 1: " + ( udg_S_OA1[GetConvertedPlayerId(GetTriggerPlayer())] + ( " Level " + I2S(udg_I_OA1[GetConvertedPlayerId(GetTriggerPlayer())]) ) ) ) )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, ( "|c0080FF80Offensive Ability 2: " + ( udg_S_OA2[GetConvertedPlayerId(GetTriggerPlayer())] + ( " Level " + I2S(udg_I_OA2[GetConvertedPlayerId(GetTriggerPlayer())]) ) ) ) )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, ( "|c0080FF80Defensive Ability 1: " + ( udg_S_DA1[GetConvertedPlayerId(GetTriggerPlayer())] + ( " Level " + I2S(udg_I_DA1[GetConvertedPlayerId(GetTriggerPlayer())]) ) ) ) )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, ( "|c0080FF80Defensive Ability 2: " + ( udg_S_DA2[GetConvertedPlayerId(GetTriggerPlayer())] + ( " Level " + I2S(udg_I_DA2[GetConvertedPlayerId(GetTriggerPlayer())]) ) ) ) )
    call DisplayTimedTextToForce( GetForceOfPlayer(GetTriggerPlayer()), 25.00, ( "|c0080FF80Ultimate Ability: " + ( udg_S_ULTI[GetConvertedPlayerId(GetTriggerPlayer())] + ( " Level " + I2S(udg_I_ULTI[GetConvertedPlayerId(GetTriggerPlayer())]) ) ) ) )
endfunction

//===========================================================================
function InitTrig_Ability_Stats takes nothing returns nothing
    set gg_trg_Ability_Stats = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(0), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(1), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(2), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(3), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(4), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(5), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(6), "-as", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Ability_Stats, Player(7), "-as", true )
    call TriggerAddAction( gg_trg_Ability_Stats, function Trig_Ability_Stats_Actions )
endfunction

Setting the blank Variables:

JASS:
function Trig_SetAbils_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 8
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_I_DA1[GetForLoopIndexA()] = 0
        set udg_I_DA2[GetForLoopIndexA()] = 0
        set udg_I_OA1[GetForLoopIndexA()] = 0
        set udg_I_OA2[GetForLoopIndexA()] = 0
        set udg_S_DA1[GetForLoopIndexA()] = ""
        set udg_S_DA2[GetForLoopIndexA()] = ""
        set udg_S_OA1[GetForLoopIndexA()] = ""
        set udg_S_OA2[GetForLoopIndexA()] = ""
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_SetAbils takes nothing returns nothing
    set gg_trg_SetAbils = CreateTrigger(  )
    call TriggerAddAction( gg_trg_SetAbils, function Trig_SetAbils_Actions )
endfunction

Aquiring abilities through items:

JASS:
function Trig_Upgrading_Offensive_Conditions takes nothing returns boolean
    if ( not ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_POWERUP ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001Func001Func003C takes nothing returns boolean
    if ( not ( udg_S_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] == GetItemName(GetManipulatedItem()) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001Func001Func004C takes nothing returns boolean
    if ( not ( udg_S_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] == GetItemName(GetManipulatedItem()) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001Func001Func005Func002C takes nothing returns boolean
    if ( not ( udg_S_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] == "" ) ) then
        return false
    endif
    if ( not ( udg_S_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] != GetItemName(GetManipulatedItem()) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001Func001Func005C takes nothing returns boolean
    if ( not ( udg_S_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] == "" ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A004', GetTriggerUnit()) < 6 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(GetManipulatedItem()) == 'I000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Upgrading_Offensive_Actions takes nothing returns nothing
    if ( Trig_Upgrading_Offensive_Func001C() ) then
        if ( Trig_Upgrading_Offensive_Func001Func001C() ) then
            if ( Trig_Upgrading_Offensive_Func001Func001Func003C() ) then
                call SetUnitAbilityLevelSwapped( 'A004', GetTriggerUnit(), ( GetUnitAbilityLevelSwapped('A004', GetTriggerUnit()) + 1 ) )
                set udg_I_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = ( udg_I_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] + 1 )
            else
            endif
            if ( Trig_Upgrading_Offensive_Func001Func001Func004C() ) then
                call SetUnitAbilityLevelSwapped( 'A004', GetTriggerUnit(), ( GetUnitAbilityLevelSwapped('A004', GetTriggerUnit()) + 1 ) )
                set udg_I_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = ( udg_I_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] + 1 )
            else
            endif
            if ( Trig_Upgrading_Offensive_Func001Func001Func005C() ) then
                call UnitAddAbilityBJ( 'A004', GetTriggerUnit() )
                set udg_S_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetItemName(GetManipulatedItem())
                set udg_I_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = ( udg_I_OA1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] + 1 )
            else
                if ( Trig_Upgrading_Offensive_Func001Func001Func005Func002C() ) then
                    call UnitAddAbilityBJ( 'A004', GetTriggerUnit() )
                    set udg_S_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetItemName(GetManipulatedItem())
                    set udg_I_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = ( udg_I_OA2[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] + 1 )
                else
                endif
            endif
        else
            call DisplayTimedTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), 15.00, "TRIGSTR_091" )
            call SetPlayerStateBJ( GetOwningPlayer(GetTriggerUnit()), PLAYER_STATE_RESOURCE_LUMBER, ( GetPlayerState(GetOwningPlayer(GetTriggerUnit()), PLAYER_STATE_RESOURCE_LUMBER) + 1 ) )
        endif
    else
    endif
endfunction

//===========================================================================
function InitTrig_Upgrading_Offensive takes nothing returns nothing
    set gg_trg_Upgrading_Offensive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Upgrading_Offensive, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Upgrading_Offensive, Condition( function Trig_Upgrading_Offensive_Conditions ) )
    call TriggerAddAction( gg_trg_Upgrading_Offensive, function Trig_Upgrading_Offensive_Actions )
endfunction

Thanks for reading,
PiCk
 
  • Like
Reactions: ZIR
Top