// Threshold timeout to fire event for one player
constant function MouseMovement_Timeout takes nothing returns real
return 0.2
endfunction
function MouseMovement_onClick takes nothing returns nothing
if (BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_RIGHT) then
set udg_MMS_IsClicked[GetPlayerId(GetTriggerPlayer())] = true
endif
endfunction
function MouseMovement_onRelease takes nothing returns nothing
if (BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_RIGHT) then
set udg_MMS_IsClicked[GetPlayerId(GetTriggerPlayer())] = false
endif
endfunction
function MouseMovement_onMove takes nothing returns nothing
local integer playerId = GetPlayerId(GetTriggerPlayer())
if (udg_MMS_IsClicked[playerId] and TimerGetRemaining(udg_MMS_Timer[playerId]) == 0 ) then
if MouseMovement_Timeout() > 0 then
call TimerStart(udg_MMS_Timer[playerId], MouseMovement_Timeout(), false, null)
endif
set udg_MMS_X = BlzGetTriggerPlayerMouseX()
set udg_MMS_Y = BlzGetTriggerPlayerMouseY()
set udg_MMS_Location = Location(udg_MMS_X, udg_MMS_Y)
set udg_MMS_Player = GetTriggerPlayer()
set udg_MMS_Event = 1
set udg_MMS_Event = 0
call RemoveLocation(udg_MMS_Location)
endif
endfunction
function MouseMovement_MouseRegister takes trigger t, integer ev returns nothing
local integer i = 0
loop
exitwhen i > 24
call TriggerRegisterPlayerMouseEventBJ(t, Player(i), ev)
set i = i + 1
endloop
endfunction
function InitTrig_MouseMovement takes nothing returns nothing
local trigger t
local integer i
set t = CreateTrigger()
call TriggerAddAction(t, function MouseMovement_onClick)
call MouseMovement_MouseRegister(t, bj_MOUSEEVENTTYPE_DOWN)
set t = CreateTrigger()
call TriggerAddAction(t, function MouseMovement_onRelease)
call MouseMovement_MouseRegister(t, bj_MOUSEEVENTTYPE_UP)
set t = CreateTrigger()
call TriggerAddAction(t, function MouseMovement_onMove)
call MouseMovement_MouseRegister(t, bj_MOUSEEVENTTYPE_MOVE)
set i = 0
loop
exitwhen i > 24
set udg_MMS_Timer[i] = CreateTimer()
set i = i + 1
endloop
endfunction