library NoStacks
// Prevent multiple occurences of same item
// by jondrean
// CREDITS: http://www.wc3c.net/showthread.php?t=84044
private struct S extends array
static unit shop
static unit buyer
static method onSell takes nothing returns boolean
local item it = GetSoldItem()
local item temp
local integer id = GetItemTypeId(it)
local unit u = GetBuyingUnit()
local integer i = 5
local player owner
loop
set temp = UnitItemInSlot(u, i)
if temp!=null and GetItemTypeId(temp)==id then
call SetPlayerState(Player(15), PLAYER_STATE_RESOURCE_GOLD, 50000)
call SetPlayerState(Player(15), PLAYER_STATE_RESOURCE_LUMBER, 50000)
call AddItemToStock(shop, id, 1, 1)
call IssueNeutralImmediateOrderById(Player(15), shop, id)
call RemoveItem(UnitItemInSlot(buyer, 0))
call RemoveItemFromStock(shop, id)
set owner = GetOwningPlayer(u)
call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD)+50000-GetPlayerState(Player(15), PLAYER_STATE_RESOURCE_GOLD))
call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER)+50000-GetPlayerState(Player(15), PLAYER_STATE_RESOURCE_LUMBER))
call RemoveItem(it)
set owner = null
exitwhen true
endif
exitwhen i == 0
set i = i-1
endloop
set temp = null
set it = null
set u = null
return false
endmethod
static method onPickup takes nothing returns boolean
local item it = GetManipulatedItem()
local item temp
local integer id = GetItemTypeId(it)
local unit u = GetTriggerUnit()
local boolean hasOne = false
local integer i = 5
loop
set temp = UnitItemInSlot(u, i)
if temp!=null and GetItemTypeId(temp)==id then
if hasOne then
call SetItemPosition(it, GetUnitX(u), GetUnitY(u))
exitwhen true
else
set hasOne = true
endif
endif
exitwhen i == 0
set i = i-1
endloop
set temp = null
set it = null
set u = null
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local rect r = GetWorldBounds()
set buyer = CreateUnit(Player(15), 'hpal', 0, 0, 0)
call SetUnitX(buyer, GetRectMaxX(r))
call SetUnitY(buyer, GetRectMaxY(r))
set shop = CreateUnit(Player(15), 'nshe', 0, 0, 0)
call SetUnitX(shop,GetRectMaxX(r))
call SetUnitY(shop,GetRectMaxY(r))
call UnitAddAbility(shop, 'Asid')
call UnitRemoveAbility(shop, 'Awan')
call UnitAddAbility(shop, 'Aloc')
call RemoveRect(r)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SELL_ITEM)
call TriggerAddCondition(t, Condition(function thistype.onSell))
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t, Condition(function thistype.onPickup))
set t = null
set r = null
endmethod
endstruct
endlibrary