kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
Bump
You did not deprecate those, you removed them. There's a big difference - one breaks backwards compatibility (not that there is a problem with that in this instance, but you should be aware of the meaning of "deprecate").v1.0.3 : Deprecated : UID_Register/UnregisterOnPickUpItem(trigger), UID_Registe/UnregisterrOnDropItem(trigger), UID_Register/UnregisterOnChangeItemPosition(trigger), UID_Register/UnregisterOnSellItem(trigger), UID_Register/UnregisterOnPawnItem(trigger), UID_Register/UnregisterOnUseItem(trigger), GetItemInUnitBySlot
Laiev, as far as i know, charge splitter doesn't do anything.
And btw, since we're talking about oddities with the way your code is arranged, kingkingyyk3, I should mention that i think it makes more sense to put chargesplitter and chargemerger libraries underneath UID in the same trigger. Like how AIDS has PUI underneath it.
// =========================
// What is Charge Splitter?
// =========================
// Charge Splitter allows auto splitting of
// items' charges when it is moved to
// another slot in inventory of a unit.
JASS:// ========================= // What is Charge Splitter? // ========================= // Charge Splitter allows auto splitting of // items' charges when it is moved to // another slot in inventory of a unit.
So Charge Splitter do a thing... What i say about 'bug' is because the Charge Merger got the same description :thdown:
Also DON'T DO IT kingking =.= don't merge both triggers :nuts::nuts:
library Itemdex initializer init requires optional Table
//**************************************************************
//* Itemdex (Multi-version)
//* -------
//* I need this for many things, something that indexes items
//* Problems of item indexing:
//* a) Only way to detect item death is with a dynamic trigger
//* b) No known way to detect an item removal event. Besides
//* expecting the user to tell you.
//* c) Runes leave some kind of ghost item with 0.0 life that
//* still got all the data of the item , including its type.
//*
//* ...So, I use a loop to do index garbage collection,
//* see you in hell. Luckily it is even rarer to think of 8190
//* items than to think of 8190 units so it should work ok...
//*
//* UserData or Table?
//* ------------------
//* By setting the USE_USER_DATA constant to true, Itemdex will
//* use ItemUserData instead of Table.
//*
//* UserData is faster, if you don't use UserData for other things
//* in your map, it is a good idea to use UserData.
//*
//* If USE_USER_DATA is set to false, you will require Table in
//* your map.
//*
//***************************************************************
//===============================================================
globals
private constant boolean USE_USER_DATA = true
private constant real RECYCLE_INTERVAL = 45.0//2.5
private constant integer RECYCLE_COUNT = 72//10
// Smaller RECYCLE_INTERVAL / Bigger RECYCLE_COUNT equal faster
// detection of removed items and worse performance.
//
// "Every RECYCLE_INTERVAL seconds RECYCLE_COUNT indexes are
// reviewed looking for removed/dead ones to recycle"
endglobals
//=============================================================
private struct index
item attachedto
endstruct
globals
private index array activeIndexes
private integer indexN = 0
private integer DataInteger
endglobals
function GetItemId takes item it returns integer
local index d
//sankaku adds the if then to avoid indexing blank inventory slots...
if it==null then
return 0
endif
static if(USE_USER_DATA) then
set d = index( GetItemUserData(it) )
else
set d = index( HandleTable(DataInteger)[it] )
endif
if(d==0) then
set d = index.create()
set d.attachedto = it
static if(USE_USER_DATA) then
call SetItemUserData(it, integer(d) )
else
set HandleTable(DataInteger)[it] = integer(d)
endif
set activeIndexes[indexN] = d
set indexN = indexN + 1
endif
return integer(d)
endfunction
// Requirements to use ItemdexModule:
// : create takes no arguments
// : no custom .destroy method
//
module Itemdex
private static thistype array V
private item attachedto = null
method operator thatItem takes nothing returns item
return this.attachedto
endmethod
private static method get takes nothing returns nothing
//remind me to add .name to structs
endmethod
static method operator [] takes item it returns thistype
local integer d = GetItemId(it)
static if( DEBUG_MODE) then
if ( (GetItemTypeId(it)==0) or (GetWidgetLife(it)<=0.0) ) then
call BJDebugMsg("Itemdex user error: ghost item used for "+thistype.get.name)
endif
endif
if( (.V[d]!=0) and (.V[d].attachedto != it) ) then
call .V[d].destroy()
set .V[d] = 0
endif
if ( .V[d] == 0) then
set .V[d] = thistype.create()
set .V[d].attachedto = it
endif
return .V[d]
endmethod
method destroy takes nothing returns nothing
local integer d
if ( this.attachedto != null) then
set d = GetItemId( this.attachedto)
set .V[d] = 0
call deallocate()
set this.attachedto = null
else
call deallocate()
endif
endmethod
method release takes nothing returns nothing
call destroy()
endmethod
endmodule
globals
private integer lastindex = 0
endglobals
private function recycleLoop takes nothing returns nothing
local integer start
local integer i
local integer j
if(indexN>0) then
//set start = lastindex % indexN
set start = lastindex - indexN * (lastindex/indexN)
set i=start
set j=0
loop
exitwhen (j>=RECYCLE_COUNT)
if (GetItemTypeId(activeIndexes<i>.attachedto) == 0) or (GetWidgetLife(activeIndexes<i>.attachedto) == 0.0) then
set activeIndexes<i>.attachedto = null
call activeIndexes<i>.destroy()
set indexN = indexN-1
set activeIndexes<i> = activeIndexes[ indexN ]
endif
set i = i +1
exitwhen (indexN==0)
if(i>=indexN) then
set i=0
endif
if(start>=indexN) then
set start = 0
endif
exitwhen(i==start)
set j=j+1
endloop
set lastindex = i
endif
endfunction
private function init takes nothing returns nothing
local timer T= CreateTimer()
static if( not USE_USER_DATA ) then
set DataInteger = integer(HandleTable.create())
endif
call TimerStart(T, RECYCLE_INTERVAL, true, function recycleLoop)
set T=null
endfunction
endlibrary
</i></i></i></i></i>
library UID requires AIDS, T32, Event, Itemdex
globals
public constant integer FIRST_INVENTORY_ID = 852002
public constant integer LAST_INVENTORY_ID = 852007
endglobals
globals
private Event OnMoveItem
private item array MovedItem
private integer array LastPosition
private integer StackLevel = 0
endglobals
public function RegisterOnMoveItem takes trigger trig returns EventReg
return OnMoveItem.register(trig)
endfunction
public function UnregisterOnMoveItem takes trigger trig returns nothing
call OnMoveItem.unregister(trig)
endfunction
private keyword items
private keyword UnitStruct
private struct ItemStruct
integer position
item it
unit owner
boolean isCreated
private method periodic takes nothing returns nothing
if GetItemTypeId(this.it)==0 or GetWidgetLife(it)<=0.0 then
call this.stopPeriodic()
set this.isCreated = false
call this.destroy()
endif
endmethod
static method load takes item i returns thistype
local thistype this = GetItemId(i)
if not this.isCreated then
set this = thistype.allocate()
set this.it = i
set this.position = -1
set this.owner = null
set this.isCreated = true
call this.startPeriodic()
endif
return this
endmethod
implement Itemdex
implement T32x
private static method onInit takes nothing returns nothing
set thistype(0).position = -1
endmethod
endstruct
private type items extends ItemStruct array [6]
private struct UnitStruct extends array
items items
method periodic takes nothing returns nothing
local integer i = 0
local integer maxSize = UnitInventorySize(this.unit)
local item it
loop
exitwhen i == maxSize
set it = UnitItemInSlot(this.unit,i)
if it != null then
set ItemStruct[it].position = i
set ItemStruct[it].owner = this.unit
set this.items<i> = ItemStruct[it]
endif
set i = i + 1
endloop
endmethod
private method AIDS_onCreate takes nothing returns nothing
call this.startPeriodic()
set this.items = items.create()
endmethod
private method AIDS_onDestroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i == 6
set this.items<i>.owner = null
set this.items<i>.position = -1
set i = i + 1
endloop
call this.stopPeriodic()
call this.items.destroy()
endmethod
implement T32x
//! runtextmacro AIDS()
endstruct
function GetItemOwner takes item i returns unit
return ItemStruct<i>.owner
endfunction
function GetItemInventoryPosition takes item i returns integer
return ItemStruct<i>.position
endfunction
function GetMovedItem takes nothing returns item
return MovedItem[StackLevel]
endfunction
function GetLastInventoryPosition takes nothing returns integer
return LastPosition[StackLevel]
endfunction
function GetUnitItemInSlot takes unit u, integer slot returns item
return UnitStruct<u>.items[slot].it
endfunction
private struct Initializer extends array
private static method onPickUp takes nothing returns boolean
local ItemStruct i = ItemStruct.load(GetManipulatedItem())
local integer pos = 0
set i.owner = GetTriggerUnit()
loop
exitwhen pos == 6
if UnitItemInSlot(i.owner,pos) == GetManipulatedItem() then
set i.position = pos
set pos = 5
endif
set pos = pos + 1
endloop
return false
endmethod
private static method onDrop takes nothing returns boolean
local ItemStruct i = ItemStruct.load(GetManipulatedItem())
set UnitStruct[i.owner].items[i.position] = 0
set i.owner = null
set i.position = -1
return false
endmethod
private static method onMove takes nothing returns boolean
local integer orderId = GetIssuedOrderId()
local unit u = GetTriggerUnit()
local integer originalPos
local ItemStruct movedItem
local ItemStruct originalItem
set orderId = orderId - FIRST_INVENTORY_ID
set movedItem = ItemStruct.load(GetOrderTargetItem())
set originalItem = UnitStruct<u>.items[orderId]
if movedItem != originalItem then
if originalItem != 0 then
set originalItem.position = movedItem.position
endif
set originalPos = movedItem.position
set movedItem.position = orderId
set UnitStruct<u>.items[orderId] = movedItem
set UnitStruct<u>.items[originalPos] = originalItem
set StackLevel = StackLevel + 1
set MovedItem[StackLevel] = movedItem.it
set LastPosition[StackLevel] = originalPos
call OnMoveItem.fire()
set StackLevel = StackLevel - 1
endif
set u = null
return false
endmethod
private static method checkOrder takes nothing returns boolean
return GetIssuedOrderId() >= FIRST_INVENTORY_ID and GetIssuedOrderId() <= LAST_INVENTORY_ID
endmethod
private static method onInit takes nothing returns nothing
local trigger pickUp = CreateTrigger()
local trigger drop = CreateTrigger()
local trigger move = CreateTrigger()
set OnMoveItem = Event.create()
call TriggerRegisterAnyUnitEventBJ(pickUp,EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerRegisterAnyUnitEventBJ(drop,EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerRegisterAnyUnitEventBJ(move,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(pickUp,Condition(function thistype.onPickUp))
call TriggerAddCondition(drop,Condition(function thistype.onDrop))
call TriggerAddCondition(move,And(Condition(function thistype.checkOrder),Condition(function thistype.onMove)))
endmethod
endstruct
endlibrary
</u></u></u></u></i></i></i></i></i>
JASS:library UID requires AIDS, T32, Event, Itemdex globals public constant integer FIRST_INVENTORY_ID = 852002 public constant integer LAST_INVENTORY_ID = 852007 endglobals globals private Event OnMoveItem private item array MovedItem private integer array LastPosition private integer StackLevel = 0 endglobals public function RegisterOnMoveItem takes trigger trig returns EventReg return OnMoveItem.register(trig) endfunction public function UnregisterOnMoveItem takes trigger trig returns nothing call OnMoveItem.unregister(trig) endfunction private keyword items private keyword UnitStruct private struct ItemStruct integer position item it unit owner boolean isCreated private method periodic takes nothing returns nothing if GetItemTypeId(this.it)==0 or GetWidgetLife(it)<=0.0 then call this.stopPeriodic() set this.isCreated = false call this.destroy() endif endmethod static method load takes item i returns thistype local thistype this = GetItemId(i) if not this.isCreated then set this = thistype.allocate() set this.it = i set this.position = -1 set this.owner = null set this.isCreated = true call this.startPeriodic() endif return this endmethod implement Itemdex implement T32x private static method onInit takes nothing returns nothing set thistype(0).position = -1 endmethod endstruct private type items extends ItemStruct array [6] private struct UnitStruct extends array items items method periodic takes nothing returns nothing local integer i = 0 local integer maxSize = UnitInventorySize(this.unit) local item it loop exitwhen i == maxSize set it = UnitItemInSlot(this.unit,i) if it != null then set ItemStruct[it].position = i set ItemStruct[it].owner = this.unit set this.items<i> = ItemStruct[it] endif set i = i + 1 endloop endmethod private method AIDS_onCreate takes nothing returns nothing call this.startPeriodic() set this.items = items.create() endmethod private method AIDS_onDestroy takes nothing returns nothing local integer i = 0 loop exitwhen i == 6 set this.items<i>.owner = null set this.items<i>.position = -1 set i = i + 1 endloop call this.stopPeriodic() call this.items.destroy() endmethod implement T32x //! runtextmacro AIDS() endstruct function GetItemOwner takes item i returns unit return ItemStruct<i>.owner endfunction function GetItemInventoryPosition takes item i returns integer return ItemStruct<i>.position endfunction function GetMovedItem takes nothing returns item return MovedItem[StackLevel] endfunction function GetLastInventoryPosition takes nothing returns integer return LastPosition[StackLevel] endfunction function GetUnitItemInSlot takes unit u, integer slot returns item return UnitStruct<u>.items[slot].it endfunction private struct Initializer extends array private static method onPickUp takes nothing returns boolean local ItemStruct i = ItemStruct.load(GetManipulatedItem()) local integer pos = 0 set i.owner = GetTriggerUnit() loop exitwhen pos == 6 if UnitItemInSlot(i.owner,pos) == GetManipulatedItem() then set i.position = pos set pos = 5 endif set pos = pos + 1 endloop return false endmethod private static method onDrop takes nothing returns boolean local ItemStruct i = ItemStruct.load(GetManipulatedItem()) set UnitStruct[i.owner].items[i.position] = 0 set i.owner = null set i.position = -1 return false endmethod private static method onMove takes nothing returns boolean local integer orderId = GetIssuedOrderId() local unit u = GetTriggerUnit() local integer originalPos local ItemStruct movedItem local ItemStruct originalItem set orderId = orderId - FIRST_INVENTORY_ID set movedItem = ItemStruct.load(GetOrderTargetItem()) set originalItem = UnitStruct<u>.items[orderId] if movedItem != originalItem then if originalItem != 0 then set originalItem.position = movedItem.position endif set originalPos = movedItem.position set movedItem.position = orderId set UnitStruct<u>.items[orderId] = movedItem set UnitStruct<u>.items[originalPos] = originalItem set StackLevel = StackLevel + 1 set MovedItem[StackLevel] = movedItem.it set LastPosition[StackLevel] = originalPos call OnMoveItem.fire() set StackLevel = StackLevel - 1 endif set u = null return false endmethod private static method checkOrder takes nothing returns boolean return GetIssuedOrderId() >= FIRST_INVENTORY_ID and GetIssuedOrderId() <= LAST_INVENTORY_ID endmethod private static method onInit takes nothing returns nothing local trigger pickUp = CreateTrigger() local trigger drop = CreateTrigger() local trigger move = CreateTrigger() set OnMoveItem = Event.create() call TriggerRegisterAnyUnitEventBJ(pickUp,EVENT_PLAYER_UNIT_PICKUP_ITEM) call TriggerRegisterAnyUnitEventBJ(drop,EVENT_PLAYER_UNIT_DROP_ITEM) call TriggerRegisterAnyUnitEventBJ(move,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER) call TriggerAddCondition(pickUp,Condition(function thistype.onPickUp)) call TriggerAddCondition(drop,Condition(function thistype.onDrop)) call TriggerAddCondition(move,And(Condition(function thistype.checkOrder),Condition(function thistype.onMove))) endmethod endstruct endlibrary </u></u></u></u></i></i></i></i></i>
As you wish. (Freehand, didn't try it yet.)
It is not so efficient.