library DreadguardDrop initializer Init
globals
private hashtable hash = InitHashtable()
private string COL_INTENT = "|cffff0000" // Red
private string COL_CONFIRM = "|cff00ffff" // Blue
private string COL_DREAD = "|cff32cd32" // Blight Green
private group tempGroup = CreateGroup()
private unit testHero = null
endglobals
private function OnItemEject takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer uid = GetHandleId(u)
if HaveSavedReal(hash, uid, 1) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, COL_DREAD + "[DREADGUARD]:|r Item hit the ground!")
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, COL_CONFIRM + "X: " + R2S(LoadReal(hash, uid, 1)) + " | Y: " + R2S(LoadReal(hash, uid, 2)))
call FlushChildHashtable(hash, uid)
endif
set u = null
endfunction
private function CheckOrderFrame takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tid = GetHandleId(t)
local unit u = LoadUnitHandle(hash, tid, 1)
local integer uid = GetHandleId(u)
local integer order = GetUnitCurrentOrder(u)
if order >= 852001 and order <= 852007 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, COL_INTENT + "[INTENT]|r Locking coordinates...standby...")
call SaveReal(hash, uid, 1, LoadReal(hash, tid, 2))
call SaveReal(hash, uid, 2, LoadReal(hash, tid, 3))
endif
call FlushChildHashtable(hash, tid)
call DestroyTimer(t)
set t = null
set u = null
endfunction
private function OnMouseClick takes nothing returns nothing
local timer t
local integer tid
local player p = GetTriggerPlayer()
local unit selected = null
if BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_LEFT then
call GroupEnumUnitsSelected(tempGroup, p, null)
set selected = FirstOfGroup(tempGroup)
call GroupClear(tempGroup)
if selected != null then
set t = CreateTimer()
set tid = GetHandleId(t)
call SaveUnitHandle(hash, tid, 1, selected)
call SaveReal(hash, tid, 2, BlzGetTriggerPlayerMouseX())
call SaveReal(hash, tid, 3, BlzGetTriggerPlayerMouseY())
call TimerStart(t, 0.00, false, function CheckOrderFrame)
endif
endif
set t = null
set p = null
set selected = null
endfunction
private function DelayedSetup takes nothing returns nothing
local timer t = GetExpiredTimer()
local player p = Player(0)
call DestroyTimer(t)
set t = null
set testHero = CreateUnit(p, 'Usyl', 0, 0, 270)
call SelectUnitForPlayerSingle(testHero, p)
call UnitAddItemById(testHero, 'phea')
call DisplayTimedTextToPlayer(p, 0, 0, 30, COL_DREAD + "DREADGUARD SYSTEM READY.|r")
call DisplayTimedTextToPlayer(p, 0, 0, 30, "Right-click item -> Left-click, drop it like it's hot!")
set p = null
endfunction
private function Init takes nothing returns nothing
local trigger m = CreateTrigger()
local trigger d = CreateTrigger()
local integer i = 0
loop
exitwhen i > 12
call TriggerRegisterPlayerEvent(m, Player(i), EVENT_PLAYER_MOUSE_DOWN)
set i = i + 1
endloop
call TriggerAddAction(m, function OnMouseClick)
call TriggerRegisterAnyUnitEventBJ(d, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddAction(d, function OnItemEject)
call TimerStart(CreateTimer(), 0.50, false, function DelayedSetup)
// Final nulling
set m = null
set d = null
endfunction
endlibrary