Page 1 of 1
Auto First Build Facing
Posted: 26 Oct 2008, 23:55
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
Re: Auto First Build Facing
Posted: 27 Oct 2008, 01:17
by REVENGE
Simple but useful, nice job.

Re: Auto First Build Facing
Posted: 27 Oct 2008, 02:40
by zwzsg
simpler, faster, stronger, shorter, better:
Re: Auto First Build Facing
Posted: 27 Oct 2008, 16:41
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?
Re: Auto First Build Facing
Posted: 27 Oct 2008, 16:52
by lurker
You should be able to do that in uikeys.txt, and it's unrelated to this widget.
Re: Auto First Build Facing
Posted: 27 Oct 2008, 19:14
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.
Re: Auto First Build Facing
Posted: 28 Oct 2008, 00:29
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.
Re: Auto First Build Facing
Posted: 28 Oct 2008, 05:08
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.
Re: Auto First Build Facing
Posted: 28 Oct 2008, 07:02
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
Re: Auto First Build Facing
Posted: 15 Aug 2009, 06:55
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?
Re: Auto First Build Facing
Posted: 15 Aug 2009, 13:53
by FLOZi
it is doable with a gadget. IIRC IW already has one.
Re: Auto First Build Facing
Posted: 15 Aug 2009, 15:08
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.
Re: Auto First Build Facing
Posted: 15 Aug 2009, 20:39
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.
Re: Auto First Build Facing
Posted: 16 Aug 2009, 00:07
by Forboding Angel
Yeah I can wait, no rush. And yeah, turrning after spawn would be bad, cause then the yardmap would be lolforked.
Re: Auto First Build Facing
Posted: 16 Aug 2009, 04:40
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.
Re: Auto First Build Facing
Posted: 16 Aug 2009, 05:30
by Forboding Angel
Woot! Works perfectly

, Thanks Gnome!
Re: Auto First Build Facing
Posted: 21 Aug 2009, 20:44
by manolo_
suggestion: sorry in the wrong widget
Re: Auto First Build Facing
Posted: 21 Aug 2009, 21:46
by Caydr
Suggestion: the widget should shut itself off after it's been run once, no reason it should keep running.
Re: Auto First Build Facing
Posted: 21 Aug 2009, 22:23
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.
Re: Auto First Build Facing
Posted: 22 Aug 2009, 03:15
by Caydr
Yep, I was tricked
