CustomKeys: unit_khaos.lua

File unit_khaos.lua, 1.5 KB (added by licho, 4 years ago)

Script for selecting unit types in view

Line 
1--------------------------------------------------------------------------------
2--------------------------------------------------------------------------------
3
4include("keysym.h.lua")
5
6
7function widget:GetInfo()
8  return {
9    name      = "Khaos group",
10    desc      = "description",
11    author    = "author",
12    date      = "31.1.2008",
13    license   = "GNU GPL, v2 or later",
14    layer     = 0,
15    enabled   = false  --  loaded by default?
16  }
17end
18
19--------------------------------------------------------------------------------
20--------------------------------------------------------------------------------
21
22local myTeam
23
24function widget:Initialize()
25        local _, _, spec, team = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
26        if spec then -- you are spectator, disable this widget
27                widgetHandler:RemoveWidget()
28                return false
29        end
30  myTeam = team
31end
32
33
34
35
36function widget:KeyPress(key, modifier, isRepeat)
37  local filter = nil
38  if (modifier.ctrl) then
39                if (key == KEYSYMS.J) then
40      filter = {armjanus = 1, armstump = 1}
41    end
42    if (key == KEYSYMS.N_1) then
43      filter = {armflash = 1}
44    end
45  end
46 
47  if (filter ~= nil) then
48    local toSelect = {}
49    for _, id in pairs(Spring.GetVisibleUnits(myTeam)) do
50      if (filter[UnitDefs[Spring.GetUnitDefID(id)].name] ~= nil) then
51        table.insert(toSelect, id)
52      end
53    end
54    Spring.SelectUnitArray(toSelect)
55  end
56end
57
58
59--------------------------------------------------------------------------------