System Bag System

Reaction score
341
Bag System

This is a little system I made that stores items, inside an item, also known as a bag.

I made this bag system because I have only really seen extended inventorys to heroes.

This system stores all the items into a bag, so if you drop that bag, and someone else picks it up, the items will still remain in the bag.

Features

  • MUI (or MII, Multi Item instancability :p)
  • Stores items depending on the bag, not the hero.
  • Stores the items UserData (Custom Value).
  • Simple Usage, by only calling one function.
  • You can store bags, inside bags!
  • Saves the items position in the inventory.
  • Stores item charges!

Code!

It's pretty simple, i'm sure theres a flaw in it, so comments and suggestions welcome!

JASS:
//***************************************************************************
//*
//*  Bag System - By TriggerHappy187
//*
//***************************************************************************
//*
//*  Installation
//*     Simply copy the BagSys trigger into your map.
//*     You can optionally copy the demo triggers, if they suite you.
//*     This system also requires JassHelper (included with JNGP)
//*     Also, copy the CloseBag and Bag items into your map, and edit the BagSys globals to fit the raw ID
//***************************************************************************
//*
//*  Documentation
//*     This is a little system I made that stores items, inside an item, also known as a bag.
//*  
//*     made this bag system because I have only really seen extended inventorys to heroes.
//*  
//*     This system stores all the items into a bag, so if you drop that bag, and someone else picks it up,
//*     the items will still remain in the bag.
//*
//***************************************************************************
//*
//*  The Functions
//*     They are self explanitory in my opinion.
//*  
//*     OpenBag opens the bag for the current person holding it.
//*     
//*     CloseBag closes the currently open bag for the owner
//*
//***************************************************************************

library BagSys
    
    globals
        private constant integer BAG = 'I000'
        private constant integer CLOSE_BAG = 'I001'
    endglobals
    
    private struct bag
    
        integer array items[7]
        integer array UserData[7]
        integer array bagitems[7]
        integer array Charges[7]
        boolean isOpen = false
        
        static method create takes item whichBag returns bag
            local bag b = bag.allocate()
            call SetItemUserData(whichBag, b)
            return b
        endmethod
        
    endstruct
    
    function CloseBag takes unit owner, item whichBag returns boolean
        local bag b = GetItemUserData(whichBag)
        local integer i = 0
        local item itm

        if b.isOpen == false then
            debug call BJDebugMsg(GetItemName(whichBag) + " is not open!")
            return false
        endif
        
        set b.isOpen = false
        call RemoveItem(UnitItemInSlot(owner, 5))

        loop
            exitwhen i == 7
            set b.bagitems<i> = GetItemTypeId(UnitItemInSlot(owner, i))
            set itm = CreateItem(b.items<i>, 0, 0)
            call SetItemUserData(itm, b.UserData<i>)
            call SetItemCharges(itm, b.Charges<i>)
            set b.UserData<i> = GetItemUserData(UnitItemInSlot(owner, i))
            set b.Charges<i> = GetItemCharges(UnitItemInSlot(owner, i))
            call RemoveItem(UnitItemInSlot(owner, i))
            call UnitAddItem(owner, itm)
            call UnitDropItemSlot(owner, itm, i)
            set i = i + 1
        endloop

        set itm = null
        return true
    endfunction
    
    function OpenBag takes unit owner, item whichBag returns boolean
        local bag b = GetItemUserData(whichBag)
        local integer i = 0
        local item itm
        
        if b.isOpen == true then
            debug call BJDebugMsg(GetItemName(whichBag) + &quot; is already open!&quot;)
            return false
        elseif GetItemTypeId(UnitItemInSlot(owner, 5)) == CLOSE_BAG then
            debug call BJDebugMsg(&quot;You cannot open two bags at once&quot;)
            return false
        endif
        
        loop
            exitwhen i == 6
            set b.items<i> = GetItemTypeId(UnitItemInSlot(owner, i))
            set itm = CreateItem(b.bagitems<i>, 0, 0)
            call SetItemUserData(itm, b.UserData<i>)
            call SetItemCharges(itm, b.Charges<i>)
            set b.UserData<i> = GetItemUserData(UnitItemInSlot(owner, i))
            set b.Charges<i> = GetItemCharges(UnitItemInSlot(owner, i))
            call RemoveItem(UnitItemInSlot(owner, i))
            call UnitAddItem(owner, itm)
            call UnitDropItemSlot(owner, itm, i)
            set i = i + 1
        endloop

        set b.isOpen = true
        set itm = CreateItem(CLOSE_BAG, 0, 0)   
        call SetItemUserData(itm, b)
        call UnitAddItem(owner, itm)
        call UnitDropItemSlot(owner, itm, 5)
        
        set itm = null
        return true
    endfunction
    
    function ToggleBag takes unit owner, item whichBag returns nothing
        if bag(GetItemUserData(whichBag)).isOpen == true then
            call CloseBag(owner, whichBag)
        else
            call OpenBag(owner, whichBag)
        endif
    endfunction
    
    function CreateBag takes item whichBag returns nothing
        call bag.create(whichBag)
    endfunction
    
    
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i>


For all you gui'ers, don't be afraid, try the demo map and you will see how easy it is to use.
 

Attachments

  • BagSys.w3x
    17.9 KB · Views: 319
  • bagsys.JPG
    bagsys.JPG
    5.9 KB · Views: 272

Azlier

Old World Ghost
Reaction score
461
Hah, that snippet was just for when I was learning structs. It didn't even use a proper create method. This is different.
 

Flare

Stops copies me!
Reaction score
662
Tag changed to [System]

JASS:
        integer array items[7]
        integer array UserData[7]
        integer array bagitems[7]
        integer array Charges[7]

Why is the array size 7? To my knowledge, item slots work from 0 to 5 or, at least, they did when I wrote this:
JASS:
//Yes, it works, don&#039;t even think about asking <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
globals
    integer array ItemIds[2][6]
    integer array ItemCharges[2][6]
endglobals

function SwapItems takes unit first, unit second returns nothing
    local integer i = 0
    local item itm
    loop
    exitwhen i == 6
        set itm = UnitItemInSlot (first, i)
        set ItemIds[0]<i> = GetItemTypeId (itm)
        set ItemCharges[0]<i> = GetItemCharges (itm)
        call RemoveItem (itm)
        set itm = UnitItemInSlot (second, i)
        set ItemIds[1]<i> = GetItemTypeId (itm)
        set ItemCharges[1]<i> = GetItemCharges (itm)
        call RemoveItem (itm)
        set i = i + 1
    endloop
    set i = 0
    loop
    exitwhen i == 6
        set itm = UnitAddItemById (first, ItemIds[1]<i>)
        call SetItemCharges (itm, ItemCharges[1]<i>)
        set itm = UnitAddItemById (second, ItemIds[0]<i>)
        call SetItemCharges (itm, ItemCharges[0]<i>)
        set i = i + 1
    endloop
    set itm = null
endfunction

</i></i></i></i></i></i></i></i>

Seems silly to have an extra, unused array slot where it's not needed (since, as it is, you're acquiring data for 7 items (0, 1, 2, 3, 4, 5, 6 - there be 7 numbers thar), and I'm sure you know that standard inventories don't have 7 slots)
 
Reaction score
341
Did you reduce the 'exitwhen i == 7' to i == 6 as well? Not sure if that's the problem, or if it'd solve it, but it's worth a shot if it's not already done. Might take a look at things myself later, I'm tired right now :(

I'm pretty sure I tried that, I will take a second and maybe third look :thup:

EDIT: alright, it works, don't know how the bug occured before.

I will update it once I add a dragNdrop demo.
 

Tooblet

Active Member
Reaction score
6
heyooooo

I love this system, but I can't get it to be MUI(MII)..

It works like a charm, I create the bag item when I select a hero in my map, and then give it to the hero after setting variable and calling CreateBag(udg_variable).

But when I play my map multiplayer and we all choose heroes, we share the same bag.
when one person opens the bag, others cannot open "their" bags.
and when anyone puts an item in his bag, it comes to the same bag.
It's like everyone has a bagitem that leads to the same bag :p

any idéa why this occurs? I can swear I've done everything right :/
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Would be nice if the items that are in a bag gives you the effect they normally, do. (I can understand, it would be such hard to do, but would be very enjoyable).
 

Tooblet

Active Member
Reaction score
6
well it's MII in the testmap, But I can't seem to get it goin right.
any solutions or changes I should make?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top