System Item Switcher

SerraAvenger

Cuz I can
Reaction score
234
Many of us know the problem with the changing of active items into an inactive version, and back.

This is what this system does:
It creates pairs of Items, and then can switch within the pair.

Item A <- switch -> Item B

REQUIREMENTS
- JassPack NewGen
- The ItemAttacher and the Hash libraries
- A tiny bit of JASS knowledge

How to use:
- Copy this into any Custom-Code trigger
- Create a Custom-Code line in a trigger which is ran once ( preferably at map init ) and enter
JASS:
call SetItemPair( &#039;&#039;, &#039;&#039; )
. Between each the two '' put one of the itemtypeids of the pair. Eg: Itemtypeids I007 and I0A4 need to be paired, so we write
JASS:
call SetItemPair( &#039;I007&#039;, &#039;I0A4&#039; )

NOTE: If you'ld call lateron
JASS:
call SetItemPair( &#039;I007&#039;, &#039;I0B5&#039; )
, the first pair would be destroyed - I007 would switch to I0B5, I0B5 to I007 and I0A4 wouldn't switch into anything anymore.
- Now whenever you need to switch an item, use
JASS:
call SwitchItem( item )
and then you can wether use the returned item (JASS) or the "Last Created Item" (GUI) in order to refer to the switched item.
NOTE: The Item will not be automatically Added to the Inventory of the unit that held the first item before, so you'll need to add the item manually if needed!
Example:
Code:
Item - Create Item of Type Magic Sword[I](I007)[/I]
Set SwapItem = Last Created Item
Custom Script - call SetItemPair( 'I007', 'I0A4' )
Custom Script - call SwitchItem( udg_SwapItem )
Unit - Add Last Created Item to Heroes[ 4 ]
Will swap the Magic Sword with the item of type 'I0A4', and afterwards add it to hero number 4ths inventory.

JASS:
// This can switch items

//! runtextmacro AddItemValue( &quot;SwapId&quot;, &quot;integer&quot;, &quot;-1&quot; )

library ItemSwitcher needs SwapIdAttacherItem
function SetItemPair takes integer itemtypeidA, integer itemtypeidB returns nothing
    local integer swapidA = GetItemTypeSwapId( itemtypeidA )
    local integer swapidB = GetItemTypeSwapId( itemtypeidB )
    
    if swapidA != -1 then
        call SetItemTypeSwapId( swapidA, -1 )
    endif
    if swapidB != -1 then
        call SetItemTypeSwapId( swapidB, -1 )
    endif
    
    call SetItemTypeSwapId( itemtypeidA, itemtypeidB )
    call SetItemTypeSwapId( itemtypeidB, itemtypeidA )
endfunction

function SwitchItem takes item toswitch returns item
    local integer itemId = GetItemTypeId( toswitch )
    local integer swapId = GetItemTypeSwapId( itemid )
    local real x = GetItemX( toswitch )
    local real y = GetItemY( toswitch )
    if swapId != -1 then
        call RemoveItem( toswitch )
        set toswitch = null
        set bj_lastCreatedItem = CreateItem( swapId, x, y )
        return bj_lastCreatedItem
    endif
endfunction
endlibrary
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top