/
autoquit.lua
57 lines (50 loc) · 1.62 KB
/
autoquit.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
----------------------------------------------------------------
-- global variables
----------------------------------------------------------------
local versionNumber = "v1.2"
local delay = 20
local endTime
local mx,my
----------------------------------------------------------------
-- speedups
----------------------------------------------------------------
local DiffTimers = Spring.DiffTimers
local GetTimer = Spring.GetTimer
local SendCommands = Spring.SendCommands
local Echo = Spring.Echo
local GetMouseState = Spring.GetMouseState
----------------------------------------------------------------
-- callins
----------------------------------------------------------------
function widget:GetInfo()
return {
name = "Autoquit",
desc = versionNumber .. " Automatically quits "..delay.."s after the game ends. Move mouse to cancel.",
author = "Evil4Zerggin & zwzsg",
date = "25 December 2008",
license = "GNU LGPL, v2.1 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
function widget:Initialize()
endTime = false
end
function widget:GameOver()
endTime = GetTimer()
mx,my = GetMouseState()
Echo("<autoquit> Automatically exiting in " .. delay .. " seconds. Move mouse to cancel.")
end
function widget:Update(dt)
if endTime then
local nmx,nmy = GetMouseState()
if nmx~=mx or nmy~=my then
Echo("<autoquit> Autoquit canceled.")
endTime = false
-- widgetHandler:RemoveWidget()
elseif DiffTimers(GetTimer(), endTime) > delay then
Echo("<autoquit> Autoquit sending quit command.")
SendCommands("quitforce")
end
end
end