XxShadyxX
I abused the rep system.
- Reaction score
- 81
it keeps asking for int_triggername ??
it keeps asking for int_triggername ??
local integer i = 0
local integer extendedInventorySize = ...
local unit u = ...
loop
exitwhen i == extendedInventorySize
if GetItemType(InventoryGetItemById(u,i)) == ITEM_TYPE_CHARGED then
//save item.
endif
set i = i+1
endloop
scope pertearmedrop initializer init
//=================================================
globals
private constant integer GARN = 039;Abun039;
endglobals
//=================================================
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO)==true
endfunction
//=================================================
private function Actions takes nothing returns nothing
local unit hero = GetTriggerUnit()
local player pl = GetOwningPlayer(hero)
local integer k = GetPlayerId(pl)+1
local integer i = 0
local item obj = GetManipulatedItem()
local integer objtype = GetItemTypeId(obj)
loop
exitwhen i > udg_item_weapon_integer
if objtype == udg_item_type_weapon<i> and obj == udg_item_weapon[k] then
call UnitAddAbility(hero,GARN )
set udg_item_weapon[k] = null
call UnitRemoveAbility(hero,udg_item_sp[k])
set hero = null
set pl = null
set obj = null
return
endif
set i = i + 1
endloop
set hero = null
set pl = null
set obj = null
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
endfunction
endscope
</i>
library ExtendedInventorySystem
//#######################################################################################
//#Extended Inventory System v1.5c - By Tom Jones.
//#######################################################################################
//#Requirements:
//#1) NewGen Editor with JassHelper v0.9.G.1
//#
//#Implementation:
//#1) Copy/paste this trigger from this map to your map.
//#
//#Usage:
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call ExtendUnitInventory(unit,size) returns boolean
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# This will extends a unit's inventory with the size given. Returns true if
//# succesful, false if the unit already has extended inventory. Size should be
//# divisable by six.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryDisable(unit,boolean)
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryDisabled(unit) returns boolean
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryAutomove(unit,boolean)
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# This will enable automoving of items from the main inventory to the extended
//# inventory.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryAutomoves(unit) returns boolean
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryAddItem(unit,item,integer) returns item
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Sends an item to or removes an item from the extended inventory. Integer determines
//# which page the item should be added to. Note that adding an item to a hidden page
//# will remove the given item and the item returned can't be seen by UnitHasItem(...),
//# UnitItemInSlot(...), etc.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryGetItemById(unit,integer) returns item
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Returns the first item in the inventory that meets the integer argument.
//# Note that the integer can be either a slot id ranging from 0 to the size of the
//# extended inventory or an item rawcode.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryHasItemById(unit,integer) returns boolean
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Integer argument can be both a slot id ranging from 0 to the size of the extended
//# inventory or an item rawcode.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryHasItem(unit,item) returns boolean
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryDisplayPage(unit,integer)
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Displays the page equal to the integer argument. Each page has six slots and
//# their id range from 1 to size of the extended inventory. Page ids not in this range
//# will display the main inventory, page id 1 displays the main inventory.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call InventoryGetPage(unit) returns integer
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Returns the id of the currently displayed page.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call SetMaxStackById(integer id,integer value)
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Requires Extended Inventory Item Stack module.
//#
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call SetMaxStackById(integer,integer)
//# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Requires Extended Inventory Item Stack module.
//#
//#Notes:
//#1) This system wont require you to predefine any items. It does however rely on
//# bug, and should thus be used with care.
//#2) The bug: UnitAddItemToSlotById(...) is able to take a negative value as argument.
//# The interesting part is that items added this way wont appear on the hero, however
//# their effects will. Also note that not all negative values can be used. Values -1
//# to -12 will cause a memeory reference error on exit. Values below -21 will cause a
//# critical error.
//#3) Please report any bugs or errors by PM'ing me on <a href="http://www.TheHelper.net" target="_blank" class="link link--external" rel="nofollow ugc noopener">www.TheHelper.net</a> or posting them
//# in this thread:
//#
//#Changelog:
//# v1.00a - Initial draft.
//# v1.2b - Release.
//# v1.5a - Changes to the source code.
//# Added Extended Inventory Stack v1.1
//# Added Extended Inventory IconTag v1.1
//# Changed Example B.
//# v1.5c - Changed InventoryAddItem(unit,item,boolean) to InventoryAddItem(unit,item,integer)
//# Changes to the source code to accomodate the above change.
//# Added Extended Inventory Item Stack v.1.2
//#
//#######################################################################################
//#######################################################################################
//#Extended Inventory System API.
//#######################################################################################
private keyword inventory
function UnitExtendInventory takes unit u, integer size returns boolean
if u:inventory > 0 then
return false
endif
call inventory.extend(u,size)
return true
endfunction
function InventoryDisable takes unit u, boolean flag returns nothing
call u:inventory.disable(flag)
endfunction
function InventoryDisabled takes unit u returns boolean
return u:inventory.disabled
endfunction
function InventoryAutomove takes unit u, boolean flag returns nothing
set u:inventory.automove = flag
endfunction
function InventoryAutomoves takes unit u returns boolean
return u:inventory.automove
endfunction
function InventoryAddItem takes unit u, item whichitem, integer page returns item
return u:inventory.additem(whichitem,page)
endfunction
function InventoryGetItemById takes unit u, integer id returns item
return u:inventory.getitem(id)
endfunction
function InventoryHasItemById takes unit u, integer id returns boolean
local inventory this = u:inventory
local integer i = 0
loop
exitwhen this.getitem(id) != null or i == this.size
set i = i+1
endloop
return i < this.size
endfunction
function InventoryHasItem takes unit u, item whichitem returns boolean
local inventory this = u:inventory
local integer i = 0
loop
exitwhen this.getitem(i) == whichitem or i == this.size
set i = i+1
endloop
return i < this.size
endfunction
function InventoryDisplayPage takes unit u, integer page returns nothing
call u:inventory.turnpage(page)
endfunction
function InventoryGetPage takes unit u returns integer
return u:inventory.page
endfunction
function SetMaxStackById takes integer id, integer max returns nothing
call inventory.setstack(id,max)
endfunction
function GetMaxStackById takes integer id returns integer
return inventory.getstack(id)
endfunction
//#######################################################################################
//#Hashing.
//#######################################################################################
globals
private constant integer DEDUCT = 0x100000
private constant integer HASH = 8192
endglobals
//#######################################################################################
//#Slot type.
//#######################################################################################
public struct slot
static slot last = 0
slot next
inventory current
item thisitem
integer itemid
integer charges
integer page
integer id
boolean free
method operator item= takes item whichitem returns nothing
if whichitem != null and .last == this then
set .last = 0
set .thisitem = whichitem
elseif whichitem == null and .last != this then
set .thisitem = null
set .itemid = 0
set .charges = 0
set .free = true
elseif whichitem != null then
set .itemid = GetItemTypeId(whichitem)
set .charges = GetItemCharges(whichitem)
set .last = this
call RemoveItem(whichitem)
if .current.page == .page then
call UnitAddItemToSlotById(.current.u,.itemid,.id-(6*(.page-1)))
else
call UnitAddItemToSlotById(.current.u,.itemid,-13)
endif
call SetItemCharges(.thisitem,.charges)
endif
set .free = .item == null
endmethod
method operator item takes nothing returns item
return .thisitem
endmethod
method update takes nothing returns nothing
set .thisitem = UnitItemInSlot(.current.u,.id-(6*(.page-1)))
set .itemid = GetItemTypeId(.thisitem)
set .free = .thisitem == null
endmethod
endstruct
//#######################################################################################
//#Inventory type.
//######################################################################################
private struct modules
method itemstack takes item whichitem returns integer
return 0
endmethod
static method setstack takes integer id, integer max returns nothing
endmethod
static method getstack takes integer id returns integer
return 0
endmethod
method icontag takes item whichitem, integer id returns nothing
endmethod
endstruct
private struct inventory
private static integer index
private static integer array value
private trigger trig
integer pages
slot first
slot last
unit u
player p
integer page
boolean automove
boolean disabled
integer size
delegate modules addons
implement optional ItemStack
implement optional IconTag
static method operator []= takes unit u, inventory value returns nothing
set .index = GetHandleId(u)-DEDUCT
set .value[.index-(.index/HASH)*HASH] = value
endmethod
static method operator [] takes unit u returns inventory
set .index = GetHandleId(u)-DEDUCT
return .value[.index-(.index/HASH)*HASH]
endmethod
static method Delegator takes nothing returns boolean
local inventory this = GetTriggerUnit():inventory
if .disabled then
elseif GetTriggerEventId() == EVENT_UNIT_PICKUP_ITEM then
call inventory.onAquire.execute()
elseif GetTriggerEventId() == EVENT_UNIT_DROP_ITEM then
call inventory.onDrop.execute()
endif
return false
endmethod
private method updatepage takes integer page returns nothing
local slot s = .first
loop
exitwhen s == 0
if s.id >= 6*(page-1) and s.id < 6*page then
call s.update()
endif
set s = s.next
endloop
endmethod
method additem takes item whichitem, integer page returns item
local slot s
local integer pages = .pages
local integer id
if whichitem == null or .disabled then
if .disabled then
debug call BJDebugMsg("Extended Inventory Error: Disabled.")
else
debug call BJDebugMsg("Extended Inventory Error: Passing null as argument.")
endif
return null
endif
call .updatepage(.page)
set s = .itemstack(whichitem)
if s > 0 then
return s.item
else
set s = .first
endif
loop
if (s.id >= 6*(page-1) and s.id < 6*page) then
if s.free or s.item == whichitem then
exitwhen true
endif
endif
if s.id+1 >= 6*page then
set page = page+1
set pages = pages-1
endif
if page > .pages then
set page = pages
set s = .first
else
set s = s.next
endif
if s == 0 or pages == 0 then
return null
endif
endloop
if s.page != .page then
call .icontag(whichitem,1)
endif
set s.item = whichitem
return s.item
endmethod
method getitem takes integer id returns item
local slot s = .first
if id < .size then
loop
exitwhen s.id == id or s == 0
set s = s.next
endloop
elseif id >= 039;0000039; then
loop
exitwhen s.itemid == id
set s = s.next
endloop
else
return null
endif
return s.item
endmethod
method turnpage takes integer page returns nothing
local integer oldpage = .page
local slot a = .first
local slot b = .first
if page == oldpage then
return
elseif page > .pages or page == 0 then
set page = 1
endif
set .page = page
loop
exitwhen a.page == oldpage or a == 0
set a = a.next
endloop
loop
exitwhen b.page == page or b == 0
set b = b.next
endloop
call .updatepage(oldpage)
call .icontag(null,0)
loop
exitwhen a.id == oldpage*6 or b.id == page*6
if a.item != null then
set a.item = a.item
endif
if b.item != null then
set b.item = b.item
endif
set a = a.next
set b = b.next
endloop
endmethod
method disable takes boolean flag returns nothing
local slot s
local real x
local real y
if flag then
set s = .first
set x = GetUnitX(.u)
set y = GetUnitY(.u)
loop
exitwhen s == 0
if s.page > 1 then
call CreateItem(s.itemid,x,y)
call RemoveItem(s.item)
endif
set s = s.next
endloop
call DisableTrigger(.trig)
else
call EnableTrigger(.trig)
set .page = 1
call .updatepage(1)
endif
set .disabled = flag
endmethod
static method extend takes unit u, integer size returns nothing
local inventory this = inventory.allocate()
local integer i = 0
local slot s
set .u = u
set .u:inventory = this
set .p = GetOwningPlayer(.u)
set .size = size+6
set .pages = .size/6
set .page = 1
loop
exitwhen i == .size
set s = slot.create()
set s.current = this
if .last == 0 then
set .first = s
else
set .last.next = s
endif
set s.page = 1+(i/6)
set s.id = i
set s.free = s.item == null
set .last = s
set i = i+1
endloop
set .trig = CreateTrigger()
call TriggerRegisterUnitEvent(.trig,.u,EVENT_UNIT_PICKUP_ITEM)
call TriggerRegisterUnitEvent(.trig,.u,EVENT_UNIT_DROP_ITEM)
call TriggerAddCondition(.trig,Condition(function inventory.Delegator))
set .disabled = false
set .automove = false
set .addons = modules.create()
call .updatepage(1)
endmethod
static method onAquire takes nothing returns nothing
local inventory this = GetTriggerUnit():inventory
local item whichitem = GetManipulatedItem()
if slot.last > 0 then
set slot.last.item = whichitem
else
if .automove then
call .additem(whichitem,.page+1)
else
call .additem(whichitem,.page)
endif
endif
set whichitem = null
endmethod
static method onDrop takes nothing returns nothing
local inventory this = GetTriggerUnit():inventory
local item whichitem = GetManipulatedItem()
local slot s = .first
loop
exitwhen s.item == whichitem or s == 0
set s = s.next
endloop
set s.item = null
set whichitem = null
endmethod
endstruct
endlibrary
http://www.thehelper.net/forums/showpost.php?p=1110263&postcount=33Can you fix it to works in 1.24b