• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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
 
Level 7
Joined
May 21, 2009
Messages
289
Lol ok ill could just disable my 10 GUI triggers and use this one...much cleaner and where it says "max number of charges" what happens when the player reaches max? Do they start another stack? Because I dont want 2 stacks.
 
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.
Top