With vessel deletion via oapi.del_vessel and vessel status manipulation via v_defset_status, one thing that's missing is vessel creation in lua.
I've been trying to add this function in the interpreter without much success.
I'd like it to work in a similar way that vessel creation works with the Scenario Editor:
-Enter name
-Enter Classname
-Vessel gets created in orbit around Earth:
R = 1.1 planet radius
Inc = 0 (ecl)
etc...
Once the vessel is created then manipulating its state is easy, either via set_elements or v_defset_status.
I believe that the addition of this function would open up a range of possibilities in lua scripting, so is there anyone who can do this?
Thanks in advance
---------- Post added 28th Sep 2018 at 11:46 ---------- Previous post was 27th Sep 2018 at 22:21 ----------
I am making some progress with this, but still having some trouble.
So far I've been able to spawn a vessel in Orbiter with lua.
I entered this in the Interpreter.h
These in Interpreter.cpp
Borrowed from the ScnEditor example
It compiles without errors and when I call oapi.create_vessel() in the script,
an XR2 Ravenstar (named "Jim") gets placed in orbit around Earth.
When I recompile with
I get a freeze and a few seconds later an "orbiter.exe is not responding" message. Same thing happens with classname = ("DG-S").
With classname = ("Atlantis"), I also get a freeze, but it lasts only for 2 seconds and the vessel spawns ok.
Does anyone have any idea why this is happening?
I've been trying to add this function in the interpreter without much success.
I'd like it to work in a similar way that vessel creation works with the Scenario Editor:
-Enter name
-Enter Classname
-Vessel gets created in orbit around Earth:
R = 1.1 planet radius
Inc = 0 (ecl)
etc...
Once the vessel is created then manipulating its state is easy, either via set_elements or v_defset_status.
I believe that the addition of this function would open up a range of possibilities in lua scripting, so is there anyone who can do this?
Thanks in advance
---------- Post added 28th Sep 2018 at 11:46 ---------- Previous post was 27th Sep 2018 at 22:21 ----------
I am making some progress with this, but still having some trouble.
So far I've been able to spawn a vessel in Orbiter with lua.
I entered this in the Interpreter.h
Code:
...
static int oapiSetFocusObject (lua_State *L);
static int oapiCreateVessel(lua_State *L); [COLOR="Red"]-- added here[/COLOR]
static int oapiGetObjectHandle (lua_State *L);
...
These in Interpreter.cpp
Code:
...
{"set_focusobj", oapiSetFocusObject},
{"create_vessel", oapiCreateVessel}, [COLOR="Red"]--added[/COLOR]
{"get_objhandle", oapiGetObjectHandle},
...
Borrowed from the ScnEditor example
Code:
int Interpreter::oapiCreateVessel(lua_State *L)
{
OBJHANDLE hVessel;
const char *name = ("Jim"); // lua_tostring(L, 1);
const char *classname = ("xr2ravenstar"); //lua_tostring(L, 1);
VESSELSTATUS2 vs;
memset(&vs, 0, sizeof(vs));
vs.version = 2;
vs.rbody = oapiGetGbodyByName("Earth");
if (!vs.rbody) vs.rbody = oapiGetGbodyByIndex(0);
double rad = 1.1 * oapiGetSize(vs.rbody);
double vel = sqrt(GGRAV * oapiGetMass(vs.rbody) / rad);
vs.rpos = _V(rad, 0, 0);
vs.rvel = _V(0, 0, vel);
hVessel = oapiCreateVesselEx(name, classname, &vs);
return 1;
}
It compiles without errors and when I call oapi.create_vessel() in the script,
an XR2 Ravenstar (named "Jim") gets placed in orbit around Earth.
When I recompile with
Code:
const char *classname = ("deltaglider");
With classname = ("Atlantis"), I also get a freeze, but it lasts only for 2 seconds and the vessel spawns ok.
Does anyone have any idea why this is happening?
Last edited: