better unit_prevent_outsides_orders.lua needed

better unit_prevent_outsides_orders.lua needed

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

Moderator: Moderators

Post Reply
ansiktsburk
Posts: 7
Joined: 28 Dec 2009, 03:42

better unit_prevent_outsides_orders.lua needed

Post by ansiktsburk »

I'm a Lua noob and have been messing with BrainDamage's script with the aforementioned name to not only stop move orders but also build orders outside a certain area on my map. Stopping move, attack etc. works but do you guys have any suggestions how to stop construction? It seems to me that I could prevent stuff from being built even though they would still be in the queue, if placed on buildable locations and that might annoy players. For instance, if a radar can be placed in the middle of a queue and the queue completes without it being built, it certainly sucks.

Ideally, such a script would not only prevent queueing of orders like that but it would even show the area as unbuildable when pressing F2 but that might be too much to ask. It amazes me that this functionality hasn't been implemented through the typemap but until it is, this sort of lua script could do the trick. My solution with the current version of the map has been to make the terrain "spiky" so that nothing can be built and that works fine but doesn't look pretty.

Since I'm new to Lua and spring, no answer can be too detailed or explicit :)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: better unit_prevent_outsides_orders.lua needed

Post by Argh »

Um, just get the value of the typemap. If X, then allow the command, if Y, then fail the command. If you return false, a build order will not be added to the queue. No need for spiky stuff, you just need to set up your typemaps appropriately.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: better unit_prevent_outsides_orders.lua needed

Post by Niobium »

What is wrong with preventing them the same way you prevented move/attack etc? All build commands have a negative command ID / all negative command ID's are builds (afaik)
ansiktsburk
Posts: 7
Joined: 28 Dec 2009, 03:42

Re: better unit_prevent_outsides_orders.lua needed

Post by ansiktsburk »

I didn't know how to filter build commands until you said that about negative IDs so thanks! :-) Now that I think about it, I don't know if there's any reason not to prevent all commands outside the playing area but now the code prevents construction as well as movement outside so gameplay is what I want it to be.

But since you know this stuff I follow up by asking if there's a way to get the ideal solution: Currently the area is mostly green when you press F2 and have selected a building. Is there any way to make it show up red like any other unbuildable area then?
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: better unit_prevent_outsides_orders.lua needed

Post by Beherith »

Yeah, make its typemap 0 0 0 0 then it should be red.
ansiktsburk
Posts: 7
Joined: 28 Dec 2009, 03:42

Re: better unit_prevent_outsides_orders.lua needed

Post by ansiktsburk »

Won't that only make it show red because it's impassable for all cons except aircons? And only aircons could reach the area in question if the gadget didn't prevent it.
ansiktsburk
Posts: 7
Joined: 28 Dec 2009, 03:42

Re: better unit_prevent_outsides_orders.lua needed

Post by ansiktsburk »

Argh, how do I get the typemap value?

And is there any simple way to make building preview screens red when you have one selected and hover the mouse over the "forbidden" area? Then the only confusing thing would be F2, when used with an aircon and LOS to the forbidden area.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: better unit_prevent_outsides_orders.lua needed

Post by Argh »

Code: Select all

local type = Spring.GetGroundInfo(x,z)
...returns the name of the typemap, i.e., "ground", "sand", "whatever the mapper put in SMD". That's all you really need... have a typemap named "blocked terrain" or w/e, read that value, voila.
Post Reply

Return to “Lua Scripts”