Page 1 of 2

Request: auto hold position for long range units.

Posted: 15 Feb 2007, 17:53
by Bobcatben
hi guys, i was wondering if someone could make a lua script that would turn long range units(like merls, mobile artillery the core missile tank, missile ship etc) hold position, i like to use them for defense or park them next to some place and let them shell.

i would write it myself, but iam a newb when it comes to lua, and theres no way for me to figure out whats wrong with it as theres no error messages, it just doesnt appear in the menu when it doesnt work.

thanks

Posted: 15 Feb 2007, 19:38
by RaiFox
I'd like to get a Lua script like this aswell, due to the ping I get It usually takes me 3-5 seconds to cycle thru the options to get to hold position, so a script like this will be appreciated.

Posted: 15 Feb 2007, 19:59
by Bobcatben
like i said, ill even write it myself if someone could give me a bit of code that will filter units by they're description, or even name, i would just make a list of all of the long ranged units to affect. unless theres a more efficient way.

Posted: 15 Feb 2007, 20:16
by LOrDo
Scratch long range units. Make it do that for EVERYTHING. I hate my units suddenly attack a nearby somthing only to get blown up by a dozen HLT's.

Posted: 15 Feb 2007, 20:23
by trepan
Some related widgets to take a look at:
LuaUI/Widgets/unit_stockpiler.lua
LuaUI/Widgets/unit_immobile_builder.lua

Posted: 15 Feb 2007, 22:45
by Bobcatben
ive looked at those, my problem is, i dont know how to check in lua, if a string contains another string, so i could filter descriptions for stuff like rocket, missile, artillery etc, unless i could just do it by range.

Posted: 15 Feb 2007, 22:53
by trepan
Section 5.3 in http://www.lua.org/manual/5.0/manual.html

P.S. I don't really think that filtering by name is the best way
to go. See if you can pick out what you need from the UnitDefs
and WeaponDefs structures (their parameters are listed at the
end of LuaUI/API.txt).

Posted: 16 Feb 2007, 00:03
by Bobcatben
i finnaly got one to work that filters by range, > 300 are set to hold position if they arnt planes and are mobile.

Posted: 16 Feb 2007, 00:43
by mehere101
I'd say make that configurable, for various mods/preferences

Posted: 17 Feb 2007, 16:23
by Bobcatben
how does one check if a element exists in a lua table, i was going to make it use one so you could have multiple settings for different mods, with the mod string as the key to the array. once i get that working i was thinking about uploading it.

Posted: 17 Feb 2007, 21:43
by ZellSF
LOrDo wrote:Scratch long range units. Make it do that for EVERYTHING. I hate my units suddenly attack a nearby somthing only to get blown up by a dozen HLT's.
Eh, if you want to do it for everything, just set your factories to it, that's not difficult, or time consuming.

Posted: 23 Feb 2007, 01:45
by Bobcatben
what i want is only long ranged units to be hold position, my script works, i just wanted to add a way to put different ranges for different mods, but i know nothing of lua so i dont know how to see if a entry with a certain key exists in a table acting as a associative array(std::map in c++, dictionary in python).

Posted: 23 Feb 2007, 02:29
by LOrDo
ZellSF wrote:
LOrDo wrote:Scratch long range units. Make it do that for EVERYTHING. I hate my units suddenly attack a nearby somthing only to get blown up by a dozen HLT's.
Eh, if you want to do it for everything, just set your factories to it, that's not difficult, or time consuming.
Having to set EVERY one of my factories every single game is pretty time consuming. :X And hard to remember.
Automation is win.

Posted: 24 Feb 2007, 00:56
by LordMatt
I'm sure it would be possible to write a widget that set certain units to hold position, however, I don't have time to write it. ;)

Posted: 24 Feb 2007, 02:07
by Bobcatben
i wrote one, i just need help to make it have multiple settings for different mods, i just need to know how to see if a element with a certain key exists in a lua associative array.

Posted: 24 Feb 2007, 18:42
by Kloot

Code: Select all

local val = table[key]

if (val ~= nil) then
	<key, val> was in table
else
	<key, val> was not in table
end

Posted: 26 Feb 2007, 17:33
by Bobcatben
and how do you format strings in lua.

in python it would be
blah = "hello my name is %s iam %d years old"%(name,age)

in c++ it would be.
sprintf(blah,"hello my name is %s iam %d years old",name,age);


and for some reason(i cant exactly get error messages so i have no idea why)

this makes the script not load.

Code: Select all

local Ranges = {
	["AASS223.sdz"] = 300,
}

local RangeGreaterThen = nil

	---pick the range from the array.
	RangeGreaterThen = Ranges[Game.modName]
	if(RangeGreaterThen ~= nil)
		Spring.SendCommands({"echo dingdong"})
	else
		RangeGreaterThen = 300
	
	Spring.SendCommands({"echo Loaded"})

Posted: 26 Feb 2007, 17:42
by trepan
Section 5.3 (string.format)
http://www.lua.org/manual/5.0/manual.html

You can also use the ".." concatenation operator and the
tostring() function (numbers will automatically be converted
to strings when using "..").

example:

Code: Select all

value = 12
print("value = " .. value)

Posted: 26 Feb 2007, 18:50
by Bobcatben
any idea why my code doesnt load?

Posted: 26 Feb 2007, 18:55
by Kloot
"if(RangeGreaterThen ~= nil)" is missing a then, by the looks of it.