Page 1 of 1

Lua ui help request. (unit selection icon)

Posted: 25 Feb 2007, 23:23
by smoth
I am looking into learning lua ui, is there a widget that I can look at to learn how to do this:

I want to make a widget to look for a specific unit in my mod. If it finds the target unit on my team and alive it will create a icon that I can click to select the unit while it exists.

Posted: 26 Feb 2007, 22:21
by tinnut
Hi smoth,

You could start with the IdleBuilders widget by Ray.

Add the following into to the Initialize call-in function (perhaps at line 25):

Code: Select all

	local unitDefId
	for unitDefId = 1, table.getn(UnitDefs) do
		if UnitDefs[unitDefId].name == "armsolar" then
			lookingForUnitId = unitDefId						
			break
		end
	end
The above searches through the UnitDefs table to find the unitDefID that is your unit type and then sets the "lookingForUnitId" global variable to this value. You'll want to replace "armsolar" with the name of the unit you're looking for.

Next, at at line 87 is:

Code: Select all

if IsIdleBuilder(unitID) then
If you changed IsIdleBuilder to a new function, say, IsMyUnit():

Code: Select all

if IsMyUnit(unitID) then
and then create this new function like:

Code: Select all

function IsMyUnit(unitId)
	local unitDefId = Spring.GetUnitDefId(unitId)
	return unitDefId == lookingForUnitId
end
In theory the above should give you basically what you want, but I have not tested it. You'll also want to change the functions; LeftMouseButton, RightMouseButton and MiddleMouseButton to do the functions you want.

This will unfortunately be in-compatible with IdleBuilders as they'd operate in the same screen space, but you can fix this up after you've got it working.

You could also change the call to "GetTeamUnits()" to "GetTeamUnitsSorted()" along with the associated code, as this would be a lot more efficient for your purposes, but then again the difference may not be noticeable.

Cheers.

Posted: 27 Feb 2007, 09:02
by smoth
wow, thanks. I was looking into the mod specific gui(wanted to add some stuff) so I can make gundam a little easier to play. I am still very new to lau and I always am a bit nervous with a new language.

I hope this weekend I can try it out. If my professors do not load me down with homework that is :P.

any tips on lua reading? like a good website that I can see many examples?

Posted: 27 Feb 2007, 10:49
by tinnut
I usually just Google any queries I have, but they usually take me to this site:
http://lua-users.org/wiki/TutorialDirectory

Posted: 28 Feb 2007, 00:53
by LordMatt
smoth wrote:any tips on lua reading? like a good website that I can see many examples?
lol reading isn't cool. Better to just pm spam trepan with all your questions. :P

::RUNS::

Posted: 01 Mar 2007, 10:15
by smoth
LordMatt wrote:
smoth wrote:any tips on lua reading? like a good website that I can see many examples?
lol reading isn't cool. Better to just pm spam trepan with all your questions. :P

::RUNS::
I'd rather save that for the really hard questions.