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. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  5. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  6. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  7. The results are out! Check them out.
    Dismiss Notice
  8. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  9. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  10. 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.

Item Fuse/Disassemble 2 (GUI & vJass)

Submitted by Dark_Dragon
This bundle is marked as approved. It works and satisfies the submission rules.
This system's setup is made in GUI, but code is in vJass. This system can combine and disassemble items.


Changelog


Update to my previous system 1.4

-------------------------------------------------------
Version 1.5
- Mirror image sound now can be configurable, once can delay it, shut it down or use it and disable effect sound. If do not want to use MirrIm sound then just use effect from comments. If you want to play both just delay MirrIm sound.

- The "return" line of code was there to eliminate extra loops and simply end the code
so i just added "u = null" to fix the leak
-------------------------------------------------------

-------------------------------------------------------
Version 1.6
- Added option for array increase
- Fixed hex array id
- Fixed timer leak
- Added compatibility with 'Table'
-------------------------------------------------------

-------------------------------------------------------
Version 1.7
- Added support for item disassemble
- Fixed bug with wrong flush of 'Table'
-------------------------------------------------------

-------------------------------------------------------
Version 1.7b
- Replaced multiple instances of "6" by bj_MAX_INVENTORY, for easier readability
- Changed trigger action with condition
- Added some more comments
- Fixed sound bug (when 2 recipes are fused faster than "fuse" sound ends, sound would not play)
-------------------------------------------------------

-------------------------------------------------------
Version 2
- Optimized code
-------------------------------------------------------






Why use this recipe system?

It is vJass and GUI, very simple to use (using GUI globals)
You do not use say different functions such as CreateRecipe1,2,3,....
just use global vars instead of rawcodes, it is easier to click directly on icons and then just call recipecreate function.




GUI
  • Load Items
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- ----------------------------------------------------------------- --------
      • -------- Item Group 1 --------
      • Set CItemType[1] = Claws of Attack +6
      • Set CItemType[2] = Claws of Attack +9
      • Set CItemType[0] = Claws of Attack +15
      • Set CItemDisassemble = True
      • Custom script: call NewItemGroup()
      • -------- ----------------------------------------------------------------- --------
      • -------- Item Group 2 --------
      • Set CItemType[1] = Circlet of Nobility
      • Set CItemType[2] = Circlet of Nobility
      • Set CItemType[3] = Circlet of Nobility
      • Set CItemType[0] = Crown of Kings +5
      • Set CItemDisassemble = True
      • Custom script: call NewItemGroup()
      • -------- ----------------------------------------------------------------- --------
      • -------- Item Group 3 --------
      • Set CItemType[1] = Mantle of Intelligence +3
      • Set CItemType[2] = Slippers of Agility +3
      • Set CItemType[0] = Hood of Cunning
      • Set CItemDisassemble = True
      • Custom script: call NewItemGroup()
      • -------- ----------------------------------------------------------------- --------
      • -------- Item Group 4 --------
      • Set CItemType[1] = Boots of Quel'Thalas +6
      • Set CItemType[2] = Slippers of Agility +3
      • Set CItemType[0] = Bloodfeather's Heart
      • Set CItemDisassemble = True
      • Custom script: call NewItemGroup()
      • -------- ----------------------------------------------------------------- --------
      • -------- Item Group 5 --------
      • Set CItemType[1] = Claws of Attack +15
      • Set CItemType[2] = Claws of Attack +6
      • Set CItemType[0] = Divine Rapier
      • Set CItemDisassemble = False
      • Custom script: call NewItemGroup()
      • -------- ----------------------------------------------------------------- --------
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )
  • Item Disassemble
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Disassemble
    • Actions
      • -------- Set the slot from which you want item to be dissasembled --------
      • Set CItemDisassembleSlot = 1
      • -------- The unit which will be casting disassemble ability, in case you have different way of disassembling, --------
      • -------- change that unit variable to mach that unit, for example Circle of Power... --------
      • Set CItemUnit = (Triggering unit)
      • Custom script: call SlotItemDisassemble(udg_CItemUnit, udg_CItemDisassembleSlot)




Code
Code (vJASS):

//TESH.scrollpos=0
//TESH.alwaysfold=0
// ===============================================================================
//                  * System: Item Combine v2
//
// * Installation:
//
// 1) Copy "DD Library" "Load Items", "Item Disassemble" and "Item Combine Core" triggers to your map
//  note: dummy unit and other stuff for "DD Library" trigger is not in this map because this system does not need dummies...
// 2) Copy ability "Disassemble" and paste it in your map, unless you use different method of item disassemble
// 3) Export and import "ItemFuse.mdx", "Item_Disassembly.wav" and "Item_Disassemble.mdx" to your map
//    Import path: Same as in this map
//    If you want to change path or use different effect, change that below
// 4) Make your own recipes in "Load Items" trigger
// 5) Enjoy!
//
// Credits: Magos, Audacity team, Notepad++ team, Vexorian, Blizzard
// ===============================================================================

//! zinc
library DDItemCombineBasic requires DDLib
{

    // -------------------------------------------------------
    // *** Edit to your own will ***
       
    // * This is effect that will be displayed when items combine/disassemble and attachment point
 constant string         ITEM_COMBINE_EFFECT         = "Custom\\Models\\ItemFuse.mdx"; //"Abilities\\Spells\\Items\\AIlm\\AIlmTarget.mdl"
 constant string   ITEM_DISASSAMBLE_EFFECT  = "Custom\\Models\\Item_Disassemble.mdx";
 constant string         ATTACH_POINT          = "origin";
       
    // * If you want to use custom sound, setup it below
    // * "Sound path", "time in second to play sound after combine is done", "volume" and "pitch" of sound
    constant boolean        USE_CUSTOM_SOUND            = true;
 constant real           SOUND_MAX_DISTANCE          = 3500.;
    constant string         SOUND_FILE            = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImage.wav";
    constant real           SOUND_VOL                   = 90.;
    constant real           SOUND_PITCH                 = 1.2;
   
 
 // * This is disassemble sound
 constant string         SOUND_FILE_2            = "Custom\\Sounds\\Item_Disassembly.wav";
 constant real           SOUND_VOL_2                 = 90.;
 constant real           SOUND_PITCH_2               = 1.;
    // *** End edit ***
    // -------------------------------------------------------
   
    //private keyword Table
    // ===========================================================================
    // ===========================================================================
    sound               ItemCombineSound        = null;
 sound    ItemDisassembleSound = null;
    integer          CType[];
 boolean      CTypeDisassemble[];
 integer             ItemN                   = 0;
 
    // ===========================================================================
   
 // -----------------------------------------------------------------------
 // ** Items in CItemType from 1-6 are user items that we need to shift to next memory locations, that is why for this recipe system
 //    slots lower than 6 are not used, we store items in higher slots
    public function NewItemGroup() {
        integer i = ItemN*bj_MAX_INVENTORY + 07;
        integer h = 01;
 
  if (bj_gameStarted || udg_CItemType[00] == 00)
   return;
 
        while(h != 07) {
            udg_CItemType[i] = udg_CItemType[h];
            udg_CItemType[h] = 00;
            h += 01;
            i += 01;
        }
        CType[ItemN] = udg_CItemType[00];
  CTypeDisassemble[ItemN] = udg_CItemDisassemble;
        udg_CItemType[00] = 00;
  ItemN += 01;
  //udg_CItemDisassemble = false;
    }
   
 // -----------------------------------------------------------------------
 // ** Primary public function for item disassemble
    public function SlotItemDisassemble(unit u, integer slot) {
  item it = UnitItemInSlot(u, slot-01);
  integer it_id = GetItemTypeId(it);
  real x = GetUnitX(u);
  real y = GetUnitY(u);
 
  // *** is slot empty? ***
  if (it != null) {
   // *** search for registerd item recipe ***
   for(slot=00; slot < ItemN; slot+=01) {
    // *** found the item ***
    if (CType[slot] == it_id) {
     // *** Check if allow disassemble by user? ***
     if (!CTypeDisassemble[slot]) {
      // *** Disassembly not allowed, but null the item
      it = null;
      return;
     }
     
     // *** Do remove and creation jobs ***
     RemoveItem(it);
     slot = slot*bj_MAX_INVENTORY + 07; // get to first item id of this recipe
     while(udg_CItemType[slot] != 00) {
      CreateItem(udg_CItemType[slot], x, y);
      slot += 01;
     }
     
     // -------------------------------------------------------------------------------------
     // *** play custom sound and effect ***
     // *** If items are disassembled too fast, sound might be playing, so first we have to stop it
     DDGenericSound(SOUND_FILE_2, SOUND_VOL_2, x, y, SOUND_MAX_DISTANCE, SOUND_PITCH_2);
     DestroyEffect( AddSpecialEffectTarget(ITEM_DISASSAMBLE_EFFECT, u, ATTACH_POINT) );
     // *** Item is removed, now null
     it = null;
     return;
    }
   }
   // *** invalid item, do null anyway ***
   it = null;
  }
 }
 
 // ====================================================================================

    function UnitRemoveItemById(unit whichUnit, integer itemId) {
        integer i = 00;
        item it;
       
        for(i=00; i < bj_MAX_INVENTORY; i+=01) {
            it = UnitItemInSlot(whichUnit, i);
            if (GetItemTypeId(it) == itemId) {
                RemoveItem(it);
                break;
            }
        }
        it = null;
    }

    //===========================================================================
    function onInit() {
        trigger t = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM);
        TriggerAddCondition(t, function() -> boolean {
   unit  u = GetTriggerUnit();
   integer it[];
   integer n, i = 07;
   integer h;
   integer x, y, z;
   
   boolean b = true;
   integer hero_item_type[];
   
   static if (USE_CUSTOM_SOUND)
    timer t;

   // Get hero items
   for(x=00; x < bj_MAX_INVENTORY; x+=01)
    hero_item_type[x] = GetItemTypeId(UnitItemInSlot(u, x));

   for(n=00; n < ItemN; n+=01) {
    h = i + bj_MAX_INVENTORY;
   
    x = 00;
    it[x] = hero_item_type[x]; x = 01;
    it[x] = hero_item_type[x]; x = 02;
    it[x] = hero_item_type[x]; x = 03;
    it[x] = hero_item_type[x]; x = 04;
    it[x] = hero_item_type[x]; x = 05;
    it[x] = hero_item_type[x]; x = 06;
   
    //y = 00; // N of items that hero has ()
    //z = 00; // N of items needed ()
    for(y=00, z=00; i < h; i+=01) {
     if (udg_CItemType[i] == 0)
      break;
     
     z += 01;
     // Does unit contain item n
     for(x=00; x < bj_MAX_INVENTORY; x+=01) {
      if (it[x] == udg_CItemType[i]) {
       // Kick out the item
       it[x] = 00;
       y += 01;
       // And increase by 1
       break;
      }
     }
    }
   
    i = h;
   
    if (y == z) {
     i -= bj_MAX_INVENTORY;
     while(i <= h && udg_CItemType[i] != 00) {
      UnitRemoveItemById(u, udg_CItemType[i]);
      i += 01;
     }
     UnitAddItemById(u, CType[n]);
     
     static if (USE_CUSTOM_SOUND)
      DDGenericSound(SOUND_FILE, SOUND_VOL, GetWidgetX(u), GetWidgetY(u), SOUND_MAX_DISTANCE, SOUND_PITCH);
     DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT));
     u = null;
     return false;
    }
   }
   
   u = null;
   return false;
  });

    }

}
//! endzinc

[/B]

[B]

 



If you have any more questions, please ask in comments.
Enjoy!

~Dark Dragon



Keywords:
System, recipe, items, combine
Contents

System - Recipe/Disassemble v2 (Map)

Reviews
Moderator
12:37, 3st Feb 2016 BPower: Criticism: The code is short and does exacly what it was made for. Good job. In my opinion the sound files fit to the mechanics. Approved as good alternative to Diablo-dk's recipe system.
  1. 12:37, 3st Feb 2016
    BPower:

    Criticism:

    The code is short and does exacly what it was made for. Good job.
    In my opinion the sound files fit to the mechanics.

    Approved as good alternative to Diablo-dk's recipe system.
     
  2. Meatmuffin

    Meatmuffin

    Joined:
    Jul 25, 2014
    Messages:
    454
    Resources:
    9
    Maps:
    2
    Spells:
    7
    Resources:
    9
    Please post your triggers and vJASS code for easy review.
     
  3. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    Hi, here you go:

    GUI Combine Sample

    • Load Items
      • Events
        • Map initialization
      • Conditions
      • Actions
        • -------- ----------------------------------------------------------------- --------
        • -------- Item Group 1 --------
        • Set CItemType[1] = Claws of Attack +6
        • Set CItemType[2] = Claws of Attack +9
        • Set CItemType[0] = Claws of Attack +15
        • Set CItemDisassemble = True
        • Custom script: call NewItemGroup()
        • -------- ----------------------------------------------------------------- --------
        • -------- Item Group 2 --------
        • Set CItemType[1] = Circlet of Nobility
        • Set CItemType[2] = Circlet of Nobility
        • Set CItemType[3] = Circlet of Nobility
        • Set CItemType[0] = Crown of Kings +5
        • Set CItemDisassemble = True
        • Custom script: call NewItemGroup()
        • -------- ----------------------------------------------------------------- --------
        • -------- Item Group 3 --------
        • Set CItemType[1] = Mantle of Intelligence +3
        • Set CItemType[2] = Slippers of Agility +3
        • Set CItemType[0] = Hood of Cunning
        • Set CItemDisassemble = True
        • Custom script: call NewItemGroup()
        • -------- ----------------------------------------------------------------- --------
        • -------- Item Group 4 --------
        • Set CItemType[1] = Boots of Quel'Thalas +6
        • Set CItemType[2] = Slippers of Agility +3
        • Set CItemType[0] = Bloodfeather's Heart
        • Set CItemDisassemble = True
        • Custom script: call NewItemGroup()
        • -------- ----------------------------------------------------------------- --------
        • -------- Item Group 5 --------
        • Set CItemType[1] = Claws of Attack +15
        • Set CItemType[2] = Claws of Attack +6
        • Set CItemType[0] = Divine Rapier
        • Set CItemDisassemble = False
        • Custom script: call NewItemGroup()
        • -------- ----------------------------------------------------------------- --------
        • Custom script: call DestroyTrigger( GetTriggeringTrigger() )



    GUI Disassemble Sample
    • Item Disassemble
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Disassemble
      • Actions
        • -------- Set the slot from which you want item to be dissasembled --------
        • Set CItemDisassembleSlot = 1
        • -------- The unit which will be casting disassemble ability, in case you have different way of disassembling, --------
        • -------- change that unit variable to mach that unit, for example Circle of Power... --------
        • Set CItemUnit = (Triggering unit)
        • Custom script: call SlotItemDisassemble(udg_CItemUnit, udg_CItemDisassembleSlot)



    ------------------------------------------------------------------------

    Jass code is now in description!

    Regards!
    ~DD
     
    Last edited: Feb 2, 2016
  4. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,738
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    set TUnit[GetHandleId(t)-0x10000] = u
    is incorrect. The minimum possible handle id is 0x100000.

    Also not very safe, as handle ids are shared over different type of objects.
    They can go above 8910 during a game season.

    You leak a timer handle.

    I don't think the system is more advanced than dk-diablo system.

    The API is nice and straight foreward.
     
  5. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,496
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    I still think this is a great system for all the GUI users who are way too scared to look at vJass. The API on this is so simple, I don't see how any newbie can be confused by it. On a side note, I really think you should put a warning somewhere that this still requires JNGP to use. The "GUI / Triggers" is a bit misleading.
     
  6. Arad MNK

    Arad MNK

    Joined:
    Dec 11, 2014
    Messages:
    1,889
    Resources:
    3
    Maps:
    2
    Spells:
    1
    Resources:
    3
    Code (vJASS):
                set x = 0
                set it[x] = hero_item_type[x]
                set x = x + 1
                set it[x] = hero_item_type[x]
                set x = x + 1
                set it[x] = hero_item_type[x]
                set x = x + 1
                set it[x] = hero_item_type[x]
                set x = x + 1
                set it[x] = hero_item_type[x]
                set x = x + 1
                set it[x] = hero_item_type[x]
                set x = x + 1


    You can put this in a loop as well. Shortens the code and improves readability.
     
  7. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,738
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    Your code will not compile in DEBUG_MODE = true.

    Why does ARRAY_SIZE influence the array space of CType.
    It should increases the size of TUnit.
    I would recommend to use a table instance from library Table instead of the array.
     
  8. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    I know, but it is faster to directly code then to use loop.
    if i where to code this now, i would use loop, but at the time i was coding this, i did it this way coz i thought i had to do it as fast as possible...

    Ops sorry about debug mode, did this in zinc, but forgot to change to vjass...
    ARRAY_SIZE changed to TUnit... sorry i rushed the update and miss the variable :xxd:

    About table, i never used it, but i could learn to... its just that for system i am not using much of data for this so i think this array_size var should do...

    EDIT: I added support for Table, for thous who already have it/use it in there maps and it is part of 1.6 update

    Regards!
    ~DD
     
    Last edited: Feb 2, 2016
  9. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,738
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    Nice coding. I will approve it later as an alternative to dk-diablos system.

    Btw the table syntax for handles is a bit different.

    table.remove(integer) --> RemoveSavedInteger(hash, this, integer)
    table.handle.remove(integer) --> RemoveSavedHandle(hash, this, integer)
     
  10. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,738
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    You have an item handle leak in UnitRemoveItemById, if the item type id has been found.
    Fix that please.
    Edit: My mistake. There is no leak in the code.

    Trigger conditions are favored over trigger actions to run on as trigger action/condition function.
    Simply because they evaluate faster than trigger actions.
    ---
    Actually it's not a big performance difference, but that issue is mentioned hundred times accross our forums.
    Trigger conditions also have other advantages when it comes
    to dynamically created triggers, but that is not important for this resource.

    Good resource. Approved.

    Edit:
    As there is a link from your to Diablo-dk's system in your review,
    I also added a link backwards to this resource in his submission review.
     
    Last edited: Feb 3, 2016
  11. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    Ok thanks, i updated the system, hope its good now.

    Regards!
    ~DD
     
  12. pusha1999

    pusha1999

    Joined:
    Jan 7, 2014
    Messages:
    66
    Resources:
    0
    Resources:
    0
    what need to change for modify this system for possible to create items with full inventory if you take an dummy item wich is last needed for create the item? its little hard to improve not your own systems. i added recipe with dummy item, but it doesnt works. another recipes with 1-6 items works perfect, but with 7th items have no idea how.
     
  13. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    Hi,

    Could you modify this "map/system" so that i can see what does not work.

    Regards!
    ~DD
     
  14. pusha1999

    pusha1999

    Joined:
    Jan 7, 2014
    Messages:
    66
    Resources:
    0
    Resources:
    0
    ty for fast answer, i solved that problem already :)
    there just need implement few conditions with checks permanent item or its powerup item )
     
  15. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    I see, glade it worked!
    Regards!
    ~DD
     
  16. pusha1999

    pusha1999

    Joined:
    Jan 7, 2014
    Messages:
    66
    Resources:
    0
    Resources:
    0
    good system, but still does not support +7 items :), for support need to implement few lines in code
     
    Last edited: Jun 21, 2019
  17. Dark_Dragon

    Dark_Dragon

    Joined:
    Jul 19, 2007
    Messages:
    596
    Resources:
    8
    Tools:
    1
    Spells:
    7
    Resources:
    8
    Hi, yes this system is for standard 6 item slots. Its old system that i improved a bit now.
    Regards!
    ~DD