Lua ui help request. (unit selection icon)

Lua ui help request. (unit selection icon)

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

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Lua ui help request. (unit selection icon)

Post 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.
tinnut
Posts: 67
Joined: 09 Sep 2006, 08:17

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Post 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?
tinnut
Posts: 67
Joined: 09 Sep 2006, 08:17

Post by tinnut »

I usually just Google any queries I have, but they usually take me to this site:
http://lua-users.org/wiki/TutorialDirectory
User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Post 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::
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Post 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.
Post Reply

Return to “Lua Scripts”