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:
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:
5) don't forget to get GT and if you want to utilize the ammo charge stacking feature, UID
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:
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.
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:
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.