Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Ugh, that does make things a little more complex. You can still do it without reflection or dependencies though (which to me is preferable).

You could build a reference on reaching the Main Menu which has all applicable mod parts and their intake area. The issue with this would be parts which can change (I imagine tweakscale could be a bit of an issue here unless you can query the rescale factor)

foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PART"))
{
float area;
ConfigNode intakeNode = node.GetNode("AtmosphericIntake");
if (intakeNode != null)
{
float.TryParse(intakeNode.GetValue("area"), out area);
modIntakeDict.Add(node.GetValue("name"), area); // Dictionary<string,float> (part name, intake area)
}
}

Link to comment
Share on other sites

I am calling Die() on a Kerbal, and it shows the KIA message below, however if I click on EVA the Kerbal(s) all come back to life, tried searching didn't really find anything.

Sample code:

   public class TestModule : PartModule
{
private bool foundCrew;

public override void OnStart(StartState state)
{
print("Hello Kerbin!");
base.OnStart(state);
}

public override void OnUpdate()
{
if (foundCrew) return;

var crew = vessel.GetVesselCrew();
foreach (var c in crew)
{
foundCrew = true;
StartCoroutine(KillKerbal(c));
}

base.OnUpdate();
}

private IEnumerator KillKerbal(ProtoCrewMember c)
{
yield return new WaitForSeconds(5);
c.Die();

}
}

Link to comment
Share on other sites

After killing the kerbal try adding: vessel.GetCrew().Remove©;

Gave that a shot, doesn't seem to make an effect. The EVA/IVA buttons are still available on their portraits and all of them are able to be revived.

Edited by ctordtor
Link to comment
Share on other sites

Gave that a shot, doesn't seem to make an effect. The EVA/IVA buttons are still available on their portraits and all of them are able to be revived.

In the logs I'm seeing:

[Log]: [00:00:00]: Jebediah Kerman was killed.

[Log]: [00:00:00]: Bill Kerman was killed.

[Log]: [00:00:00]: Bob Kerman was killed.

For grins, I added:

if(vessel.GetVesselCrew().Remove(c)) print("Removed");

But Removed doesn't show up in the log.

Link to comment
Share on other sites

Edit: Nevermind! Found that "flightID" does this exactly.

I am trying to link two objects, and save the reference between them in a persistent KSPField. Just saving the pointer doesn't work since the address will change each time etc, is there some consistent way to get a specific object after saving and loading? I think that the "routine mission manager" mod has you manually name a docking port, which is then uses as a reference to find it again after load, but I wanted something more automatic. Is there an internal part-instance-id that stays consistent across saves? Or am I best to generate a random GUID for my part and reference that way?

Thanks!

Edited by Koobze
Link to comment
Share on other sites

I found several id numbers which are saved for every part:

  • cid
    - get it with Part.craftID
    - different for each part of a vessel
    - I don't know if it stays the same all the time.
  • uid
    - get it with Part.flightID
    - different for each part
    - doesn't change on load/save and docking/undocking
  • mid
    - get it with Part.missionID
    - same for for all parts of a vessel
    - is set when the vessel is created the first time (upon launch)
    - doesn't change on load/save and docking/undocking
  • launchID
    - get it with Part.launchID
    - same for all part on the vessel
    - I don't know if it stays the same all the time.

A lot about the use of this numbers are unknown.

Link to comment
Share on other sites

Thanks, for now I am using flightID but I will keep an eye on it to see if it changes.

On an unrelated note... I've been trying to figure out how to change a Kerbal's velocity, but I can't seem to get it right. Been trying to make a Star Trek style teleporter to beam down to the surface of the planet, but every time my Kerbal retains his orbit velocity and smashes into the planet. I've tried using the kerbal's vessel.ChangeWorldVelocity, changing his rigidbody.velocity, changing his obt_velocity, but nothing seems to work. Anyone know how to get this done? I've killed Jeb so many times now. And what is World Velocity anyway? I don't see anywhere to actually query it.

Link to comment
Share on other sites

Hey quick question: so far has it proven possible to make a part cost science to first unlock (as in, first unlock the tech tree node, then to unlock the individual part for use costs science)?

If so, how was it done? Even an example workaround, like I believe at one point interstellar was capable of doing it.

Link to comment
Share on other sites

Initialising a floatCurve from a part config.

Everything I've read indicates I can just tag it as a KSPField and it works the same as most any other config variable. However I'm having no luck with this approach.


[KSPField]
FloatCurve torqueCurve = new FloatCurve();

// inside FixedUpdate()
torqueCurve.Evaluate(0.5); // returns zero

The config for the module has this for the floatcurve


torqueCurve
{
key = 0 1
key = 1 1
}

but evaluate always returns zero.

I checked the MM cache and the torquecurve is inside the partmodule where I would expect it to be.

Full source here

Edited by Crzyrndm
Link to comment
Share on other sites

I'm not sure about that, but I think adding the KSPField attribute doesn't imply, that the float curve is saved and loaded by KSP by default.

You'll have to modify it:

[KSPField(isPersistant = true)]

Also make sure you test that on a newly launched vessel. Existing parts may not have that attribute if you launched them before you added it in your code.

Link to comment
Share on other sites

Nada, KSPField works on it's default values if you just tag it like I have done (persistent = false, no GUI, etc.). You can see it higher up the source page I linked for saturationScale (which is 100% confirmed working as intended). Also, tagging things with persistent = true when you don't need to permanently track them is a bad idea (exactly because of cfg changes not taking effect on old parts)

EDIT

With persistent = true, I took a look in the save file just to make sure. torqueCurve had no keys

Edited by Crzyrndm
Link to comment
Share on other sites

I found a very old thread about KSPField: http://forum.kerbalspaceprogram.com/threads/10296-0-15-code-update-PartModule-KSPField-KSPEvent-ConfigNode-and-PartResource?p=168279&viewfull=1#post168279

If I understand that post right, KSPField can't handle complex data structures without some help. But again, it's a very old post. It could be different now.

Link to comment
Share on other sites

Just dropping in after a few years out-of-game.

I'd like to know whether there are library restrictions in place for mod development - I faintly remember some sort of DLL inspection/sanitation to prevent malicious code from a while back. I'm toying with the idea of integrating a broad .NET library and I'm afraid it might get the boot because it's likely full of unmanaged/unrestricted code and other goodies like that. Or I just made this all up...

Google couldn't relieve me, sorry.

Thanks in advance!,

Candre.

Link to comment
Share on other sites

Some of the restrictions were lifted a while back. I know that "System.Diagnostics.Process" is still on the list, but I don't know if there is any other.

Are you sure you really need big libs ? You may have problem with anything not targeting .NET 3.5.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...