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.
Lua ui help request. (unit selection icon)
Moderator: Moderators
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):
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:
If you changed IsIdleBuilder to a new function, say, IsMyUnit():
and then create this new function like:
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.
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
Next, at at line 87 is:
Code: Select all
if IsIdleBuilder(unitID) then
Code: Select all
if IsMyUnit(unitID) then
Code: Select all
function IsMyUnit(unitId)
local unitDefId = Spring.GetUnitDefId(unitId)
return unitDefId == lookingForUnitId
end
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.
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
.
any tips on lua reading? like a good website that I can see many examples?
I hope this weekend I can try it out. If my professors do not load me down with homework that is

any tips on lua reading? like a good website that I can see many examples?
I usually just Google any queries I have, but they usually take me to this site:
http://lua-users.org/wiki/TutorialDirectory
http://lua-users.org/wiki/TutorialDirectory