Snippet Stack Items

SanKakU

Member
Reaction score
21
Update:
Ok, i've updated the code, and for greater ease of importing, made it into a library.
It's not a snippet anymore, but a system, i think.
Got a Demo Map Uploaded for you.

I've seen other stack item methods, but wondered if using GT would be a good idea for it. So here it is, stacking items using Jesus4Lyf's system GT.

edit: oh i had to change some of the numbers to correspond to regular inventories...

also, if you're not familiar with how this works and want to get started with it right away, i'll explain.

to implement:
1) make a new trigger and replace the code in there with the full code, shown below step 5.
2) make another trigger or put at the bottom of your other new trigger the following:
JASS:
scope switcha initializer I
    //! runtextmacro itemswitching("'mcri'","'I00B'")

scope stacka initializer I
    //! runtextmacro itemstacking("'desc'","'I007'")

scope ammoa initializer I
    //! runtextmacro ammostacking("'I00C'","'whwd'","2")

as many times as you need to
3) add on your own numbers or letters, i used a,b,c,d, etc.

where 'mcri' is the item you are denying the non hero units who can use items
and 'I00B' is the alternate item for non hero units who can use items.

where 'desc' is the item which is a fake pickup or buying item, which is perishable and is used upon pickup
and 'I007' is the item which is the real item which is given when you get the fake item. after you already have the real item you will get the real item stacked.

where 'I00C' is the fake item much like the item stacking...and 'whwd' is the real item which is a charged item...and 2 is your charge count for an individual item buy. you will now be able to stack your charges automatically, as well as manually merge your charges.

4) (optional) expand the snippet to create your own system by making hero classes or whatever. if you can make items turn into other items when different types of units get them, it makes things more interesting.

you would probably do that by adding your own textmacro based on this part of the code:
JASS:
//! textmacro itemswitching takes itemA, itemB
    private function f takes nothing returns boolean
    local unit mu = GetManipulatingUnit()
    local item itm=GetItemHero(mu,$itemA$)
        if IsUnitType(mu, UNIT_TYPE_HERO) then
            set mu=null
            return false
        else
            call RemoveItem(itm)
            set itm=UnitAddItemById(mu,$itemB$)
            set mu=null
            return false
        endif
    endfunction    
    private function I takes nothing returns nothing
        call GT_AddItemAcquiredAction(function f, $itemA$)
    endfunction

endscope
//! endtextmacro

5) don't forget to get GT and if you want to utilize the ammo charge stacking feature, UID

JASS:

/*stack items
uses GT
uses UID
by SanKakU*/
//=====================================================================================
//HOW TO USE:
//=====================================================================================
//
//COPY ALL THE TEXT FROM THIS TRIGGER AND REPLACE THE TEXT FOR A TRIGGER NAMED
//StackItems WITH IT
//
//DO THE SAME FOR THE TRIGGER CALLED GT, YOU CAN GET IT AT thehelper.net
//
//IF YOU WANT TO USE AMMO TYPE STACKING IN YOUR MAP, THEN:
//DO THE SAME FOR THE TRIGGER CALLED UID, AND ALL THE STUFF THAT IT REQUIRES
//
//UID IS ALSO FOUND AT thehelper.net
//
//=====================================================================================
//MAKE YOUR OWN TRIGGER, CALL IT WHATEVER YOU LIKE...AND MAKE YOUR OWN TEXTMACRO SCOPES
//=====================================================================================
//
//FOLLOW THE INSTRUCTIONS THROUGHOUT THE CODE AND READ THE EXAMPLE TEXTMACRO SCOPES
//
//IT'S REALLY JUST A SUPER FAST WAY TO CODE LOTS OF ITEMS FOR STACKING...
//BUT BESIDES THAT, IT - WITH THE HELP OF UID - ENABLES STACKING FOR CHARGED ITEMS THAT ARE
//OVER ONE CHARGE COUNT
//
//I'M HOPING THAT A FUTURE VERSION WILL ENABLE LIMITS ON CHARGES...
//IF YOU'RE A CODER WHO HAS AN IDEA FOR ME ABOUT THAT, PM ME ON thehelper.net
//
//=====================================================================================
//CREDITS
//=====================================================================================
//RDZ's Incredible Item Stacking System of Doom - by Rao Dao Zao
//=====================================================================================
//GTrigger Event System - by Jesus4Lyf
//=====================================================================================
//Units' Inventory Data - by kingkingyyk3
//=====================================================================================
library StackItems uses GT, optional UID

//no need to edit the first two functions unless your map has special item needs

function GetInventoryHero takes unit u, integer i returns integer
    local integer index
    local item indexItem
    set index = 0
        loop
            set indexItem = UnitItemInSlot(u, index)
            if (indexItem != null) and (GetItemTypeId(indexItem) == i) then
                return index
            else
                set index=index+1
            endif
        exitwhen index>5
        endloop
    return 6
endfunction

function GetItemHero takes unit whichUnit, integer itemId returns item
    local integer index = GetInventoryHero(whichUnit, itemId)
        if (index == 6) then
            return null
        else
            return UnitItemInSlot(whichUnit, index)
        endif
endfunction

static if LIBRARY_UID then

//unless you edited the first two functions you shouldn't need to edit this textmacro
//this textmacro uses GTrigger by Jesus4Lyf, download it at thehelper.net
//it also uses kingkingyyk3's UnitInventoryData System, download it at thehelper.net
    //! textmacro ammostacking takes itemA, itemB, count
        private function f takes nothing returns boolean
        local unit mu = GetManipulatingUnit()
        local integer invi = GetInventoryHero(mu, $itemB$)
        local item itm = null
            if invi !=6 then
                set itm=GetItemHero(mu,$itemB$)
                call SetItemCharges(itm,GetItemCharges(itm)+$count$)
                set mu=null
                return false 
            else
                call UnitAddItemById(mu,$itemB$)
                set mu=null
                return false
            endif
                set mu=null
                return false
        endfunction
        
        private function I takes nothing returns nothing
        call GT_AddItemAcquiredAction(function f, $itemA$)
        endfunction

    endscope
    //! endtextmacro
    
//comments about UID TextMacro...
//remember to add to your library called setup (from UID)
//which requires chargemerger the $itemB$ in your ammo textmacro scopes...
//for example:
/*
scope ammoa initializer I
    //! runtextmacro ammostacking("'I00C'","'whwd'","2")

scope ammob initializer I
    //! runtextmacro ammostacking("'I00D'","'mcri'","5")
*/
/*
//! zinc
library Setup requires ChargeMarger {

function onInit() {
MergeCharge('whwd');
MergeCharge('mcri');
}

}
//! endzinc
*/
//also do not forget to replace the real items in the shops with the fake ones.

endif

//unless you edited the first two functions you shouldn't need to edit this textmacro
//this textmacro uses GTrigger by Jesus4Lyf, download it at thehelper.net
//! textmacro itemstacking takes itemA, itemB
    private function f takes nothing returns boolean
    local unit mu = GetManipulatingUnit()
    local integer invi = GetInventoryHero(mu, $itemB$)
    local item itm = null
        if invi !=6 then
            set itm=GetItemHero(mu,$itemB$)
            call SetItemCharges(itm,GetItemCharges(itm)+1)
            set mu=null
            return false 
        else
            call UnitAddItemById(mu,$itemB$)
            set mu=null
            return false
        endif
            set mu=null
            return false
    endfunction

    private function I takes nothing returns nothing
    call GT_AddItemAcquiredAction(function f, $itemA$)
    endfunction

endscope
//! endtextmacro
//remember to make your own textmacro scopes in another trigger, or if you prefer, at the
//bottom of this trigger
//for example:
/*
scope stacka initializer I
    //! runtextmacro itemstacking("'desc'","'I007'")

scope stackb initializer I
    //! runtextmacro itemstacking("'fgsk'","'I008'")

scope stackc initializer I
    //! runtextmacro itemstacking("'fgfh'","'I009'")

scope stackd initializer I
    //! runtextmacro itemstacking("'pclr'","'I005'")

scope stacke initializer I
    //! runtextmacro itemstacking("'pman'","'I006'")

scope stackf initializer I
    //! runtextmacro itemstacking("'tgxp'","'I002'")

scope stackg initializer I
    //! runtextmacro itemstacking("'pams'","'I004'")

scope stackh initializer I
    //! runtextmacro itemstacking("'moon'","'I003'")
    */

/*the following is a textmacro that exchanges one item for another, think of it like
in dota when a hero is ranged or melee, or you have a bear or syllabear item versions...
well it is kinda like that.  you can make additional textmacro scopes for different unit
types easily by replacing the UNIT_TYPE_HERO with something else, like in the dota
example of melee or ranged... UNIT_TYPE_MELEE_ATTACKER, in this case, we are checking
to make sure that the heroes get the itemA, but if a different unit picks up the itemA,
that unit gets itemB instead.  you can of course name your textmacro whatever you want,
we can of course, make the next one be called itemswitchhero and make a second one
called itemswitchmelee
*/
//! textmacro itemswitching takes itemA, itemB
private function f takes nothing returns boolean
    local unit mu = GetManipulatingUnit()
    local item itm=GetItemHero(mu,$itemA$)
        if IsUnitType(mu, UNIT_TYPE_HERO) then
            set mu=null
            return false
        else
            call RemoveItem(itm)
            set itm=UnitAddItemById(mu,$itemB$)
            set mu=null
            return false
        endif
    endfunction
    
    private function I takes nothing returns nothing
    call GT_AddItemAcquiredAction(function f, $itemA$)
    endfunction

endscope
//! endtextmacro
//remember to make your own textmacro scopes in another trigger, or if you prefer, at the
//bottom of this trigger
//for example:
/*
scope switcha initializer I
    //! runtextmacro itemswitching("'mcri'","'I00B'")
    */

endlibrary



/*for redundancy, here are the examples again.
you can name the scopes whatever you want, and the textmacro names being run here
have to match up with the textmacro that were declared above. for ammo stacking,
we have "itemA","itemB","chargecount".  this is the textmacro that improves the
stacking so that we can stack not just 1 charge items, but 2 or higher charged items!
it uses kingkingyyk3's system.  don't forget to add the "itemB" here to the zinc library
as already explained above.*/

/*START OF EXAMPLES
scope ammoa initializer I
    //! runtextmacro ammostacking("'I00C'","'whwd'","2")

scope ammob initializer I
    //! runtextmacro ammostacking("'I00D'","'mcri'","5")

/*second example is the itemswitching.  again we simply have itemA, which is the item
for the unit type listed in the above textmacro.  if the unit does not correspond to the
unit type in the textmacro that you have, it gets itemB isntead of itemA when it tries
to pick up ItemA.  you can of course add a second textmacro to reverse it. once again,
name the scope whatever you want.*/
scope switcha initializer I
    //! runtextmacro itemswitching("'mcri'","'I00B'")

/*lastly we have the actual automatic item stacking.  itemA is your fake item and itemB
is the real item.  the same goes for the ammostacking...itemA is fake and itemB is real.
the fake items need to be perishable and use when acquired and have no abilities.*/
scope stacka initializer I
    //! runtextmacro itemstacking("'desc'","'I007'")

scope stackb initializer I
    //! runtextmacro itemstacking("'fgsk'","'I008'")

scope stackc initializer I
    //! runtextmacro itemstacking("'fgfh'","'I009'")

scope stackd initializer I
    //! runtextmacro itemstacking("'pclr'","'I005'")

scope stacke initializer I
    //! runtextmacro itemstacking("'pman'","'I006'")

scope stackf initializer I
    //! runtextmacro itemstacking("'tgxp'","'I002'")

scope stackg initializer I
    //! runtextmacro itemstacking("'pams'","'I004'")

scope stackh initializer I
    //! runtextmacro itemstacking("'moon'","'I003'")
END OF EXAMPLES*/

I think it could probably use some additional features but I think it's a decent start and sometimes huge masses of code scare me, so I imagine they'd scare other people, too.

in case you're wondering about the numbers...in my original code i was using it in the map where the 0 slot item is a permanent item for the heroes that every hero gets...kindof like a scroll of tp that never goes away
i think i fixed all that rather easily enough.

edit: added code indentation to the jassbox.
update: added support for charge merging with kingkingyyk3's unit inventory data system.
update: made a library for it...update:idk where that old beta version of itemswitching came from, but i just replaced it. idk how long it was there, for...

Notes:
is compatible with the following system:
Click Me!
wink.gif

Advantages to using this system:
good for gui newbs or jass newbs alike - anyone who can read rawdata and edit items can use it easily. just copy and paste the jass and edit it with your rawdata. (use ctrl d in your editor to view rawdata)
Disadvantages: it doesn't feature backpacks like mmorpg or inventories past 6 items or anything like that.
 

Attachments

  • StackItems.w3x
    88.8 KB · Views: 338

SanKakU

Member
Reaction score
21
indents please?

you can indent the code and post it if you like, and i can update my original post jassbox. i dislike code indentation.

edit: oh what am i saying? i'll do it even though i don't like it.

edit2: ok, done. that wasn't a big deal because like i said the code is short. what do you think?
 

SanKakU

Member
Reaction score
21
charge merging is probably a good idea. kindof depends on the map needs. i haven't really thought about how that works exactly. i'm sure it would be more important for maps where the heroes are like using lots of ammo or something like that.
 

Romek

Super Moderator
Reaction score
963
Click
I'll move this back now, anyhow.

Edit: Or perhaps not; this was posted within 90 days, so it can't have been graveyarded for that reason.
Perhaps Ghan made a mistake, or didn't think this was approve-worthy?
I'll keep it here until a moderator reviews this.
 

SanKakU

Member
Reaction score
21

just for clarification i wanted to add that i did update the original post in response to this post. oh i better + rep him i think i forgot to do that thus far.

also, if anyone else has ideas of what to add to the snippet, or has made your own snippets or systems that this snippet would be compatible with, feel free to post it here.

i think i might add a textmacro scope base for item recipes but i'm not sure.

if i do i guess this snippet would perhaps evolve into a system at that point.
if it becomes a system i might want to add a test map for it.
if you guys are looking for one right now and can't wait for that, you can use the one kingy linked to but you have to edit it for this snippet. just follow my instructions.
 

Chaos_Knight

New Member
Reaction score
39
I mean, in the Script, people forgets what [LJASS]//! runtextmacro "Whatever" Does "Whatever"[/LJASS]
Does.
 

SanKakU

Member
Reaction score
21
ok, i added a lot more comments. hopefully that'll explain everything properly for you.

basically... you type in your own //! runtextmacro itemstack("'xxxx'","'xxxx'") lines.
the xxxx is the item code of the items in your object editor that need stacking.
 

SanKakU

Member
Reaction score
21
great, let me know if you run into any problems using it or if you have an idea of something you want me to add.
 

SanKakU

Member
Reaction score
21
"Shouldn't it be in a library..?"

as long as it's all in the one trigger, it's fine. you don't need to put it in a library. unless you somehow have conflicting names with it, then you might need to put it in a library and make them public functions or something like that.

those textmacros with their scope declaration are just two lines each. you really don't need to make a trigger for each. that's tedious. if you want to put the non scope section in a library and put the scope section in a single trigger, that's fine. i would recommend your primary map library, if you've got one. although if you want to use those functions in other systems, then yes, you would definitely want it in a library.

i suppose, if you wanted to put sets of textmacros in other scopes or libraries, i can see why you might want to put those functions in a library. i just can't think of any examples at the moment. do you have any?

edit: ok, TTE, it's a library now. guess it's no longer a snippet, though.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top