1 |
Virtual file system... so that's where it's been hiding!
|
1 |
Virtual file system... so that's where it's been hiding!
|
2 |
\n
|
2 |
\n
|
3 |
OK, here's a little working example widget that I made. Should be helpful if someone still can't figure out how to put all of the above together. Criticism welcome.
|
3 |
OK, here's a little working example widget that I made. Should be helpful if someone still can't figure out how to put all of the above together. Criticism welcome.
|
4 |
\n
|
4 |
\n
|
5 |
[spoiler]{
{
{
local
version
=
"0.
01"
|
5 |
[spoiler]{
{
{
local
version
=
"0.
02"
|
6 |
\n
|
6 |
\n
|
7 |
function widget:GetInfo()
|
7 |
function widget:GetInfo()
|
8 |
return {
|
8 |
return {
|
9 |
name
=
"Pull
'em
all!
v
".
.
version,
|
9 |
name
=
"Pull
'em
all!
v
".
.
version,
|
10 |
desc
=
"Switches
freshly
built
Newtons
to
pull
in
their
targets.
",
|
10 |
desc
=
"Switches
freshly
built
Newtons
to
pull
in
their
targets.
",
|
11 |
author
=
"RandomX",
|
11 |
author
=
"RandomX",
|
12 |
date
=
"",
|
12 |
date
=
"January
24,
2019",
|
13 |
license
=
"",
|
13 |
license
=
"",
|
14 |
layer
=
0,
|
14 |
layer
=
0,
|
15 |
enabled
=
true
|
15 |
enabled
=
true
|
16 |
}
|
16 |
}
|
17 |
end
|
17 |
end
|
|
|
18 |
\n
|
18 |
\n
|
19 |
\n
|
19 |
-- include ("LuaRules/Configs/customcmds.h.lua")
|
20 |
-- include ("LuaRules/Configs/customcmds.h.lua")
|
20 |
VFS.Include ("LuaRules/Configs/customcmds.h.lua")
|
21 |
VFS.Include ("LuaRules/Configs/customcmds.h.lua")
|
21 |
-- local CMD_PUSH_PULL = 35666
|
22 |
-- local CMD_PUSH_PULL = 35666
|
22 |
local MarkerAddPoint = Spring.MarkerAddPoint
|
23 |
local MarkerAddPoint = Spring.MarkerAddPoint
|
23 |
local GetUnitPosition = Spring.GetUnitPosition
|
24 |
local GetUnitPosition = Spring.GetUnitPosition
|
24 |
local GiveOrderToUnit = Spring.GiveOrderToUnit
|
25 |
local GiveOrderToUnit = Spring.GiveOrderToUnit
|
25 |
local
Pull
=
0
|
26 |
local
GetSpecState
=
Spring.
GetSpectatingState
|
|
|
27 |
local Pull = {0}
|
26 |
\n
|
28 |
\n
|
27 |
-- As soon as a Newton is built, switch its mode to "Pull".
|
29 |
-- As soon as a Newton is built, switch its mode to "Pull".
|
28 |
function widget:UnitFinished (unitID, unitDefID, teamID)
|
30 |
function widget:UnitFinished (unitID, unitDefID, teamID)
|
29 |
--
Spectators
shouldn't
interfere.
.
.
|
31 |
local
ux,
uy,
uz
|
30 |
if Spring.GetSpectatingState() then
|
|
|
31 |
widgetHandler:RemoveWidget()
|
|
|
32 |
end
|
|
|
33 |
\n
|
32 |
\n
|
34 |
local ux, uy, uz
|
|
|
35 |
if UnitDefs[unitDefID].name == "turretimpulse" then
|
33 |
if UnitDefs[unitDefID].name == "turretimpulse" then
|
36 |
ux, uy, uz = GetUnitPosition (unitID)
|
34 |
ux, uy, uz = GetUnitPosition (unitID)
|
|
|
35 |
\n
|
37 |
MarkerAddPoint (ux, uy, uz, UnitDefs[unitDefID].humanName, true)
|
36 |
MarkerAddPoint (ux, uy, uz, UnitDefs[unitDefID].humanName, true)
|
38 |
-- Spring.GiveOrderToUnit (Newton's ID, 35666, {0}, 0)
|
37 |
-- Spring.GiveOrderToUnit (Newton's ID, 35666, {0}, 0)
|
39 |
GiveOrderToUnit
(
unitID,
CMD_PUSH_PULL,
{
Pull}
,
0)
|
38 |
GiveOrderToUnit
(
unitID,
CMD_PUSH_PULL,
Pull,
0)
|
|
|
39 |
end
|
|
|
40 |
end
|
|
|
41 |
\n
|
|
|
42 |
\n
|
|
|
43 |
-- The rest of the code is there to disable the widget for spectators
|
|
|
44 |
local function DisableForSpec()
|
|
|
45 |
if GetSpecState() then
|
|
|
46 |
widgetHandler:RemoveWidget()
|
|
|
47 |
end
|
|
|
48 |
end
|
|
|
49 |
\n
|
|
|
50 |
\n
|
|
|
51 |
function widget:Initialize()
|
|
|
52 |
DisableForSpec()
|
40 |
end
|
53 |
end
|
|
|
54 |
\n
|
|
|
55 |
\n
|
|
|
56 |
function widget:PlayerChanged (playerID)
|
|
|
57 |
DisableForSpec()
|
41 |
end}}}[/spoiler]
|
58 |
end}}}[/spoiler]
|