Unit information

Unit information

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

Moderator: Moderators

Post Reply
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Unit information

Post by discodowney »

Hey,

So i need to retrieve unit information, stuff like health, number of units, etc. I was wondering if someone could help me out here. Im using conflict terra and i was talking to oksnoop2 and he mentioned that maybe i should use a lua gadget. Im not too familiar with these though. Is this the correct way of obtaining the info i need?

Cheers
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Unit information

Post by knorke »

how good are you with lua?
gadgets: lua included with the mod
widgets: lua run by the user

you could have a look at the logging widget from my demonaut program:
http://springrts.com/phpbb/viewtopic.ph ... 1&start=62

there is a function called unit_stats or similiar that shows how to get all kind of unit informations like health, position, name, team, name of owning player, etc
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Unit information

Post by discodowney »

where is that unit_stats function?

Im just beginning with lua, so im not great with it.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Unit information

Post by knorke »

the unitstats_s function is in the eventlogger.lua:
http://pastebin.ca/1963276

it is a bit choatic but basically there are functions like

Code: Select all

x,y,z=Spring.GetUnitPosition (unitID)
they can all be found here: http://springrts.com/wiki/Lua_SyncedRea ... formations

probally best to start from here: http://springrts.com/wiki/Lua_Scripting
and then do a "hello world" or something.
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Unit information

Post by discodowney »

Maybe im going blind, im not ruling it out, but i cant see anywhere on them pages where it tells me how to actually run a lua script. Can someone sort me out? thanks.

EDIT: Book i have mentions that in 5.0 theres a luac.exe where code can be entered into. This doesnt exist in 5.1. So Im gussing the thing to do is write a quick C++ program to execute the scripts.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Unit information

Post by knorke »

i cant see anywhere on them pages where it tells me how to actually run a lua script.
ah ok.
http://springrts.com/wiki/Lua_Widgets :
Installing Widgets & Using Widgets

Basically you put the .lua files in your spring\LuaUI\widgets folder.
Then ingame you press F11 and get a list of all active scripts. By clicking on them you can en/dis able them.

For developing there is this usefull command that you can enter in chat:
/luaui reload
it reloads all lua scripts if you have made changes to them. This way you do not have to restart spring.exe all the time.

It is also nice to have a good text editor, like this one: http://notepad-plus-plus.org/
It does synthax highlighting (helps avoiding mistakes) and shows line numbers. Line numbers are important if spring says "error in myaweseomewidget.lua in line 75."
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Unit information

Post by discodowney »

Can Widgets be automated. So can the function that gets a units health be made to run from the AI code?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Unit information

Post by knorke »

:shock:
widgets are always automatic, there are program code uhm what do you mean?
An AI written in Lua is basically just a widget (more correct: a gadget) and can of course use functions as Spring.GetUnitHealth (id)
If the AI is written in Java, C, Phython, ... there is an AI-interface. I don't know how that works but I am sure it does also provide similiar functions.
Post Reply

Return to “Lua Scripts”