Ok detailed response time.
If you haven't already should create a boolean-type class variable named "SM_is_attached" or similar.
Initialize it as being true in your class constructor because I assume that your vessel starts with the SM attached and then jettisons it rather than vice versa

.
In clbksetclasscaps declare your thrusters, propellant tanks, and meshes for both the CM and SM. Make sure that the CM's are declared
before the SM's to avoid errors with indexing on scenario load (explained in my tutorial).
Now create a custom void function named "SeperateSM()" or similar. It's structure should look something like this...
Code:
void Pheonix::SeparateSM (void)
{
if (SM_is_attached) // Sanity check, is there a SM to jettison?
{
declare a char (string-type) variable and copy your parent vessel's name to it.
add "_SM" or something similar to the end of your string
declare a VESSELSTATUS variable and copy your parent vessel's current state to it.
declare a seperation offset for your SM, aka VECTOR3 showing it's location relative to the parent vessel
declare a seperation vector, aka direction
declare a seperation velocity.
apply the above vectors as transformations to your VESSELSTATUS variable
Use oapiCreateVessel (name, class, status), with the above string and VESSELSTATUS variables to create the SM as a seperate vessel.
Get the object handle of the newly created vessel using our string variable
use that object handle in conjunction with oapiGetVesselInterface to get a independant VESSEL interface for our newly spawned SM vessel
Using that interface set propellant level of the SM vessel's tanks to the propellant level in the parent vessel's SM tanks.
Now that we've created the SM as a seperate vessel...
Delete the parent vessel's SM tanks.
Delete the parent vessel's SM thrusters.
Delete the Parent vessel's SM mesh.
Shift parent vessel's CoG.
Declare new thrusters and thrust groups as required.
} // end if statement
SM_is_attached = false; // update status of SM
} //Done
From there simply call the stage seperation function on the appropriate key press or when the assigned conditions are met.
This is all explained in detail, along with working code samples, in the following post
http://orbiter-forum.com/blog.php?b=1221
---------- Post added at 10:43 ---------- Previous post was at 10:30 ----------
PS:
Code:
// Key "J" Jettison the service module
if(key==OAPI_KEY_J&&!KEYMOD_SHIFT(kstate)&&!KEYMOD_CONTROL (kstate))
if (SMJett=1)
{
SMJettison();
SMJett--;
MeshControl ();
ClassControl ();
}
else
{
MeshControl ();
ClassControl ();
}
Should look like
Code:
// Key "J" Jettison the service module
if(key==OAPI_KEY_J&&!KEYMOD_SHIFT(kstate)&&!KEYMOD_CONTROL (kstate))
{
SeperateSM();
return 1;
}
---------- Post added at 10:52 ---------- Previous post was at 10:43 ----------
PPS:
You'll also need something in clbkpostcreation to handle instances where the vessel is spawned without a SM, on scenario load for instance.
to do this copy/paste everything in your stage seperation function that is not spawing the descent stage into clbkpostcreation and place it within a "if (SM_is_attached == false)" statement.