Request: auto hold position for long range units.

Request: auto hold position for long range units.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Request: auto hold position for long range units.

Post 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
RaiFox
Posts: 40
Joined: 06 Oct 2006, 16:12

Post 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.
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post 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.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

Some related widgets to take a look at:
LuaUI/Widgets/unit_stockpiler.lua
LuaUI/Widgets/unit_immobile_builder.lua
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post 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).
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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.
User avatar
mehere101
Posts: 293
Joined: 15 Mar 2006, 02:38

Post by mehere101 »

I'd say make that configurable, for various mods/preferences
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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.
ZellSF
Posts: 1187
Joined: 08 Jul 2006, 19:07

Post 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.
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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).
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post 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.
User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Post 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. ;)
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Post 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
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post 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"})
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post 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)
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

any idea why my code doesnt load?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Post by Kloot »

"if(RangeGreaterThen ~= nil)" is missing a then, by the looks of it.
Post Reply

Return to “Lua Scripts”