Page 1 of 1

Unit information

Posted: 15 Oct 2010, 20:11
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

Re: Unit information

Posted: 15 Oct 2010, 20:27
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

Re: Unit information

Posted: 15 Oct 2010, 20:28
by discodowney
where is that unit_stats function?

Im just beginning with lua, so im not great with it.

Re: Unit information

Posted: 15 Oct 2010, 20:49
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.

Re: Unit information

Posted: 16 Oct 2010, 14:03
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.

Re: Unit information

Posted: 16 Oct 2010, 19:02
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."

Re: Unit information

Posted: 25 Oct 2010, 17:39
by discodowney
Can Widgets be automated. So can the function that gets a units health be made to run from the AI code?

Re: Unit information

Posted: 25 Oct 2010, 19:05
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.