Auto First Build Facing

Auto First Build Facing

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

Moderators: Moderators, Moderators

Post Reply
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Auto First Build Facing

Post by zwzsg »

So that Build Facing default is less stupid than always south.

Instruction: copy into \LuaUI\Widgets

Edit: Version before that edit was very broken
Attachments
autofirstbuildfacing.lua
(1.56 KiB) Downloaded 44 times
0 x

User avatar
REVENGE
Posts: 2379
Joined: 24 Aug 2006, 06:13

Re: Auto First Build Facing

Post by REVENGE »

Simple but useful, nice job. :-)
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Auto First Build Facing

Post by zwzsg »

simpler, faster, stronger, shorter, better:
Attachments
autofirstbuildfacing.lua
(1007 Bytes) Downloaded 43 times
0 x

User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Auto First Build Facing

Post by manolo_ »

zwzsg wrote:simpler, faster, stronger, shorter, better:
could u modify ur lua in that way that u could turn the building by holding e.g. alt+mousewheel up/down?
0 x

User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Auto First Build Facing

Post by lurker »

You should be able to do that in uikeys.txt, and it's unrelated to this widget.
0 x

User avatar
Aqo
Posts: 24
Joined: 18 Oct 2008, 02:23

Re: Auto First Build Facing

Post by Aqo »

Cool, I wanted something like that. Good job.
It would be nice if there was an arrow pointing out every time you build a building that produces units to make it more hands down obvious where it's facing.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Auto First Build Facing

Post by zwzsg »

manolo_ wrote:could u modify ur lua in that way that u could turn the building by holding e.g. alt+mousewheel up/down?
lurker wrote:You should be able to do that in uikeys.txt
Personnaly I have edited my uikeys.txt to add:

Code: Select all

bind            numpad2  buildfacing  south
bind            numpad4  buildfacing  west
bind            numpad6  buildfacing  east
bind            numpad8  buildfacing  north
I should be noted that by default you have

Code: Select all

  bind                  [  buildfacing inc
  bind            Shift+[  buildfacing inc
  bind                  ]  buildfacing dec
  bind            Shift+]  buildfacing dec
which means that without changing any file, right now, you can rotate buildings by pressing [ and ] (assuming you don't have like me a foreign keyboard)

Editing uikeys.txt yourself is probably easier and more convenient than asking for Lua Widget. But of course I could wrap up those configuration commands into a lua widget. However, I did not find any "key" for mousewheelup and mousewheeldown.
lurker wrote:and it's unrelated to this widget.
Indeed it is unrelated. I assumed that [ and ] to turn building was common knownledge. My widget is to remove the hassle of pressing them at each start of the game.
0 x

User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Auto First Build Facing

Post by lurker »

I was under the impression scrolling tended to map to mouse 4 and 5, but perhaps not or perhaps only on some setups.
0 x

User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Auto First Build Facing

Post by manolo_ »

thx, but i wanted something like that, hold shift+mouse wheel down --> building heading to east, hold shift+mouse wheel down building heading to north, hold shift+mouse wheel down building heading to west, hold shift+mouse wheel up building heading to back to north,.... im not sure if its possible with uikeys.txt
0 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14618
Joined: 17 Nov 2005, 02:43

Re: Auto First Build Facing

Post by Forboding Angel »

Z, I could really use this, but tbh what I need is for the commander to be facing in the correct direction when he spawns (The commander is a factory in this case). Is that doable?
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6113
Joined: 29 Apr 2005, 01:14

Re: Auto First Build Facing

Post by FLOZi »

it is doable with a gadget. IIRC IW already has one.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Auto First Build Facing

Post by zwzsg »

Kernel Panic has had something to make the homebases face the center of the map since.. even before Lua! Then it was improved a bit with Lua, which result in now having an ugly half cob half Lua code that I wouldn't recommend copying.
0 x

Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Auto First Build Facing

Post by Gnomre »

The gadget I wrote (it was something like a week before this widget iirc) is basically the same process in gadget form. The major difference is that you have to respawn the commander unit to change its direction.

I haven't had this approach cause any problems with any other gadgets/widgets except for select & center widgets, which need to be delayed a couple frames to work properly.

If you can wait about 8-10 hours until I get home, I'll go ahead and release it; it's not terribly advanced code, especially when zwzsg's widget could just as easily be adapted. Hell, maybe there's a better way to do it than the way I used, but afaik you can't change the buildfacing of a building after it's been spawned.
0 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14618
Joined: 17 Nov 2005, 02:43

Re: Auto First Build Facing

Post by Forboding Angel »

Yeah I can wait, no rush. And yeah, turrning after spawn would be bad, cause then the yardmap would be lolforked.
0 x

Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Auto First Build Facing

Post by Gnomre »

Code: Select all

function gadget:GetInfo()
	return {
		name      = "HQ Heading",
		desc      = "Sets the heading of the Imperial HQ based on nearest map edge",
		author    = "Gnome",
		date      = "October 2008",
		license   = "PD",
		layer     = -5,
		enabled   = true  --  loaded by default?
	}
end

if (gadgetHandler:IsSyncedCode()) then

function gadget:GameFrame(n)
	if(n == 1) then
		local mapx = Game.mapX * 512
		local mapz = Game.mapY * 512
		for _,uid in ipairs(Spring.GetAllUnits()) do
			local udid = Spring.GetUnitDefID(uid)
			if(UnitDefs[udid].name == "imp_commander") then
				local x,y,z = Spring.GetUnitBasePosition(uid)
				local team = Spring.GetUnitTeam(uid)
				local heading = "south"

				if(x > mapx / 2) then						--unit is in the east side
					if(z > mapz / 2) then					--unit is in the south east
						if(mapx - x < mapz - z) then heading = "west"
						else heading = "north" end
					else							--unit is in the north east
						if(mapx - x < z) then heading = "west"
						else heading = "south" end
					end
				else								--unit is in the west side
					if(z > mapz / 2) then					--unit is in the south west
						if(x < mapz - z) then heading = "east"
						else heading = "north" end
					else							--unit is in the north west
						if(x < z) then heading = "east"
						else heading = "south" end
					end
				end

				Spring.CreateUnit("imp_commander",x,y,z,heading,team)
				Spring.DestroyUnit(uid,false,true)
			end
		end
		gadgetHandler:RemoveGadget()
	end
end

end
You could probably pretty it up, but since it only runs once per game in a loop of what, 32 units max, what's a little inefficiency hurt? The only notable change you might need to make is to make it able to handle multiple unitdefs. Or I guess you could just cache the unit name and look for isCommander == true or whatever that unitdef tag is called.
0 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14618
Joined: 17 Nov 2005, 02:43

Re: Auto First Build Facing

Post by Forboding Angel »

Woot! Works perfectly :-), Thanks Gnome!
0 x

User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Auto First Build Facing

Post by manolo_ »

suggestion: sorry in the wrong widget
Last edited by manolo_ on 21 Aug 2009, 21:51, edited 1 time in total.
0 x

User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Re: Auto First Build Facing

Post by Caydr »

Suggestion: the widget should shut itself off after it's been run once, no reason it should keep running.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Auto First Build Facing

Post by zwzsg »

It's not and cannot be a widget!

Also, what do you think gadgetHandler:RemoveGadget() is for?

Edit: Oh sorry, you meant mine, not Gnome's.

Well, the one in my third post has: widgetHandler:RemoveWidget() Maybe you were tricked by how it has to remain active until you attempt to place one building? That was because I can't change buildfacing when not in buildplacing mode.
0 x

User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Re: Auto First Build Facing

Post by Caydr »

Yep, I was tricked :(
0 x

Post Reply

Return to “Lua Scripts”