• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Item Stack JASS - Please Verify

Status
Not open for further replies.
Level 7
Joined
May 21, 2009
Messages
289
I have this JASS trigger, can I just copy and paste it into another map err right? And items will still stack? AND does this trigger stack every item that is acquired?
JASS trigger-


JASS:
function Combine_Items_Conditions takes nothing returns boolean
    return GetItemCharges(GetManipulatedItem()) > 0 
endfunction

function Combine_Items_Actions takes nothing returns nothing
    local item NEWITEM = GetManipulatedItem()
    local unit OURUNIT = GetManipulatingUnit()
    local integer MAXIMUM = 15  //The max no. of charges allowed
    local integer ITEMCOUNT = 0
    local integer ITEMLOOP = 0
    local integer CHARGES = 0
    
    loop
        exitwhen ITEMLOOP > 6
        if GetItemTypeId(NEWITEM) == GetItemTypeId(UnitItemInSlot(OURUNIT, ITEMLOOP)) then
            if GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM) <= MAXIMUM then
                if not (UnitItemInSlot(OURUNIT, ITEMLOOP) == NEWITEM) then                
                    set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM)
                    call SetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP), CHARGES)
                    call RemoveItem(NEWITEM)
                    set ITEMLOOP = 7
                endif
            endif
        endif
        if (ITEMLOOP < 7) then
            set ITEMLOOP = ITEMLOOP + 1
        endif
    endloop
EDIT:
probably should have put this under Triggering and Script= sorry people
 
A little better.

JASS:
function Combine_Items_Conditions takes nothing returns boolean
    return GetItemCharges(GetManipulatedItem()) > 0
endfunction

function Combine_Items_Actions takes nothing returns nothing
    local item NEWITEM = GetManipulatedItem()
    local unit OURUNIT = GetManipulatingUnit()
    local integer id = GetItemTypeId(NEWITEM) // saves function calls
    local integer c  = GetItemCharges(NEWITEM) // saves function calls
    local integer MAXIMUM = 15  //The max no. of charges allowed
    local integer ITEMCOUNT = 0
    local integer ITEMLOOP = 0
    local integer CHARGES = 0

    loop
        exitwhen ITEMLOOP > 6
        if id == GetItemTypeId(UnitItemInSlot(OURUNIT, ITEMLOOP)) then
            if GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + c <= MAXIMUM then
                if not (UnitItemInSlot(OURUNIT, ITEMLOOP) == NEWITEM) then
                    set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM)
                    call SetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP), CHARGES)
                    call RemoveItem(NEWITEM)
                    set ITEMLOOP = 7
                endif
            endif
        endif
        if (ITEMLOOP < 7) then
            set ITEMLOOP = ITEMLOOP + 1
        endif
    endloop
    
    set OURUNIT = null // Leaks otherwise.
    set NEWITEM = null
endfunction
 
On the current trigger it will cause another stack... but you can add some ELSE line for the
JASS:
IfGetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + c <= MAXIMUM
so that it will drop the item if the charges will reach max.... I'm not sure about that but It may work... anyway change

JASS:
setCHARGES=GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP))+GetItemCharge(NEWITEM)

to

JASS:
set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + c

I think he just forgot it...
 
which function would i put this in? or would i just paste it at the bottom?

before the second endif if I'm correct..

JASS:
if id == GetItemTypeId(UnitItemInSlot(OURUNIT, ITEMLOOP)) then            
   if GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + c <= MAXIMUM then               
          if not (UnitItemInSlot(OURUNIT, ITEMLOOP) == NEWITEM) then                    
          set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + c                  
          call SetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP), CHARGES)                    
          call RemoveItem(NEWITEM)                    
          set ITEMLOOP = 7                
          endif
    else
    //actions            
    endif        
endif
 
what problem do you get? do you only paste the trigger you posted?

it should have some line at the bottom...

make a trigger with the event Unit-Acquires an item and convert it to custom script then copy paste all lines after the
//====================================

then change some of the values to your trigger's
like this
JASS:
set gg_Trig_xxxx = CreateTrigger() //set the xxxx to your trigger's name
call TriggerResgisterEvent = xxx //only change the trigger name not the event
//for all function names change it to the names of the functions in your trigger... I think you can do it yourself, I'm not with my WE so I cannot check the right ones for you.. sorry.

and yes, just add (your script) after the else
 
Status
Not open for further replies.
Back
Top