- Joined
- Nov 30, 2007
- Messages
- 1,202
This line is fired from a condition after an ability has been casted. But I never reach beyond 2 and printing player name.
EDIT:
The reason was that GetUnitsSelectedAll() wasn't working as intended from a condition scope, if i registered it from an action it worked...
Another strange behaviour im having is that if you shift-click an item to pick up multiple times it will execute multiple pickup events and if i drop and hide the item, the unit will proceed towards the item, pick it up and reveal it...
GetUnitsSelectedAll
is terminating the execution, and I'm unsure as to why.
JASS:
method openMenu takes SpellMenu openedMenu, code callback returns nothing
call BJDebugMsg("player openMenu")
call ShowUnit(.u, true)
// If another menu is open we close it and notify changes
if IsUnitSelected(.u, .p) then
call BJDebugMsg("1")
call .notifyCloseMenu(.currentOpenMenu)
call BJDebugMsg("1.1")
else
call BJDebugMsg("2")
// No previous menu selected, save selection group
call BJDebugMsg(GetPlayerName(.p))
[B][U] set .selectedUnits = GetUnitsSelectedAll(.p)[/U][/B]
call BJDebugMsg("2.1")
endif
call BJDebugMsg("select")
if GetLocalPlayer() == .p then
call ClearSelection()
call SelectUnit(.u, true)
endif
call BJDebugMsg("reselected")
set .currentOpenMenu = openedMenu
set .prevSelected = true
call TimerStart(.timerRefresh, REFRESH_RATE, true, callback)
set .currentWindow = 0
call .notifyOpenMenu(openedMenu)
endmethod
EDIT:
The reason was that GetUnitsSelectedAll() wasn't working as intended from a condition scope, if i registered it from an action it worked...
Another strange behaviour im having is that if you shift-click an item to pick up multiple times it will execute multiple pickup events and if i drop and hide the item, the unit will proceed towards the item, pick it up and reveal it...
JASS:
scope ItemMenu initializer Init
globals
private BagMenu bagMenu
private trigger trgPickup = CreateTrigger()
private unit bagOwner
private constant integer BAG_ABILITY = 'A00Q'
private constant integer BAG_LIMIT = 18
private integer counter = 0
endglobals
private function OnMoveToInventory takes nothing returns nothing
local unit owner = GetTriggerBagOwner()
local item it = GetTriggerBagItem()
call DisableTrigger(trgPickup)
call BJDebugMsg("Item (" + GetItemName(it) + ") was moved to inventory by " + GetUnitName(owner) + ".")
call UnitAddItem(owner, it)
call EnableTrigger(trgPickup)
endfunction
private function OnItemDrop takes nothing returns nothing
call BJDebugMsg("Item (" + GetItemName(GetTriggerBagItem()) + ") was dropped by " + GetUnitName(GetTriggerBagOwner()) + ".")
endfunction
private function Open takes nothing returns nothing
call bagMenu.open()
endfunction
private function OnSpell takes nothing returns boolean
local timer t
if GetSpellAbilityId() == BAG_ABILITY then
return true
endif
return false
endfunction
private function OnPickup takes nothing returns nothing
local item it = GetManipulatedItem()
if GetTriggerUnit() != bagOwner then
return
endif
call IssueImmediateOrderBJ(bagOwner, "stop" ) // Attempt to prevent ghost adding items
call SetItemPosition(it, GetUnitX(bagOwner), GetUnitY(bagOwner))
if not bagMenu.addItem(it) then
// Failed to add item - likely due to size limit reached
else
// Item added successfully
set counter = counter + 1
call BJDebugMsg(I2S(counter) + " == " + I2S(bagMenu.count()))
endif
set it = null
endfunction
private function Init takes nothing returns nothing
local trigger trgSpell = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trgPickup, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerRegisterAnyUnitEventBJ(trgSpell, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition(trgSpell, Condition(function OnSpell))
call TriggerAddAction(trgSpell, function Open)
set bagOwner = gg_unit_Hblm_0001
call UnitAddAbility(bagOwner, BAG_ABILITY)
set bagMenu = BagMenu.create(bagOwner, BAG_LIMIT)
call TriggerAddAction(trgPickup, function OnPickup)
call Command.register("-bag", function Open)
// Register Bag Item Events
call OnBagDrop(function OnItemDrop)
call OnBagInventory(function OnMoveToInventory)
endfunction
endscope
Last edited: