Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

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
Link to comment
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
Link to comment
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)

Link to comment
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.

 

Link to comment
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

Link to comment
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
Link to comment
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!

Link to comment
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?

Link to comment
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.

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
Share on other sites

  • 3 weeks later...

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).

Link to comment
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?

Link to comment
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)

Link to comment
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!

 

Link to comment
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:

Link to comment
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
	}
}

 

 

 

Link to comment
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);
        }
    }
}

 

Link to comment
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.

Link to comment
Share on other sites

9 hours ago, wasml said:

@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.

 

Yeah I did notice it, however, the problem persists even after I've removed the characters. I don't know what those are but they don't appear in any other part cfgs. 

Link to comment
Share on other sites

I'm Having a problem creating my own generator. I want a small generator that can take ore and electricity and turn it into either liquid fuel, oxidiser or mono propellant as well as store the excess. I am new at modding KSP. I have made a model and texture that work but for some reason my code is wrong. Every resource value I enter appears in the game as 0. 

For example:


    MODULE
    {
        name = ModuleResourceConverter
        ConverterName = Mono Propellant
        StartActionName = Start Mono Propellant
        StopActionName = Stop Mono Propellant
        AutoShutdown = false
        GeneratesHeat = false
        UseSpecialistBonus = false
        INPUT_RESOURCE
        {
            ResourceName = ElectricCharge
            Rate = 0.5
        }
        INPUT_RESOURCE
        {
            ResourceName = Ore
            Rate = 0.5
        }
        OUTPUT_RESOURCE
        {
            ResourceName = MonoPropellant
            Rate = 0.95
            DumpExcess = false
        }

Can anyone see a problem? I have tried coping parts of the coding from stock game parts.

Help! Please.

Full Code:

PART
{
    name = FuelGen2
    module = Part
    author = Brahimus
    rescaleFactor = 1
    node_attach = 0, 0, 0, 1, 0, 0, 0
    TechRequired = largeElectrics
    entryCost = 2250
    cost = 750
    category = Utility
    subcategory = 0
    title = Super Ore Converter
    manufacturer = Brahimus Inc.
    description = A small generator that can convert electricity and ore into liquid fuel, mono propellant and oxidizer.
    attachRules = 0,1,0,0,0

    // --- standard part parameters ---
    mass = 0.05
    dragModelType = default
    maximum_drag = 0.2
    minimum_drag = 0.2
    angularDrag = 2
    crashTolerance = 7000
    maxTemp = 7000

    MODEL
    {
        model = Squad/Parts/Utility/FuelCell2/FuelCell
    }
    MODULE
    {
        name = ModuleResourceConverter
        ConverterName = Liquid Fuel
        StartActionName = Create Liquid Fuel
        StopActionName = Stop Liquid Fuel
        AutoShutdown = false
        GeneratesHeat = false
        UseSpecialistBonus = false
    canOverflow = false
     deactivateIfFull = false
    deactivateIfEmpty = false 
        INPUT_RESOURCE
        {
            ResourceName = ElectricCharge
            Rate = 0.5
        }
        INPUT_RESOURCE
        {
            ResourceName = Ore
            Rate = 0.05
        }
        OUTPUT_RESOURCE
        {
            ResourceName = LiquidFuel
            Rate = 0.95
            DumpExcess = false
        }
    }
    MODULE
    {
        name = ModuleResourceConverter
        ConverterName = Oxidizer
        StartActionName = Start Oxidizer
        StopActionName = Stop Oxidizer
        AutoShutdown = false
        GeneratesHeat = false
        UseSpecialistBonus = false
    canOverflow = false
     deactivateIfFull = false
    deactivateIfEmpty = false 
        INPUT_RESOURCE
        {
            ResourceName = ElectricCharge
            Rate = 0.5
        }
        INPUT_RESOURCE
        {
            ResourceName = Ore
            Rate = 0.05
        }
        OUTPUT_RESOURCE
        {
            ResourceName = Oxidizer
            Rate = 0.95
            DumpExcess = false
        }
    }
    MODULE
    {
        name = ModuleResourceConverter
        ConverterName = Mono Propellant
        StartActionName = Start Mono Propellant
        StopActionName = Stop Mono Propellant
        AutoShutdown = false
        GeneratesHeat = false
        UseSpecialistBonus = false
    canOverflow = false
     deactivateIfFull = false
    deactivateIfEmpty = false 
        INPUT_RESOURCE
        {
            ResourceName = ElectricCharge
            Rate = 0.5
        }
        INPUT_RESOURCE
        {
            ResourceName = Ore
            Rate = 0.005
        }
        OUTPUT_RESOURCE
        {
            ResourceName = MonoPropellant
            Rate = 0.95
            DumpExcess = false
        }
    }
    RESOURCE
    {
        name = LiquidFuel
        amount = 100
        maxAmount = 100
    }
    RESOURCE
    {
        name = Oxidizer
        amount = 100
        maxAmount = 100
    }
    RESOURCE
    {
        name = MonoPropellant
        amount = 100
        maxAmount = 100
    }
}
 

Edited by Brahimus
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...