| 04-05-2009, 12:03 PM | #1 | |
JASS:library BackpackSys initializer Init requires PUI, Table globals private constant integer BackpackId = 'BAG1' private boolean drop = false private constant integer MAX_ABILITIES = 6 private trigger Pickup = null private trigger Drop = null private Table DataTable = 0 endglobals public struct data integer ItemId = 0 integer Str = 0 integer Agi = 0 integer Int = 0 real Damage = 0.00 real Armor = 0.00 real MaxLife = 0.00 real MaxMana = 0.00 real LifeRegen = 0.00 real ManaRegen = 0.00 real AttackSpeed = 0.00 real MoveSpeed = 0.00 integer array Abilities[MAX_ABILITIES] integer array AbilityLevels[MAX_ABILITIES] static method create takes integer ItemId returns data local data d = data.allocate() local integer i = 0 loop set d.Abilities[i] = 0 set d.AbilityLevels[i] = 1 set i = i+1 exitwhen i >= MAX_ABILITIES endloop set d.ItemId = ItemId set DataTable[ItemId] = d return d endmethod endstruct //! textmacro CheckAndApply takes VALUE if d.$VALUE$ != 0 then set $VALUE$[u] = $VALUE$[u] + d.$VALUE$ // set Property[Unit] = Property[Unit] + x endif //! endtextmacro //! textmacro CheckAndUnapply takes VALUE if d.$VALUE$ != 0 then set $VALUE$[u] = $VALUE$[u] + -1*d.$VALUE$ endif //! endtextmacro function UnitApplyItem takes unit U, data d returns nothing local integer i //! runtextmacro CheckAndApply("Str") //! runtextmacro CheckAndApply("Agi") //! runtextmacro CheckAndApply("Int") //! runtextmacro CheckAndApply("Damage") //! runtextmacro CheckAndApply("Armor") //! runtextmacro CheckAndApply("MaxLife") //! runtextmacro CheckAndApply("MaxMana") //! runtextmacro CheckAndApply("LifeRegen") //! runtextmacro CheckAndApply("ManaRegen") //! runtextmacro CheckAndApply("AttackSpeed") //! runtextmacro CheckAndApply("MoveSpeed") if d.Abilities[0] != 0 then set i = 0 loop call UnitAddAbility(U, d.Abilities[i]) call SetUnitAbilityLevel(U, d.Abilities[i], d.AbilityLevels[i]) set i = i+1 exitwhen d.Abilities[i] == 0 or i >= MAX_ABILITIES endloop endif endfunction function UnitUnapplyItem takes unit U, data d returns nothing local integer i //! runtextmacro CheckAndUnapply("Str") //! runtextmacro CheckAndUnapply("Agi") //! runtextmacro CheckAndUnapply("Int") //! runtextmacro CheckAndUnapply("Damage") //! runtextmacro CheckAndUnapply("Armor") //! runtextmacro CheckAndUnapply("MaxLife") //! runtextmacro CheckAndUnapply("MaxMana") //! runtextmacro CheckAndUnapply("LifeRegen") //! runtextmacro CheckAndUnapply("ManaRegen") //! runtextmacro CheckAndUnapply("AttackSpeed") //! runtextmacro CheckAndUnapply("MoveSpeed") if d.Abilities[0] != 0 then set i = 0 loop call UnitRemoveAbility(U, d.Abilities[i]) set i = i+1 exitwhen d.Abilities[i] == 0 or i >= MAX_ABILITIES endloop endif endfunction private function onPickup takes nothing returns nothing local data d = DataTable[GetItemTypeId(GetManipulatedItem())] if d > 0 then call UnitApplyItem(GetTriggerUnit(), d) endif endfunction private function onDrop takes nothing returns nothing local data d = DataTable[GetItemTypeId(GetManipulatedItem())] if d > 0 then call UnitUnapplyItem(GetTriggerUnit(), d) endif endfunction public struct Data //! runtextmacro PUI() integer array ItemType[6] integer array Charges[6] integer array UserData[6] static method create takes unit u returns Data local Data d = Data.allocate() local data c 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) set c = DataTable[d.ItemType[i]] call UnitApplyItem(u,c) 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 > 6 endloop set drop = true set it = null return d endmethod endstruct function ActivateBackpack takes unit target returns nothing local Data d1 local Data d2 = Data[target] local Data d local integer i = 0 local item it if GetSpellAbilityId() == BackpackId then set d1 = Data.create(target) if d2 != 0 then loop if d2.ItemType[i] != 0 then 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) endif set i = i + 1 exitwhen i > 6 endloop endif call d2.release() set Data[target] = d1 endif set it = null set drop = false endfunction private function Init takes nothing returns nothing local data d set DataTable = Table.create() set d = data.create('I000') set d.Damage = 100 set d.Agi = 200 set d.Armor = 50 set Pickup = CreateTrigger() set d = data.create('I001') set d.Str = 50 call TriggerRegisterAnyUnitEventBJ(Pickup, EVENT_PLAYER_UNIT_PICKUP_ITEM) call TriggerAddAction(Pickup, function onPickup) set Drop = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(Drop, EVENT_PLAYER_UNIT_DROP_ITEM) call TriggerAddAction(Drop, function onDrop) endfunction endlibrary Quote:
The link to download map is here http://www.thehelper.net/forums/show...78#post1002778 |
| 04-05-2009, 12:22 PM | #2 |
Are you submitting, sharing or asking for help with usage/coding about this? :/ |
| 04-05-2009, 12:33 PM | #3 |
This sthing bug, all times i change da inventory screen i lose 1 item |
| 04-05-2009, 12:42 PM | #4 |
I am just asking for comments. It does not bug it has been tested. Send me the replay file for that bugged one if you have. |
| 04-05-2009, 12:58 PM | #5 |
| 04-05-2009, 01:18 PM | #6 |
The reason the item disappeard was because it was moved to the backpack and you need to cast the spell again to take the item out of your backpack, understood? |
| 04-05-2009, 08:43 PM | #7 |
Look the replay maybe ? 2 inventory (6 slots and 6 slots) i use all slots, i swap inventory, i have my 6 items from inventory 1, i swap inventory, i have 5 item in inventory 2 and on disppeard, i swap again to inventory 1 i have my 6 item, i swap again to inventory 2 i have only 4 item ! But ok ok it don't bug |
