HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Calling all Jass Guru to help me with my system

02-22-2009, 03:41 AM#1
wraithseeker
Collapse JASS:
library BackpackSys

globals
    private constant integer BackpackId = 'BAG1'
    //Change this to the ID of the backpack item in your map.
endglobals

private struct Data
    integer array ItemType[6]
    integer array Charges[6]
    integer array UserData[6]
    static method Create takes unit u returns Data
        local Data d = Data.create()
        local integer i = 0
        local item it
        local integer id
        loop
            set it = UnitItemInSlot(u, i)
            set id = GetItemTypeId(it)
            if GetSpellAbilityId() == BackpackId then
                set d.ItemType[i] = id
                set d.Charges[i] = GetItemCharges(it)
                set d.UserData[i] = GetItemUserData(it)
                call RemoveItem(it)
            else
                set d.ItemType[i] = 0
                set d.Charges[i] = 0
                set d.UserData[i] = 0
            endif
            set i = i + 1
            exitwhen i > 5
        endloop
        set it = null
        return d
    endmethod
endstruct

function InventoryCache takes nothing returns gamecache
   if udg_ItemCache == null then
        call FlushGameCache(InitGameCache("ItemCache.w3v"))
        set udg_ItemCache = InitGameCache("InventoryCache.w3v")
            endif
            return udg_ItemCache
endfunction

function SetItemBonuses takes integer itemId, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil returns nothing
    local gamecache g = InventoryCache()
    local string s = I2S(itemId)
        if dmg > 0 then
            call StoreInteger(g, s, "damage", dmg)
        endif
        if arm > 0 then
            call StoreInteger(g, s, "armor", arm)
        endif
        if hp > 0 then
            call StoreInteger(g, s, "hitpoints", hp)
        endif
        if mp > 0 then
           call StoreInteger(g, s, "manapoints", mp)
        endif
        if str > 0 then
            call StoreInteger(g, s, "strength", str)
        endif
        if agi > 0 then
            call StoreInteger(g, s, "agility", agi)
        endif
        if int > 0 then
            call StoreInteger(g, s, "intelligence", int)
        endif
       // if abil > 0 then
         //   call StoreInteger(g, s, "ability", PreloadAbility(abil))
       // endif
    set g = null
endfunction

//*******************************************************************************
// These wrappers use operator overloading to allow a more intuitive syntax than
// UnitSet/Modify/GetProperty():
//
// set Unit:Property = x
// or
// set Property[Unit] = x
//
// To modify a property rather than set it to a specific value:
//
// set Unit:Property = Unit:Property + x
// or
// set Property[Unit] = Property[Unit] + x
//
function AddBonus takes unit whichUnit, string s, item it returns nothing
    local string x
    local gamecache g = InventoryCache()
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
    local string p = "debugging"
        set v = GetStoredInteger(g, m, "damage")
        if v > 0 then
            set whichUnit:Damage = whichUnit:Damage + v
        endif
        set v = GetStoredInteger(g, m, "armor")
        if v > 0 then
               set whichUnit:Armor = whichUnit:Armor + v
        endif
        set v = GetStoredInteger(g, m, "hitpoints")
        if v > 0 then
              set whichUnit:Life = whichUnit:Life + v
        endif
        set v = GetStoredInteger(g, m, "manapoints")
        if v > 0 then
              set whichUnit:Mana = whichUnit:Mana + v
        endif
        set v = GetStoredInteger(g, m, "strength")
        if v > 0 then
            set whichUnit:Str = whichUnit:Str + v
        endif
        set v = GetStoredInteger(g, m, "agility")
        if v > 0 then
              set whichUnit:Agi = whichUnit:Agi + v
        endif
        set v = GetStoredInteger(g, m, "intelligence")
        if v > 0 then
               set whichUnit:Int = whichUnit:Int + v
        endif
        set v = GetStoredInteger(g, m, "ability")
        //if v > 0 then
         //   set a = "Ability"+I2S(v)
          //  set l = GetTableInt(s, a)-1
           // call SetTableInt(s, a, l)
          //  if l < 1 then
          //      call UnitRemoveAbility(c, v)
        //    endif
      //  endif
    set g = null
    call BJDebugMsg(p)
endfunction

function RemoveBonus takes unit whichUnit, string s, item it returns nothing
    local string x
    local gamecache g = InventoryCache()
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
    set v = GetStoredInteger(g, m, "damage")
    if v > 0 then
        set whichUnit:Damage = whichUnit:Damage + -v
    endif
    set v = GetStoredInteger(g, m, "armor")
    if v > 0 then
        set whichUnit:Armor = whichUnit:Armor + -v
    endif
    set v = GetStoredInteger(g, m, "hitpoints")
    if v > 0 then
         set whichUnit:Life = whichUnit:Life + -v    
         endif
    set v = GetStoredInteger(g, m, "manapoints")
    if v > 0 then
        set whichUnit:Mana = whichUnit:Mana + -v    
    endif
    set v = GetStoredInteger(g, m, "strength")
    if v > 0 then
        set whichUnit:Str = whichUnit:Str + -v        
        endif
    set v = GetStoredInteger(g, m, "agility")
    if v > 0 then
        set whichUnit:Agi = whichUnit:Agi + -v    
    endif
    set v = GetStoredInteger(g, m, "intelligence")
    if v > 0 then
        set whichUnit:Int = whichUnit:Int + -v    
    endif
    set g = null
endfunction

function ActivateBackpack takes unit whichUnit returns nothing
    local Data d1
    local Data d2 = GetUnitUserData(whichUnit)
    local integer i = 0
    local item it
    local string s
    if GetSpellAbilityId() == BackpackId then
        set d1 = Data.Create(whichUnit)
        if d2 != 0 then
            loop
                if d2.ItemType[i] != 0  then
                    set it = UnitAddItemById(whichUnit, d2.ItemType[i])
                    set s = I2S(GetItemTypeId(it))
                    call AddBonus(whichUnit,s,it)
                    call SetItemCharges(it, d2.Charges[i])
                    call SetItemUserData(it, d2.UserData[i])
                endif
                set i = i + 1
                exitwhen i > 5
            endloop
        endif
        call d2.destroy()
        call SetUnitUserData(whichUnit, d1)
    endif
    set it = null
endfunction

function SetupItembonus takes nothing returns nothing
call SetItemBonuses('rat6',6,2,1,4,5,3,2,0)
    endfunction
    
endlibrary
This thing does not work, It uses the newest BonusMod aka Unitproperties.

It took me like a day to get this stuff up and running. Can any gurus tell me how do I fix this stuff?.The item stats do not go over when items are at the backpack, I used the Rat6 aka Blades of attack + 6 as a test demo and doesn't work

It's supposed to be a 12 inventory slot system that keeps stats / bonus of items even when it's in the backpack.

The map is attached below so you can take a look. It is so complicated to me I can't figure it out anymore.

Some parts are taken from AAAInventory by Blade.DK
Attached Files
File type: w3xUnitProperties.vD.w3x (75.5 KB)
02-22-2009, 03:44 AM#2
TriggerHappy
Looks like you just c/p'd the functions from AAAInventory.
02-22-2009, 04:32 AM#3
wraithseeker
No I didnt , I took out some parts which either I don't think its needed and some which I don't know
02-23-2009, 05:42 AM#4
wraithseeker
Bump
02-24-2009, 08:18 AM#5
wraithseeker
Bump
02-27-2009, 04:38 AM#6
wraithseeker
Collapse JASS:
library BackpackSys

globals
    private constant integer BackpackId = 'BAG1'
    //Change this to the ID of the backpack item in your map.
endglobals

private struct Data
    integer array ItemType[6]
    integer array Charges[6]
    integer array UserData[6]
    static method Create takes unit u returns Data
        local Data d = Data.create()
        local integer i = 0
        local item it
        local integer id
        loop
            set it = UnitItemInSlot(u, i)
            set id = GetItemTypeId(it)
            if GetSpellAbilityId() == BackpackId then
                set d.ItemType[i] = id
                set d.Charges[i] = GetItemCharges(it)
                set d.UserData[i] = GetItemUserData(it)
                call RemoveItem(it)
            else
                set d.ItemType[i] = 0
                set d.Charges[i] = 0
                set d.UserData[i] = 0
            endif
            set i = i + 1
            exitwhen i > 5
        endloop
        set it = null
        return d
    endmethod
endstruct

function InventoryCache takes nothing returns gamecache
   if udg_ItemCache == null then
        call FlushGameCache(InitGameCache("ItemCache.w3v"))
        set udg_ItemCache = InitGameCache("InventoryCache.w3v")
            endif
            return udg_ItemCache
endfunction

function SetItemBonuses takes integer itemId, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil returns nothing
    local gamecache g = InventoryCache()
    local string s = I2S(itemId)
        if dmg > 0 then
            call StoreInteger(g, s, "damage", dmg)
        endif
        if arm > 0 then
            call StoreInteger(g, s, "armor", arm)
        endif
        if hp > 0 then
            call StoreInteger(g, s, "hitpoints", hp)
        endif
        if mp > 0 then
           call StoreInteger(g, s, "manapoints", mp)
        endif
        if str > 0 then
            call StoreInteger(g, s, "strength", str)
        endif
        if agi > 0 then
            call StoreInteger(g, s, "agility", agi)
        endif
        if int > 0 then
            call StoreInteger(g, s, "intelligence", int)
        endif
       // if abil > 0 then
         //   call StoreInteger(g, s, "ability", PreloadAbility(abil))
       // endif
    set g = null
endfunction

//*******************************************************************************
// These wrappers use operator overloading to allow a more intuitive syntax than
// UnitSet/Modify/GetProperty():
//
// set Unit:Property = x
// or
// set Property[Unit] = x
//
// To modify a property rather than set it to a specific value:
//
// set Unit:Property = Unit:Property + x
// or
// set Property[Unit] = Property[Unit] + x
//
function AddBonus takes unit whichUnit, string s, item it returns nothing
    local string x
    local gamecache g = InventoryCache()
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
    local string p = "debugging"
        set v = GetStoredInteger(g, m, "damage")
        if v > 0 then
            set whichUnit:Damage = whichUnit:Damage + v
        endif
        set v = GetStoredInteger(g, m, "armor")
        if v > 0 then
               set whichUnit:Armor = whichUnit:Armor + v
        endif
        set v = GetStoredInteger(g, m, "hitpoints")
        if v > 0 then
              set whichUnit:Life = whichUnit:Life + v
        endif
        set v = GetStoredInteger(g, m, "manapoints")
        if v > 0 then
              set whichUnit:Mana = whichUnit:Mana + v
        endif
        set v = GetStoredInteger(g, m, "strength")
        if v > 0 then
            set whichUnit:Str = whichUnit:Str + v
        endif
        set v = GetStoredInteger(g, m, "agility")
        if v > 0 then
              set whichUnit:Agi = whichUnit:Agi + v
        endif
        set v = GetStoredInteger(g, m, "intelligence")
        if v > 0 then
               set whichUnit:Int = whichUnit:Int + v
        endif
        set v = GetStoredInteger(g, m, "ability")
        //if v > 0 then
         //   set a = "Ability"+I2S(v)
          //  set l = GetTableInt(s, a)-1
           // call SetTableInt(s, a, l)
          //  if l < 1 then
          //      call UnitRemoveAbility(c, v)
        //    endif
      //  endif
    set g = null
    call BJDebugMsg(p)
endfunction

function RemoveBonus takes unit whichUnit, string s, item it returns nothing
    local string x
    local gamecache g = InventoryCache()
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
    set v = GetStoredInteger(g, m, "damage")
    if v > 0 then
        set whichUnit:Damage = whichUnit:Damage + -v
    endif
    set v = GetStoredInteger(g, m, "armor")
    if v > 0 then
        set whichUnit:Armor = whichUnit:Armor + -v
    endif
    set v = GetStoredInteger(g, m, "hitpoints")
    if v > 0 then
         set whichUnit:Life = whichUnit:Life + -v    
         endif
    set v = GetStoredInteger(g, m, "manapoints")
    if v > 0 then
        set whichUnit:Mana = whichUnit:Mana + -v    
    endif
    set v = GetStoredInteger(g, m, "strength")
    if v > 0 then
        set whichUnit:Str = whichUnit:Str + -v        
        endif
    set v = GetStoredInteger(g, m, "agility")
    if v > 0 then
        set whichUnit:Agi = whichUnit:Agi + -v    
    endif
    set v = GetStoredInteger(g, m, "intelligence")
    if v > 0 then
        set whichUnit:Int = whichUnit:Int + -v    
    endif
    set g = null
endfunction

function ActivateBackpack takes unit whichUnit returns nothing
    local Data d1
    local Data d2 = GetUnitUserData(whichUnit)
    local integer i = 0
    local item it
    local string s
    if GetSpellAbilityId() == BackpackId then
        set d1 = Data.Create(whichUnit)
        if d2 != 0 then
            loop
                if d2.ItemType[i] != 0  then
                    set it = UnitAddItemById(whichUnit, d2.ItemType[i])
                    set s = I2S(GetItemTypeId(it))
                    call AddBonus(whichUnit,s,it)
                    call SetItemCharges(it, d2.Charges[i])
                    call SetItemUserData(it, d2.UserData[i])
                endif
                set i = i + 1
                exitwhen i > 5
            endloop
        endif
        call d2.destroy()
        call SetUnitUserData(whichUnit, d1)
    endif
    set it = null
endfunction

function SetupItembonus takes nothing returns nothing
call SetItemBonuses('rat6',6,2,1,4,5,3,2,0)
    endfunction
    
endlibrary

Doesn't work...

And.... Doesn't work either.

Collapse JASS:
library BackpackSys

globals
    private constant integer BackpackId = 'BAG1'
    //Change this to the ID of the backpack item in your map.
endglobals

private struct Data
    integer array ItemType[6]
    integer array Charges[6]
    integer array UserData[6]
    static method Create takes unit u returns Data
        local Data d = Data.create()
        local integer i = 0
        local item it
        local integer id
        loop
            set it = UnitItemInSlot(u, i)
            set id = GetItemTypeId(it)
            if GetSpellAbilityId() == BackpackId then
                set d.ItemType[i] = id
                set d.Charges[i] = GetItemCharges(it)
                set d.UserData[i] = GetItemUserData(it)
                call RemoveItem(it)
            else
                set d.ItemType[i] = 0
                set d.Charges[i] = 0
                set d.UserData[i] = 0
            endif
            set i = i + 1
            exitwhen i > 5
        endloop
        set it = null
        return d
    endmethod
endstruct

private struct Bonus
integer itemId
integer dmg
integer arm
integer hp
integer mp
integer str
integer agi
integer int
integer abil
endstruct

function SetItemBonuses takes integer itemId, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil returns nothing
    local Bonus d
    local string s = I2S(itemId)
        if dmg > 0 then
            set d.dmg = dmg
        endif
        if arm > 0 then
            set d.arm = arm
        endif
        if hp > 0 then
            set d.hp = hp
        endif
        if mp > 0 then
           set d.mp = mp
        endif
        if str > 0 then
           set d.str = str
        endif
        if agi > 0 then
            set d.agi = agi
        endif
        if int > 0 then
           set d.int = int
        endif
       // if abil > 0 then
         //   call StoreInteger(g, s, "ability", PreloadAbility(abil))
       // endif
endfunction

//*******************************************************************************
// These wrappers use operator overloading to allow a more intuitive syntax than
// UnitSet/Modify/GetProperty():
//
// set Unit:Property = x
// or
// set Property[Unit] = x
//
// To modify a property rather than set it to a specific value:
//
// set Unit:Property = Unit:Property + x
// or
// set Property[Unit] = Property[Unit] + x
//
function AddBonus takes unit whichUnit, string s, item it returns nothing
    local Bonus d
    local string x
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
        set v = d.dmg
        if v > 0 then
            set whichUnit:Damage = whichUnit:Damage + v
        endif
        set v = d.arm
        if v > 0 then
               set whichUnit:Armor = whichUnit:Armor + v
        endif
        set v = d.hp
        if v > 0 then
              set whichUnit:Life = whichUnit:Life + v
        endif
        set v = d.mp
        if v > 0 then
              set whichUnit:Mana = whichUnit:Mana + v
        endif
        set v = d.str
        if v > 0 then
            set whichUnit:Str = whichUnit:Str + v
        endif
        set v = d.agi
        if v > 0 then
              set whichUnit:Agi = whichUnit:Agi + v
        endif
        set v = d.int
        if v > 0 then
               set whichUnit:Int = whichUnit:Int + v
        endif
        //set v = GetStoredInteger(g, m, "ability")
        //if v > 0 then
         //   set a = "Ability"+I2S(v)
          //  set l = GetTableInt(s, a)-1
           // call SetTableInt(s, a, l)
          //  if l < 1 then
          //      call UnitRemoveAbility(c, v)
        //    endif
      //  endif
  
    call BJDebugMsg("DEBUG")
endfunction

function RemoveBonus takes unit whichUnit, string s, item it returns nothing
    local Bonus d
    local string x
    local string m = I2S(GetItemTypeId(it))
    local integer v
    local string a
    local integer l
    set v = d.dmg
    if v > 0 then
        set whichUnit:Damage = whichUnit:Damage + -v
    endif
    set v = d.arm
    if v > 0 then
        set whichUnit:Armor = whichUnit:Armor + -v
    endif
    set v = d.hp
    if v > 0 then
         set whichUnit:Life = whichUnit:Life + -v    
         endif
    set v = d.mp
    if v > 0 then
        set whichUnit:Mana = whichUnit:Mana + -v    
    endif
    set v = d.str
    if v > 0 then
        set whichUnit:Str = whichUnit:Str + -v        
        endif
    set v = d.agi
    if v > 0 then
        set whichUnit:Agi = whichUnit:Agi + -v    
    endif
    set v = d.int
    if v > 0 then
        set whichUnit:Int = whichUnit:Int + -v    
    endif
endfunction

function ActivateBackpack takes unit whichUnit returns nothing
    local Data d1
    local Data d2 = GetUnitUserData(whichUnit)
    local integer i = 0
    local item it
    local string s
    if GetSpellAbilityId() == BackpackId then
        set d1 = Data.Create(whichUnit)
        if d2 != 0 then
            loop
                if d2.ItemType[i] != 0  then
                    set it = UnitAddItemById(whichUnit, d2.ItemType[i])
                    set s = I2S(GetItemTypeId(it))
                    call AddBonus(whichUnit,s,it)
                    call SetItemCharges(it, d2.Charges[i])
                    call SetItemUserData(it, d2.UserData[i])
                endif
                set i = i + 1
                exitwhen i > 5
            endloop
        endif
        call d2.destroy()
        call SetUnitUserData(whichUnit, d1)
    endif
    set it = null
endfunction

function SetupItembonus takes nothing returns nothing
call SetItemBonuses('rat6',6,2,1,4,5,3,2,0)
    endfunction
    
endlibrary
02-28-2009, 02:05 AM#7
azlier
Define 'doesn't work'. It does nothing at all? It does something? Are the correct functions even being called?

And, just because this is a different site doesn't mean I'm not here. I don't even get credit for the backpack part here .
03-01-2009, 12:03 AM#8
wraithseeker
The item backpack works fine but bonuses aren't being applied. I will when the code is done.
03-01-2009, 09:18 AM#9
snowtiger
Quote:
Originally Posted by wraithseeker
No I didnt , I took out some parts which either I don't think its needed and some which I don't know
Doesn't seem smart to me to remove things out of a system that you don't know what they do.
03-01-2009, 09:35 AM#10
wraithseeker
I got 2 triggers , one without AAA inventory.