Page 1 of 1

.give all mobile

Posted: 26 Dec 2006, 18:43
by Caydr
Can we have an extension to the .give all command? What I'd like it to do is give all the units with a movement speed which is greater than 0.

Thanks

Posted: 26 Dec 2006, 18:51
by trepan
You could setup a LuaUI call that generated
a ".give" command for all mobile units. The
problem would be spacing them (although
that is possible too)

Posted: 26 Dec 2006, 19:08
by trepan
Spacing isn't really a problem, they're mobile :)

Here's the code ... just stick it in gui.lua and type
the following into the console: /luaui givemobile

P.S You'll want to start with a gui.lua that is already
known to work. LuaUI requires a valid LayoutButtons()
function to work (it is the only required call-in).

Code: Select all

function ConfigureLayout(command)
  if (command == "givemobile") then
    GiveMobile()
  end
end

Code: Select all

function GiveMobile()
  Spring.SendCommands({"say .cheat 1"}) -- enable cheating
  for udid,ud in pairs(UnitDefs) do
    if (ud and ud.canMove and (ud.speed > 0)) then
      Spring.SendCommands({"say .give " .. ud.name}) 
    end
  end  
end

Posted: 26 Dec 2006, 19:33
by trepan
Note that it's fairly easy to make little adjustments to this code
(especially when you can use /luaui reload to "recompile" it on
the fly, I've got "luaui reload" bound to Meta+r). One thing that
I did notice is that you may want yet another level of control with
respect to water based units. Checking against ud.minWaterDepth
should do the trick.

Posted: 26 Dec 2006, 21:27
by Caydr
That's very interesting, I'll give that a shot. It'll save me the time of nagging you about the ".give water" and ".give air" commands too :P