HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

New Backpack not working

06-01-2009, 03:55 PM#1
wraithseeker
Bump, code update and problem right now is that if I hold x items in my inventory and then x items in my backpack and then I cast the spell backpack. They all get together in my inventory??

Collapse JASS:
struct backpack extends face
    integer array ItemType[6]
    integer array Charges[6]
    integer array UserData[6]    
    boolean Where = false
    
    static method create takes unit u returns backpack
        local backpack d = backpack.allocate()
        set d.Where = false
        return d
    endmethod
    implement AutoData
endstruct
function Store takes unit u returns nothing
    local backpack d = backpack[u]
    local backpack c
    local bonus a
    local bonus r
    local integer i = 0
    local item it
    local integer j = 0
    loop
        set it = UnitItemInSlot(u, i)
        set d.ItemType[i] = GetItemTypeId(it)
        set d.Charges[i] = GetItemCharges(it)
        set d.UserData[i] = GetItemUserData(it)
        set c = DataTable[d.ItemType[i]]
        set a = GetItemUserData(it)
        call UnitApplyItem(u,c)
        call RemoveItem(it)
        call UnitApplyAbilities(u,c)
        call UnitApplyItem(u,a)
        call RemoveItem(it)
        call UnitApplyAbilities(u,a)
        set i = i + 1
        exitwhen i > 5
    endloop
    loop
        exitwhen j >= bonus.Count
        set r = bonus.D[j]
        if BackCheck(r,d) then
            call UnitApplyItem(u,r)
            call UnitApplyAbilities(u,r)
        endif
        set j = j + 1
    endloop
    if d.OnMove.exists then
        call d.OnMove(u)
    endif
    set d.Where = true
    set it = null
endfunction

function ActivateBackpack takes nothing returns boolean
    local unit target = GetTriggerUnit()
    local backpack d1
    local backpack d2 = backpack[target]
    local backpack d
    local integer i = 0
    local integer j = 0
    local item it
    local bonus a
    local bonus r
    local boolean done = false
    if GetSpellAbilityId() == BackpackId then
        if d2.Where == true then
            loop
                exitwhen j >= bonus.Count
                set r = bonus.D[j]
                if BackCheck(r,d2) then
                    call UnitUnapplyItem(target,r)
                    call UnitApplyAbilities(target,r)
                endif
                set j = j + 1
            endloop
            loop
                if d2.ItemType[i] != 0  then
                    call BJDebugMsg("Adding items")
                    set it = UnitAddItemById(target, d2.ItemType[i])
                    call SetItemCharges(it, d2.Charges[i])
                    call SetItemUserData(it, d2.UserData[i])
                    set d = DataTable[d2.ItemType[i]]
                    call UnitUnapplyItem(target,d)
                    call UnitApplyAbilities(target,d)
                    endif
                set i = i + 1
                exitwhen i > 5
            endloop
            set d2.Where = false
        elseif d2.Where == false then
            call Store(target)
        endif
    set backpack[target] = d1
    endif
    set it = null
    return false
endfunction

function CreateBackpack takes unit u returns nothing
    local backpack d = backpack[u]
    if d == 0 then
        set d = backpack.create(u)
    endif
endfunction
06-03-2009, 06:27 AM#2
wraithseeker
bump