Cephei

The official unoffical "help a fellow plugin developer" thread

2726 posts in this topic

17 hours ago, SkyKaptn said:

If I were to release just some ASET/RPM configs as well as a ModuleManager patch, does this still require a licence?

I know it seems silly for a small thing like that, but by default, we have no rights at all to your creation.  If you want to share your stuff, then you have to tell us what we're allowed to do with it.  Can we copy it?  Can we make an improved version and give that new version to people?  Can we sell our improved version without sharing any improvements we make, and without crediting you?

Besides letting us know how we're allowed to use the software, most licenses have a disclaimer about liability and warranty, so that you don't get sued.  It's a very small probability for KSP mods, but it doesn't hurt to have it.

If the only thing you want is credit, then the MIT license is good.  If you don't even want credit, you can make it public domain.

There's plenty more "standard" licenses to choose from:

For software: https://choosealicense.com/

For art and other stuff that isn't software: https://creativecommons.org/share-your-work/

MM patches would qualify as software, since they're a set of instructions.  ASET/RPM configs.. I dunno, but applying a software license to non-software is fine, but not the other way around.

Note that you cannot change a license retroactively!  If you release something under license A one day, and then under license "B" the next, then anyone who obtained a copy under license A is free to follow those terms forever, for that copy.  If you release version 2.0 under license A, then a new improved version 3.0 under license B, then people can't use version 3.0 under license A; they can only use version 2.0 under license A.

Note that if you're just contributing patches to an existing project, your patches by default use the project's existing license.  You can contribute patches under a different license, but the project maintainer doesn't have to accept them.

1 person likes this

Share this post


Link to post
Share on other sites

Hi,

With these codes of CommNetNetwork class below, I am trying to find out how to overcome the protected set and assign with my own subclass i.e. "CommNetNetwork.Instance = new SomeSubclassCommNetNetwork();".

//Edited out the KSP codes I was not supposed to post

I tried this trick but it doesn't work.

CommNetNetwork a = CommNetNetwork.FindObjectOfType<CommNetNetwork>(); // or CommNetNetwork.Instance.GetComponentInParent<CommNetNetwork>();
a = new SomeSubclassCommNetNetwork(); // result is a = null

Anyone can give tips on overcoming protected set property?

Edited by TaxiService

Share this post


Link to post
Share on other sites

@TaxiService you can do it using reflection, but can I ask why?  Generally replacing stuff that isn't meant to be replaced leads to trouble.

Share this post


Link to post
Share on other sites

And the CommNet itself is already made to be extendable. I don't have the reference with me ATM but most of it is extendable without reflexion, it was made that way.

 

Edit : found it. What you should actually replace to replace the commnet implementation is the CommNetwork, so CommNetNetwork.Instance.commNet = <yourImplentation>;

Edited by sarbian

Share this post


Link to post
Share on other sites
8 hours ago, blowfish said:

@TaxiService you can do it using reflection, but can I ask why?  Generally replacing stuff that isn't meant to be replaced leads to trouble.

See below

8 hours ago, sarbian said:

And the CommNet itself is already made to be extendable. I don't have the reference with me ATM but most of it is extendable without reflexion, it was made that way.

 

Edit : found it. What you should actually replace to replace the commnet implementation is the CommNetwork, so CommNetNetwork.Instance.commNet = <yourImplentation>;

Yup, it is quite extendable and I succeeded in extending the most of the CommNet. But the CommNetNetwork.Instance is not extendable despite that CommNetNetwork has virtual methods to override.

(Edit)
 

Edited by Red Iron Crown

Share this post


Link to post
Share on other sites
4 hours ago, TaxiService said:

Yup, it is quite extendable and I succeeded in extending the most of the CommNet. But the CommNetNetwork.Instance is not extendable despite that CommNetNetwork has virtual methods to override.

The reason I want to replace CommNetNetwork is that CommNetNetwork contains these codes

The virtual in there are most likely left over from a code iteration. The whole thing is a singleton and a MonoBehaviour and that bring plenty of ways for things to go sideway if you try to replace it...

Indeed there is something bad going on with that reset... I ll ask if they can do something for 1.3...

 

In the meantime : properties get/set are actually method so you should use reflection to call the set_Instance(CommNetNetwork c) method.

Something like

CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(yourNewInstance, null);

(the null is there because you call a static method)

1 person likes this

Share this post


Link to post
Share on other sites
5 hours ago, sarbian said:

The virtual in there are most likely left over from a code iteration. The whole thing is a singleton and a MonoBehaviour and that bring plenty of ways for things to go sideway if you try to replace it...

Indeed there is something bad going on with that reset... I ll ask if they can do something for 1.3...

 

In the meantime : properties get/set are actually method so you should use reflection to call the set_Instance(CommNetNetwork c) method.

Something like


CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(yourNewInstance, null);

(the null is there because you call a static method)

@blowfish and this poster, many thanks for letting me know about the Unity singleton pattern and the reflection. I will go read up on those. 

I already filed a feedback issue on the bug tracker on this CommNet issue and it seems that it caught the attention of one of the KSP staff. So a fix to this could show up in the KSP 1.3 round.

 

Share this post


Link to post
Share on other sites
On 2/8/2017 at 0:04 AM, Diazo said:

I do not believe that is possible through the event itself.

If it is, you would have to manually hook into the OnMouseDown and OnMouseUp events of the button and not use the KSPEvent code itself.

So you'd have an empty game event, then in Start() hook into OnMouseDown and OnMouseUp.

I assume these events exist, they did in the old EzGUI system and are pretty typical, but I have no clue what they'd actually be called to find them.

Well, just the OnMouseUp event, the KSPEvent code is the OnMouseDown event I believe.

 

D.

Not really important, I updated the Flag Rotate mod, right now the flag rotates in 5 degree increments, I was hoping to have it a smooth rotation, but not spending a lot of time on it

Thanks

Share this post


Link to post
Share on other sites

How does one trigger a quickload? I looked at QuickSaveLoad, but that has only QuickSave().

Share this post


Link to post
Share on other sites

Hello, I've been trying to add science data to the RnD archives for a couple of days now and I can't find the answer. I'm in a bit of a unique situation right now as I am working on Syncrio (a multiplayer extension mod). To be precise I'm trying to get a science archive from one client to another. I'm using the game event "OnScienceRecieved" to get the data on one client and "ResearchAndDevelopment.Instance.SubmitScienceData(dataAmount, subject)" to input it in the other client, but all I get on the 2nd client is "[Research & Development]: +5 data on Crew Report from LaunchPad. Subject value is 0.00" in KSP's debug log, it does not register the data in the RnD archives, meaning the same data can be gathered on the client1 and then gathered again on client2. Oddly enough, on the client that gathers the data they get this message "[Research & Development]: +5 data on Crew Report from LaunchPad. 2 Science added. Subject value is 0.00" the difference being the "2 Science added." part. I've read forum after forum looking for the answer and I've had no luck. Even the KSP API did not help much. I'm ether missing the obvious, or it just can't be done... Any help anyone can give will be greatly appreciated.

Edited by Caylis1397

Share this post


Link to post
Share on other sites

I'm playing around with VesselModules for the first time and I have some questions about how they work in the editor and in flight. I see in the API that you can set Activation.NonFlightScenes, this would make it run in the editor, right? Is there any way I can then save information in the craft file to be loaded when the vessel gets sent to the flight scene? Does VesselModule.OnSave() work like that in the editor?

Thanks!

Share this post


Link to post
Share on other sites

Okay, new question: How do I create a physics connection akin to those made by attachment nodes? Note that I'm not trying to attach the two parts in the parts tree sense, I just want a physics joint between them with the same properties as an attachment node would have.

I went through the Kerbal Joint Reinforcement code and implemented their StrutConnectParts() method from KJRDecouplerReinforcementModule.cs, but it seems to have no effect. I see something that looks close-ish to what I want in KJRManager.cs in UpdatePartJoint(), but it looks like it goes above and beyond what I need and I can't quite figure out which parts I need or don't need. Anyone have some insight they can share? Maybe @ferram4?

Share this post


Link to post
Share on other sites

On the VesselModule, I wouldn't expect it to function in the editor, rather I'd expect that .NonFlightScenes flag to control whether it runs in other scenes where time passes, such as the main KSC view or the tracking station.

Have not tested that, but with what I know of how the editor works, I'm not sure how a VesselModule would work correctly....

So I would not expect VesselModule.OnSave() to do anything (as I don't think it runs) in the editor.

Can't help on the physics connection question, never touched that myself.

D.

Share this post


Link to post
Share on other sites

I have a question about the mission notes in custom missions.

I have had a look at this excellent thread:

My (one and only) contract parameter has this code:

cp.GetNotes () = "Param Notes."

The benefit is that the note show in flight:

C60-ParamNotes.jpg

The contract itself has this code:

c.GetNotes () = "Mission Notes."

But somehow both set of notes show up in the contract notes in the Mission Control building:

C60-Objectives.jpg

Do you know why that is happening, or if there is a trick to avoid it?

Share this post


Link to post
Share on other sites

Posted (edited)

Can I destroy buildings in the KSC with plugin? If not, do they need to be in load range so that I can destroy them more...kinetically (via whack-a-kerb)?

Edited by 0111narwhalz

Share this post


Link to post
Share on other sites

Does anyone know how to get SOI and altitude (or at least situation) of an unloaded kerbal? I have the name and the ProtoCrewMember object, but I can't access a corresponding Vessel object (it is destroyed when unloading the vessel/exiting the scene).

Share this post


Link to post
Share on other sites
14 minutes ago, garwel said:

Does anyone know how to get SOI and altitude (or at least situation) of an unloaded kerbal? I have the name and the ProtoCrewMember object, but I can't access a corresponding Vessel object (it is destroyed when unloading the vessel/exiting the scene).

Would finding it in FlightGlobals.Vessels work?

Share this post


Link to post
Share on other sites
10 minutes ago, HebaruSan said:

Would finding it in FlightGlobals.Vessels work?

Hmm, I somehow never used it. Will try it, thanks!

Share this post


Link to post
Share on other sites

How do you reliably run code at game start?

Trying the KSPAddon startup attributes and [RuntimeInitializeOnLoadMethodAttribute] on a static function yields no joy. I'm trying to run some code to change some hardcoded values in the game for myself.

Share this post


Link to post
Share on other sites
4 minutes ago, CrayzeeMonkey said:

How do you reliably run code at game start?

Trying the KSPAddon startup attributes and [RuntimeInitializeOnLoadMethodAttribute] on a static function yields no joy. I'm trying to run some code to change some hardcoded values in the game for myself.

The earlier you can do is a KSPAddon set to immediate and the call you want in Awake. (static is a really bad idea if you use any Unity method)

Share this post


Link to post
Share on other sites

I am attempting to write an extremely simple plugin to allow me to extract some information about the physical and orbital parameters of the stock celestial bodies. I am having some accuracy issues with a tool I created, and suspect the root of the problem might be that my raw data (taken from the wiki) is just slightly off.

What I hoped to do was simply fetch the data I needed (eg, Pe and Ap radius, orbital eccentricity, inclination, etc.) and print it to the debug menu/output log. From there I would just copy it out and process it manually.

Using the "Getting Started" thread, I've been able to put together a tiny "Hello World" add-on that starts when I enter the Tracking Station (:D). But I'm not sure where to go from there. I have no C# or Unity background, though I do have some experience with scripting and the like. Can someone provide some examples on how I can retrieve the information I'm after? I've found some instance fields and instance properties in the Orbit class that look like what I'm after, but I'm unsure of the *ahem* syntax *cough* that I need to use to fetch them.

Thanks for any guidance!

 

Share this post


Link to post
Share on other sites
1 hour ago, Syntax said:

Using the "Getting Started" thread, I've been able to put together a tiny "Hello World" add-on that starts when I enter the Tracking Station (:D). But I'm not sure where to go from there. I have no C# or Unity background, though I do have some experience with scripting and the like. Can someone provide some examples on how I can retrieve the information I'm after? I've found some instance fields and instance properties in the Orbit class that look like what I'm after, but I'm unsure of the *ahem* syntax *cough* that I need to use to fetch them.

If you want to print information about the currently focused body in the tracking station, you can listen for an event that will fire to notify you when it changes:

If you just want to loop over all the bodies, try FlightGlobals.bodies:

1 person likes this

Share this post


Link to post
Share on other sites

Hi everyone, I've been playing around with VSR and @Nertea's Cryogenic tanks. In VSR there's a new cryogenic tank called CryoX which does NOT have zero boiloff function. I've found a plugin written by @Bluebottle that provides this. However, being OCD myself I found that in the CryoX series the cost of the XXL version is incorrect. I've tried changing this by modifying the config file. However, whenever I change this number the part does not load in game. Am I missing anything? The codes are below:

This is the modified version. I only changed the line which said "cost = 6400" to "cost = 16000"

Spoiler

��PART

{

name = CryoXBig

module = Part

author = Ven



MODEL {

        model = VenStockRevamp/Part Bin/NewParts/CryoTanks/CryoBig

    }

rescaleFactor = 1



node_stack_top = 0.0, 4.304316, 0.0, 0.0, 1.0, 0.0, 2

node_stack_bottom = 0.0, -5.099721, 0.0, 0.0, -1.0, 0.0, 2

node_attach = 1.25, 0.0, 0.0, 1.0, 0.0, 0.0, 1



TechRequired = heavierRocketry

entryCost = 15250

cost = 16000

category = Propulsion

subcategory = 0

title = CryoX XXL Fuel tank

manufacturer = Kool Kerbal Products Inc.

description = The first ever product line from Kool Kerbal Products Inc, the CryoX series is mostly guaranteed to keep your cryogenic fuels chilled until the end of time.



attachRules = 1,1,1,1,0



mass = 3.6

dragModelType = default

maximum_drag = 0.2

minimum_drag = 0.3

angularDrag = 2

crashTolerance = 5

breakingForce = 200

breakingTorque = 200

maxTemp = 2000

bulkheadProfiles = size2, srf

tags = fueltank ?lfo liquid oxidizer propellant rocket (ven (vsr light

RESOURCE

{

 name = LiquidFuel

 amount = 3600

 maxAmount = 3600

}



RESOURCE

{

 name = Oxidizer

 amount = 4400

 maxAmount = 4400

}

}

 

 

 

This is the modification code by bluebottle. I haven't modified this:

Spoiler

// Patch to add zero-boil-off functionality to Ven's orange cryogenic tanks (the CryoX series). IFS only.

// ZBO tanks modified from Nertea's original (CryoTanks/CryoEngines v0.2.0)
// Not pretty because all the logic and constants are duplicated and will drift out of sync over time.

// LH2 resource levels are the default IFS-provided values.
@PART[CryoXsmall]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	RESOURCE
	{
		name=LqdHydrogen
		amount=24000
		maxAmount=24000
	}
}

@PART[CryoXmed]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	RESOURCE
	{
		name=LqdHydrogen
		amount=48000
		maxAmount=48000
	}
}

@PART[CryoXBig]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	RESOURCE
	{
		name=LqdHydrogen
		amount=80000
		maxAmount=80000
	}
}

@PART[CryoXnoseCone]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	RESOURCE
	{
		name=LqdHydrogen
		amount=11910
		maxAmount=11910
	}
}

@PART[CryoXendButt]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	RESOURCE
	{
		name=LqdHydrogen
		amount=9420
		maxAmount=9420
	}
}

@PART[CryoXsmall|CryoXmed|CryoXBig|CryoXnoseCone|CryoXendButt]:NEEDS[!modularFuelTanks&!RealFuels]:NEEDS[CryoTanks]:AFTER[CryoTanks]:AFTER[VenStockRevamp]
{
	// Remove standard resources
	!RESOURCE[LiquidFuel] {}
	!RESOURCE[Oxidizer] {}
	// Remove Nertea-added IFS and MCT
	!MODULE[InterstellarFuelSwitch] {}
	!MODULE[ModuleCryoTank] {}
	// No modifications to Nertea's patch after this line

	%LH2ConversionFactor = 10 // <- EDIT HERE (LH2 vs LF/OX capacity conversion; should be identical to LH2ConversionFactor for lifting tanks above)
	%LH2OUnitRatio = 15 // <- EDIT HERE (LH2:OX unit ratio; should be identical to LH2OUnitRatio for lifting tanks above)
	%mixOXProportion = 0.4 // <- EDIT HERE (proportion of tank volume containing OX; should be identical to mixOXProportion for lifting tanks above)
	%dryMassPerUnitLH2 = 0.00003125 // <- EDIT HERE (dry mass per unit LH2 capacity)

	%LH2 = #$RESOURCE[LqdHydrogen]/maxAmount$

	%mixOX = #$LH2$
	@mixOX /= #$LH2ConversionFactor$
	@mixOX *= #$mixOXProportion$
	%mixLH2 = #$mixOX$
	@mixLH2 *= #$LH2OUnitRatio$

	// masses
	%mixLH2mass = #$mixOX$
	@mixLH2mass *= 0.000625
	%tempVar = #$mixLH2$
	@tempVar *= #$dryMassPerUnitLH2$
	@mixLH2mass += #$tempVar$

	// costs
	%LH2cost = #$cost$
	@LH2cost *= 0.5
	@tempVar = #$LH2$
	@tempVar /= #$LH2ConversionFactor$
	@tempVar *= 0.459
	@LH2cost += #$tempVar$
	@cost -= #$LH2cost$

	%mixLH2cost = #$LH2cost$
	@tempVar = 1
	@tempVar -= #$mixOXProportion$
	@mixLH2cost *= #$tempVar$
	@tempVar = #$mixOX$
	@tempVar *= 0.18
	@mixLH2cost += #$tempVar$

	!RESOURCE[LqdHydrogen] {}

	MODULE
	{
		name = InterstellarFuelSwitch

		volumeMultiplier = 1
		massMultiplier = 1

		resourceGui = LH2;LH2/OX
		resourceNames = LqdHydrogen;LqdHydrogen,Oxidizer

		resourceAmounts = #$../LH2$;$../mixLH2$,$../mixOX$

		displayCurrentTankCost = true

		hasGUI = true
		showInfo = true

		availableInFlight = false
		availableInEditor = true

		basePartMass = 0
		tankMass = #$../mass$;$../mixLH2mass$
		tankCost = #$../LH2cost$;$../mixLH2cost$
	}
	MODULE
	{
		name =  ModuleCryoTank
		FuelName = LqdHydrogen
		// in % per hour
		BoiloffRate = 0.05
		// in Ec per 1000 units per second
		CoolingCost = 0.10
	}
}

 

 

 

Share this post


Link to post
Share on other sites
On 4/12/2017 at 5:28 PM, HebaruSan said:

If you want to print information about the currently focused body in the tracking station, you can listen for an event that will fire to notify you when it changes:

If you just want to loop over all the bodies, try FlightGlobals.bodies:

Thanks! Got it!

Here's my code. I  guess I could have done a direct write to file, but I just copypasted from the output_log and used notedpad++ to remove any extraneous lines. Didn't end up using FlightGlobals.

using UnityEngine;

namespace ParamExtract
{
    [KSPAddon(KSPAddon.Startup.TrackingStation, false)]
    public class ParamExtract : MonoBehaviour
    {
        public void Start()
        {
            // fires when focus changed in tracking station
            GameEvents.onPlanetariumTargetChanged.Add(TrackingStationTargetChanged);
        }

        // React to tracking station focus changing
        private void TrackingStationTargetChanged(MapObject target)
        {
            Debug.Log("Name: " + target.name);
            Debug.Log("Radius: " + target.celestialBody.Radius);
            Debug.Log("SMA: " + target.orbit.semiMajorAxis);
            Debug.Log("Eccentricity: " + target.orbit.eccentricity);
            Debug.Log("Inclination: " + target.orbit.inclination);
            Debug.Log("LAN: " + target.orbit.LAN);
            Debug.Log("APe: " + target.orbit.argumentOfPeriapsis);
            Debug.Log("Period: " + target.orbit.period);
            Debug.Log("Mean Motion: " + target.orbit.meanMotion);
            Debug.Log("Pe Radius: " + target.orbit.PeR);
            Debug.Log("Ap Radius: " + target.orbit.ApR);
            Debug.Log("Epoch: " + target.orbit.epoch);
            Debug.Log("MNA at UT=0: " + target.orbit.meanAnomalyAtEpoch);
            Debug.Log("SOI Radius: " + target.celestialBody.sphereOfInfluence);
            Debug.Log("Atmo Alt: " + target.celestialBody.atmosphereDepth);
        }
    }
}

 

Share this post


Link to post
Share on other sites

@MaxZhaoI notice two odd characters just before PART in your post of the file where you changed the cost - if this is in the actual file it could cause this issue. Did your text editor add some extra characters? maybe it didn't save in a basic ASCII format? This would be the only thing I can think of.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now