//First of all, we need to declare the SimError function, which will be used to display error messages
function SimError takes player ForPlayer, string msg returns nothing
if udg_SimError==null then
set udg_SimError=CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
endif
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call DisplayTimedTextToPlayer(ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r")
call StartSound(udg_SimError)
endif
endfunction
////////////////////////////
////Hoernchen's
//////Equipment
////////System
////////////////////////////
//////////////////
///////Variables
//////////////////
//
//udg_ES_Lib - hashtable
//#Here all the information about items, their classes, etc is being stored. This information
//#usually does not need to be changed during the game, but only at the start.
//#The parent keys are: 0 for all items, 1 for all slots, 2 for all twohanders, 3 for shop dummies, 4 for prices, 5 for stances, 6 for stacks, 7 for offhand items
//#The child keys store the classes of all items
//
//udg_ES_Hash - hashtable
//#This table is used to store temporary information that will frequently change during the game
//#The parent key is used to store a unit or item, the child key is used to store
//#information. Units: 0 = lock-status, 1 = item being picked up; Items: 0 = slot equipped into, 1 = linked used slot
//////////////////
///////Setup Functions
//////////////////
//Registers an itemtype with the slotid given to be handled as a slot with the class given
function ES_Register_Slot takes integer slotid, string class returns nothing
local integer i = 0
local integer start = 0
local integer finds = 0
set class = class + " "
loop //the loop is necessary to split up all the classes properly
exitwhen i == StringLength(class)
if SubString(class, i, i+1) == " " then
call SaveStr(udg_ES_Lib, 0, slotid+StringHash("class"+I2S(finds)), SubString(class, start, i))
set finds = finds + 1
set start = i+1
endif
set i = i + 1
endloop
call SaveBoolean(udg_ES_Lib, 1, slotid, true)
endfunction
//Same as ES_Register_Slot, but will only accept one class. Use this to save memory if the slot only has one class
function ES_Register_Slot_Small takes integer slotid, string class returns nothing
call SaveStr(udg_ES_Lib, 0, slotid+StringHash("class0"), class)
call SaveBoolean(udg_ES_Lib, 1, slotid, true)
endfunction
//Registers an itemtype with the itemid given to have a certain class and thus be equippable
function ES_Register_Item takes integer itemid, string class returns boolean
return SaveStr(udg_ES_Lib, 0, itemid, class)
endfunction
//You will need to use this function to make items buyable in a shop
function ES_Register_Shop takes integer dummyid, integer itemid, integer price returns nothing
call SaveInteger(udg_ES_Lib, 3, dummyid, itemid)
call SaveInteger(udg_ES_Lib, 4, dummyid, price)
endfunction
//Registers an itemtype with the itemid given to be twohanded and hence also use the offhand slot
//Note: Stacking items cannot be registered as being twohanded!
function ES_Register_Twohand takes integer itemid returns nothing
if not(HaveSavedInteger(udg_ES_Lib, 6, itemid)) then
call SaveBoolean(udg_ES_Lib, 2, itemid, true)
endif
endfunction
//Registers a SLOT to be an 'offhand' item, these are needed to equip twohanded items
//An offhand item will be occupied by a 'used' slot if the hero equips a twohanded item
function ES_Register_Offhand takes integer itemid returns nothing
if HaveSavedBoolean(udg_ES_Lib, 1, itemid) then
call SaveBoolean(udg_ES_Lib, 7, itemid, true)
endif
endfunction
//Register an item here to make it stackable up to max times. Should only be used for consumables.
//Note: Twohanded items may not stack!
function ES_Register_Stack takes integer itemid, integer max returns nothing
if HaveSavedBoolean(udg_ES_Lib, 2, itemid) == false then
call SaveInteger(udg_ES_Lib, 6, itemid, max)
endif
endfunction
//Item-classes registered here will have the unit assume the given stance when equipping them
function ES_Register_Stance takes string class, string stance returns nothing
call SaveStr(udg_ES_Lib, 5, StringHash(class), stance)
endfunction
//////////////////
///////Core Functions
//////////////////
//The lock function must be used at some points in the code to prevent infinite loops with the system
function ES_Lock takes unit u returns nothing
if LoadBoolean(udg_ES_Hash, GetHandleId(u), 0) then
call SaveBoolean(udg_ES_Hash, GetHandleId(u), 0, false)
else
call SaveBoolean(udg_ES_Hash, GetHandleId(u), 0, true)
endif
endfunction
//////////////////
//////Check Functions
//////////////////
//Tests an itemid and returns true if tested ID is a slot ID, false otherwise
function ES_IsSlot takes integer itemid returns boolean
return LoadBoolean(udg_ES_Lib, 1, itemid) //returns true if there is a record of this item in the slot-library
endfunction
function ES_IsTwohand takes integer itemid returns boolean
return LoadBoolean(udg_ES_Lib, 2, itemid) //returns true if there is a record of this item in the twohander-library
endfunction
function ES_IsOffhand takes integer itemid returns boolean
return LoadBoolean(udg_ES_Lib, 7, itemid) //returns true if the slot is an offhand slot
endfunction
//This will test if a given slot-type can equip a given itemtype
function ES_SlotMatch takes integer slotid, integer itemid returns boolean
local string class = LoadStr(udg_ES_Lib, 0, itemid) //Get the class of the tested item
local string match
local integer i = 0
loop
set match = LoadStr(udg_ES_Lib, 0, slotid+StringHash("class"+I2S(i))) //retrieve all registered classes for the matched slot
exitwhen match == null //exit if we tried all registered classes for the matched slot
if match == class then //check if the slot class that we are currently matching matches the class of the tested item
return true //The matched slot can equip the tested item
endif
set i = i + 1
endloop
return false //The matched slot cannot equip the tested item
endfunction
//////////////////
//////Operation Functions
//////////////////
//This function will return the slot that a given item is occupying or null if the item isn't occupying any slots
function ES_GetItemSlot takes item it returns item
return LoadItemHandle(udg_ES_Hash, GetHandleId(it), 0) //Returns the slot under the given item if it exists
endfunction
//Same as ES_FindSlot, but returns an occupied slot if possible, then a free slot
function ES_FindStackSlot takes unit u, integer itemid, integer max returns item
local integer i = 5
local item check
local item result = null
loop
exitwhen i < 0 //this loop will go through all 6 slots on the given unit u
set check = UnitItemInSlot(u, i)
if ES_IsSlot(GetItemTypeId(check)) == false then //check if the item we are currently checking is a slot or not
set check = ES_GetItemSlot(check) //if the item is not a slot, we will check the slot it is lying on instead
endif
if ES_SlotMatch(GetItemTypeId(check), itemid) then //it will check whether the current slot in the hero's inventory can equip the given itemid
if (GetItemCharges(UnitItemInSlot(u, i)) < max or result == null) and GetItemTypeId(UnitItemInSlot(u, i)) == itemid then //check if the item we are checking can be stacked further
set result = null
return UnitItemInSlot(u, i) //if we can stack more stuff onto this slot, then return it!
endif
if ES_IsSlot(GetItemTypeId(UnitItemInSlot(u, i))) then //checks to see if the result we got is a slot or an item lying on a slot
set result = check //if it's a slot we might wanna remember it, in case nothing stacks
endif
endif
set check = null
set i = i - 1
endloop
return result //returns a matching occupied slot, or null if no slots were matching
endfunction
//Finds the next best slot that can equip an item of given itemid, returns an item, if said item is occupying the slot
function ES_FindSlot takes unit u, integer itemid returns item
local integer i = 0
local item check
local item result = null
loop
exitwhen i == 6 //this loop will go through all 6 slots on the given unit u
set check = UnitItemInSlot(u, i)
if ES_IsSlot(GetItemTypeId(check)) == false then //check if the item we are currently checking is a slot or not
set check = ES_GetItemSlot(check) //if the item is not a slot, we will check the slot it is lying on instead
endif
if ES_SlotMatch(GetItemTypeId(check), itemid) then //it will check whether the current slot in the hero's inventory can equip the given itemid
if ES_IsSlot(GetItemTypeId(UnitItemInSlot(u, i))) then //checks to see if the result we got is a slot or an item lying on a slot
set result = null
return check //if it's a slot we can return it straight away
endif
if result == null then //if we already have an occupied slot then we want to keep it so that the item is added top->bottom
set result = UnitItemInSlot(u, i) //if it's an item occupying a slot, we wanna keep it in case no slots are free
endif
endif
set i = i + 1
set check = null
endloop
return result //returns a matching occupied slot, or null if no slots were matching
endfunction
//This is a special function used to add items that may stack (like potions) to a unit's inventory
function ES_AddStackingItem takes unit u, item it returns integer
local item slot = null
local integer i = 5
local integer max = LoadInteger(udg_ES_Lib, 6, GetItemTypeId(it))
set slot = ES_FindStackSlot(u, GetItemTypeId(it), max) //find a slot that can equip this item
if slot == null then
call SimError(GetOwningPlayer(u), "You cannot carry this item.")
return 2 //the unit cannot equip the item, return error code 2
endif
//if a free slot was returned, equip everything into this
if ES_IsSlot(GetItemTypeId(slot)) then
call SaveItemHandle(udg_ES_Hash, GetHandleId(it), 0, slot) //this will register what slot-item the item the hero just equipped is equipped onto
call ES_Lock(u) //lock the equipment system for this unit, to prevent the code from entering endless loop
call UnitRemoveItem(u, slot) //drop the matching slot from the unit's inventory
call SetItemVisible(slot, false) //make the dropped slot invisible so no one knows it was dropped
call SetItemInvulnerable(slot, true) //make the slot invulnerable to prevent it from accidently being destroyed
call UnitAddItem(u, it) //add the desired item, now that all checks were performed
call ES_Lock(u) //unlock the hero now that the operation is over (calling ES_Lock a second time will reverse the effect)
set slot = null
return 0 //success
endif
if GetItemCharges(slot) >= max then
return 1 //the unit can equip the item, but doesnt have room left to stack it
endif
//add the charges of the item to the next best item
if GetItemCharges(it) + GetItemCharges(slot) > max then
call SetItemCharges(it, GetItemCharges(it) - (max-GetItemCharges(slot))) //remove the used up charges from the aquired item
call SetItemCharges(slot, max) //max out the existing item's charges
call ES_AddStackingItem(u, it) //redo the loop with the new charge amount
else
//in this case the entire aquired item is absorbed into an existing item
call SetItemCharges(slot, (GetItemCharges(it) + GetItemCharges(slot))) //add the aquired items charges to the old items
call RemoveItem(it)
endif
set slot = null
return 0 //normal return code, means everything went fine
endfunction
//This trigger has to be run whenever you want to add a new item to a unit's inventory using EquiSys
function ES_AddItem takes unit u, item it returns integer
local item slot = null
local item doubleslot = null
local item temp = null
local integer i = 5
if HaveSavedInteger(udg_ES_Lib, 6, GetItemTypeId(it)) then
return ES_AddStackingItem(u, it)
endif
set slot = ES_FindSlot(u, GetItemTypeId(it)) //let's find the next best slot that can equip this item on the hero; if no slots are free, this will return the next best occupied slot
if slot == null then //check if the unit can equip the item at all
call SimError(GetOwningPlayer(u), "You cannot carry this item.")
return 2 //if not, return error code 2
endif
if ES_IsSlot(GetItemTypeId(slot)) == false then //check if it's an occupied slot
call SimError(GetOwningPlayer(u), "No space for this item.")
return 1 //if it's occupied, this will return error code 1
endif
//if it passed all the tests till here, we can assume that the unit can equip the item straight away
//but first of all, let's check whether the thing is two-handed
if ES_IsTwohand(GetItemTypeId(it)) then //if the item is twohanded we gotta perform some more checks
//check whether the unit has a free slot, we assume it can twohand-wield this weapon since the weaponclass and slotclass matched
loop //this loop will check all items on the hero and see if one of them is the offhand item
exitwhen i < 0
set temp = UnitItemInSlot(u, i)
if ES_IsOffhand(GetItemTypeId(temp)) then
set doubleslot = temp //if an offhand itemslot is found, remember it
endif
if ES_IsOffhand(GetItemTypeId(LoadItemHandle(udg_ES_Hash, GetHandleId(temp), 0))) and doubleslot == null then
set doubleslot = temp //if an item sitting on an offhand item is found, remember it
endif
set temp = null
set i = i - 1
endloop
if doubleslot == null then
call SimError(GetOwningPlayer(u), "You cannot carry this item.") //returns error code 2 if an offhand slot was found, but its taken
return 2
endif
if not(ES_IsSlot(GetItemTypeId(doubleslot))) then
call SimError(GetOwningPlayer(u), "No space for this item.") //if no offhand slot was found we gotta return error code 1
return 1
endif
//given that we have found a matching 2nd slot, we are gonna replace the offhand slot with a "used" slot
call ES_Lock(u)
call UnitRemoveItem(u, doubleslot)
call SetItemVisible(doubleslot, false)
call SetItemInvulnerable(doubleslot, true)
set temp = CreateItem(udg_ES_Used, 0, 0)
call UnitAddItem(u, temp)
call SaveItemHandle(udg_ES_Hash, GetHandleId(it), 1, temp)
call SaveItemHandle(udg_ES_Hash, GetHandleId(temp), 0, doubleslot)
set temp = null
set doubleslot = null
call ES_Lock(u)
endif
call SaveItemHandle(udg_ES_Hash, GetHandleId(it), 0, slot) //this will register what slot-item the item the hero just equipped is equipped onto
call ES_Lock(u) //lock the equipment system for this unit, to prevent the code from entering endless loop
call UnitRemoveItem(u, slot) //drop the matching slot from the unit's inventory
call SetItemVisible(slot, false) //make the dropped slot invisible so no one knows it was dropped
call SetItemInvulnerable(slot, true) //make the slot invulnerable to prevent it from accidently being destroyed
call UnitAddItem(u, it) //add the desired item, now that all checks were performed
call ES_Lock(u) //unlock the hero now that the operation is over (calling ES_Lock a second time will reverse the effect)
set slot = null
//check if the item's class requires a stance, and if yes apply it
set i = StringHash(LoadStr(udg_ES_Lib, 0, GetItemTypeId(it)))
if HaveSavedString(udg_ES_Lib, 5, i) then
call AddUnitAnimationProperties(u, LoadStr(udg_ES_Lib, 5, i), true) //apply the stance to the unit
endif
return 0 //An error code of 0 will be returned, meaning the operation was successful!
endfunction
Name | Type | is_array | initial_value |
ES_Hash | hashtable | No | |
ES_Lib | hashtable | No | |
ES_Used | itemcode | No | I00C |
SimError | sound | No |
function Trig_Init_Actions takes nothing returns nothing
//Setup the Hashtables
set udg_ES_Lib = InitHashtable()
set udg_ES_Hash = InitHashtable()
//Setup the slots
call ES_Register_Slot('I000', "sword bigsword")
call ES_Register_Slot('I001', "shield")
call ES_Register_Offhand('I001')
call ES_Register_Slot_Small('I002', "armor")
call ES_Register_Slot_Small('I004', "boots")
call ES_Register_Slot_Small('I003', "jewel")
call ES_Register_Stance("bigsword", "Channel")
call ES_Register_Stance("sword", "Alternate")
call ES_Register_Item('I005', "sword")
call ES_Register_Item('I00A', "armor")
call ES_Register_Item('I006', "jewel")
call ES_Register_Item('I008', "jewel")
call ES_Register_Shop('I00B', 'I006', 200)
call ES_Register_Item('I009', "boots")
call ES_Register_Item('I007', "shield")
call ES_Register_Item('I00D', "bigsword")
call ES_Register_Twohand('I00D')
call ES_Register_Item('I00F', "jewel")
call ES_Register_Shop('I00E', 'I00F', 5)
call ES_Register_Stack('I00F', 5)
endfunction
//===========================================================================
function InitTrig_ESInit takes nothing returns nothing
set gg_trg_ESInit = CreateTrigger()
call TriggerAddAction(gg_trg_ESInit, function Trig_Init_Actions)
endfunction
function ES_PickUpFull_Cond takes nothing returns boolean
if LoadBoolean(udg_ES_Hash, GetHandleId(GetOrderedUnit()), 0) then
return false
endif
if GetOrderTargetItem() == null or GetIssuedOrderId() != 851971 then
return false //check whether the order is even to pick up an item
endif
return LoadItemHandle(udg_ES_Hash, GetHandleId(GetOrderedUnit()), 1) != GetOrderTargetItem() //check whether the item in question isn't already being picked up
endfunction
function ES_PickUp takes nothing returns nothing
local unit u = GetOrderedUnit()
local item it = GetOrderTargetItem()
local location u_loc
local location it_loc
local timer t = GetExpiredTimer() //this will be null if this is the first loop
local location go_loc
//if the function called itself, then we might want to use the information it passed to itself
if t != null then
set u = LoadUnitHandle(udg_ES_Hash, GetHandleId(t), 0) //get the previously stored unit
set it = LoadItemHandle(udg_ES_Hash, GetHandleId(t), 1) //get the item stored in the timer
//this will check if the order has been aborted, by checking if the item stored in the timer is equal to the item the unit is picking up
if it != LoadItemHandle(udg_ES_Hash, GetHandleId(u), 1) then
//if the order has been cancelled, exit code and cleanup
set u = null
set it = null
call FlushChildHashtable(udg_ES_Hash, GetHandleId(t))
call DestroyTimer(t)
set t = null
return
endif
endif
set u_loc = GetUnitLoc(u)
set it_loc = GetItemLoc(it)
if DistanceBetweenPoints(u_loc, it_loc) > 150 then
call DisableTrigger(gg_trg_ESPickUpCancel) //shortly disable the trigger to prevent clashes
set go_loc = PolarProjectionBJ(it_loc, 125.00, AngleBetweenPoints(it_loc, u_loc))
call IssuePointOrderByIdLoc(u, 851971, go_loc) //order the unit to go near the item
call EnableTrigger(gg_trg_ESPickUpCancel) //renable trigger
//cleanup
call RemoveLocation(go_loc)
set go_loc = null
set t = CreateTimer() //Create a timer
//Save relevant information into the timer
call SaveUnitHandle(udg_ES_Hash, GetHandleId(t), 0, u) //save the unit in the timer
call SaveItemHandle(udg_ES_Hash, GetHandleId(u), 1, it) //save item being picked up on the unit, not timer
call SaveItemHandle(udg_ES_Hash, GetHandleId(t), 1, it) //save item to timer too
//Run the timer in order to check up on the item every 0.2 seconds
call TimerStart(t, 0.2, false, function ES_PickUp)
set t = null
elseif IsItemOwned(it) == false and IsItemVisible(it) == true then
call ES_AddItem(u, it) //if the unit can physically pick up the item, add the item to the unit's inventory
endif
//cleanup local variables
call RemoveLocation(u_loc)
call RemoveLocation(it_loc)
set u_loc = null
set it_loc = null
set u = null
set it = null
endfunction
//===========================================================================
function InitTrig_ESPickUp takes nothing returns nothing
set gg_trg_ESPickUp = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ESPickUp, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(gg_trg_ESPickUp, Condition(function ES_PickUpFull_Cond))
call TriggerAddAction(gg_trg_ESPickUp, function ES_PickUp)
endfunction
function Trig_ESPickUpCancel_Actions takes nothing returns nothing
if LoadItemHandle(udg_ES_Hash, GetHandleId(GetOrderedUnit()), 1) == GetOrderTargetItem() then
return
endif
call RemoveSavedHandle(udg_ES_Hash, GetHandleId(GetOrderedUnit()), 1)
endfunction
//===========================================================================
function InitTrig_ESPickUpCancel takes nothing returns nothing
set gg_trg_ESPickUpCancel = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ESPickUpCancel, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterAnyUnitEventBJ(gg_trg_ESPickUpCancel, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterAnyUnitEventBJ(gg_trg_ESPickUpCancel, EVENT_PLAYER_UNIT_ISSUED_ORDER)
call TriggerAddAction(gg_trg_ESPickUpCancel, function Trig_ESPickUpCancel_Actions)
endfunction
function Lose_Items_Cond takes nothing returns boolean
if LoadBoolean(udg_ES_Hash, GetHandleId(GetOrderedUnit()), 0) then
return false
endif
if IsItemIdPowerup(GetItemTypeId(GetManipulatedItem())) then
return false
endif
return not(ES_IsSlot(GetItemTypeId(GetManipulatedItem())))
endfunction
function Lose_Items_Child takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(udg_ES_Hash, GetHandleId(t), 0)
local item it = LoadItemHandle(udg_ES_Hash, GetHandleId(t), 1)
local item slot = LoadItemHandle(udg_ES_Hash, GetHandleId(t), 2)
local item temp = LoadItemHandle(udg_ES_Hash, GetHandleId(t), 3)
local integer i
//add the slot item back to the unit
call SetItemVisible(slot,true)
call SetItemInvulnerable(slot,false)
call UnitAddItem(u,slot)
call SetItemDroppable(slot, false)
call SaveItemHandle(udg_ES_Hash, GetHandleId(it), 0, null)
call SaveItemHandle(udg_ES_Hash, GetHandleId(it), 1, null)
//If a 'used slot' exists, remove it and bring back the slot it was on
if temp != null then
call RemoveItem(temp)
call UnitAddItem(u, LoadItemHandle(udg_ES_Hash, GetHandleId(temp), 0))
call SaveItemHandle(udg_ES_Hash, GetHandleId(temp), 0, null)
endif
//check if the item's class had a stance, and if yes remove it
set i = StringHash(LoadStr(udg_ES_Lib, 0, GetItemTypeId(it))) //string hash of the item's class
if HaveSavedString(udg_ES_Lib, 5, i) then
call AddUnitAnimationProperties(u, LoadStr(udg_ES_Lib, 5, i), false) //remove the stance from the unit
endif
call DestroyTimer(t)
call FlushChildHashtable(udg_ES_Hash, GetHandleId(t))
set it = null
set u = null
set slot = null
set temp = null
set t = null
endfunction
function Lose_Items takes nothing returns nothing
local timer t = CreateTimer()
local unit u = GetManipulatingUnit()
local item it = GetManipulatedItem()
//Check if the item may have been lost due to sale
if GetSoldItem() != null then
set it = GetSoldItem() //if yes, then set the item to the sold item instead
endif
call SaveUnitHandle(udg_ES_Hash, GetHandleId(t), 0, u)
call SaveItemHandle(udg_ES_Hash, GetHandleId(t), 1, it)
call SaveItemHandle(udg_ES_Hash, GetHandleId(t), 2, LoadItemHandle(udg_ES_Hash, GetHandleId(it), 0)) //this is the item's slot item
call SaveItemHandle(udg_ES_Hash, GetHandleId(t), 3, LoadItemHandle(udg_ES_Hash, GetHandleId(it), 1))
//The timer is used to delay the actions by a fraction of a second to prevent bugs
call TimerStart(t, 0.01, false, function Lose_Items_Child)
set it = null
set u = null
set t = null
endfunction
//===========================================================================
function InitTrig_ESLoseItem takes nothing returns nothing
set gg_trg_ESLoseItem = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ESLoseItem, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddCondition(gg_trg_ESLoseItem, Condition(function Lose_Items_Cond))
call TriggerAddAction(gg_trg_ESLoseItem, function Lose_Items)
endfunction
function Trig_ESBuy_Conditions takes nothing returns boolean
return IsItemIdPowerup(GetItemTypeId(GetManipulatedItem()))
endfunction
function Trig_ESBuy_Actions takes nothing returns nothing
local unit u = GetManipulatingUnit()
local item dummy = GetManipulatedItem()
local item it
local integer id = LoadInteger(udg_ES_Lib, 3, GetItemTypeId(dummy))
if id == 0 then
set dummy = null
return
endif
set it = CreateItem(id, GetUnitX(u), GetUnitY(u))
if ES_AddItem(u, it) != 0 then //adds the item and checks then if the item was successfully added
call RemoveItem(it)
call AdjustPlayerStateBJ(LoadInteger(udg_ES_Lib, 4, GetItemTypeId(dummy)), GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) //if not, then refunds the cost
endif
call RemoveItem(dummy)
set u = null
set it = null
endfunction
//===========================================================================
function InitTrig_ESBuy takes nothing returns nothing
set gg_trg_ESBuy = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ESBuy, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_ESBuy, Condition( function Trig_ESBuy_Conditions ) )
call TriggerAddAction( gg_trg_ESBuy, function Trig_ESBuy_Actions )
endfunction