Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Odd, should work since I pulled that code right out of Contract Configurator. If I had to guess I'd say you need to change your settings to compile against .net 3.5

EDIT: Yeah, quick google search seems to imply it's a framework version issue. Compile against 3.5 and you should be golden.

Edited by nightingale
Link to comment
Share on other sites

A small question:

How can I access the functions that are used by the Debug Menu (alt-F12) from a plugin?

To be more specific, I am trying to find "toggle heat overlay display". I want to relocate that handy function to a bound key...

So I can quickly toggle the display with a single keystroke.

Link to comment
Share on other sites

Odd, should work since I pulled that code right out of Contract Configurator. If I had to guess I'd say you need to change your settings to compile against .net 3.5

EDIT: Yeah, quick google search seems to imply it's a framework version issue. Compile against 3.5 and you should be golden.

How do I get 3.5 on a Mac?

Edit: Just tried a different IDE, it has 3.1 or 4.0, which is correct?

Edited by Robotengineer
Link to comment
Share on other sites

4.0 is definitely wrong. 3.1 sounds closer, but now I'm worried you're looking at something else...

From what I've heard, MonoDevelop is the tool of choice for .net work in Mac or Linux. That being said, it's the mono framework that is limited to 3.5 - so if you use MonoDevelop you shouldn't have any issues (not speaking from experience though).

Link to comment
Share on other sites

Would it be possible to make a module to allow multiple control surfaces on a part that work independently? The reason I ask is because I am making a large wing that is mounted on top of a plane with control surfaces on each side as the control surfaces are on opposite sides of the plane they need to work individually but with stock you can only have one control surface. Thanks.

Link to comment
Share on other sites

How do I prevent a variable from being reassigned every time OnGUI runs?

foreach(type t in ContractSystem.ContractTypes)
{
...
x = GUILayout.SelectionGrid(x, ..buttonstuff...)
}

If I assign x outside of the method, all of the buttons change to the same thing, but if I assign it inside the method, it resets itself every time it updates. What should I do?

Link to comment
Share on other sites


var y = x
foreach(type t in ContractSystem.ContractTypes)
{
...
y = GUILayout.SelectionGrid(y, ..buttonstuff...)
}
if (x != y )
x = y

Really fancy, I know

Link to comment
Share on other sites

I am very new to writing plugins and I am trying to make it so that I can control an animation linked to my part. I have spent ages searching through old posts and such but still cant find an answer. Below is my code and I have highlighted the parts where I am trying to control the animation to hopefully make it easier to understand. Thanks


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace BalloonModule
{
public class BalloonModule : PartModule
{
[B][COLOR="#000080"][KSPField(isPersistant = false)]
public string inflateAnimation = "inflate";

public Animation anim;[/COLOR][/B]

[KSPField(isPersistant = false)]
public float burstAtmoPressure = 0;

[KSPField(isPersistant = false)]
public float maxBalloonLift = 0;

public float balloonLift = 0;
public bool isInflated = false;

public override void OnStart(StartState state)
{
Debug.Log("Weather Balloons Mod Loaded!");
[B]anim = this.vessel.GetComponent(inflateAnimation);[/B]
}

public override void OnUpdate()
{
Debug.Log("Balloon Lift: " + balloonLift);
if(isInflated)
{
if (balloonLift < maxBalloonLift)
{
balloonLift += 0.01f * maxBalloonLift;
if (balloonLift > maxBalloonLift - 0.01) balloonLift = maxBalloonLift;
[B][COLOR="#000080"]anim.normalizedTime = (balloonLift/maxBalloonLift)/2;[/COLOR][/B]

}
float pressureCountdown = (float)FlightGlobals.getStaticPressure() - burstAtmoPressure;
[B][COLOR="#000080"]float animTime = 0.5f -(0.005f*pressureCountdown);
anim.normalizedTime = animTime;[/COLOR][/B]


this.rigidbody.AddForce(vessel.upAxis * balloonLift);
if (FlightGlobals.getStaticPressure() <= burstAtmoPressure)
{
Debug.Log("Balloon has Burst!");
balloonLift = balloonLift * 0.2f;
deflateBalloon();
}
}
else if (!isInflated && balloonLift > 0)
{
balloonLift -= 0.01f * maxBalloonLift;
if (balloonLift < 0.01) balloonLift = 0;
}
}

[KSPEvent(active = true, guiActive = true, guiActiveEditor = false, guiActiveUnfocused = false, guiName = "Inflate Balloon")]
public void inflateBalloon()
{
if (FlightGlobals.getStaticPressure() > 0)
{
Debug.Log("Inflating Balloon!");
isInflated = true;
Events["inflateBalloon"].active = false;
Events["deflateBalloon"].active = true;
}
else
{
ScreenMessages.PostScreenMessage("Cannot inflate balloon in vacuum", 3, ScreenMessageStyle.UPPER_CENTER);
}
}

[KSPEvent(active = false, guiActive = true, guiActiveEditor = false, guiActiveUnfocused = false, guiName = "Deflate Balloon")]
public void deflateBalloon()
{
Debug.Log("Deflating Balloon!");
Events["deflateBalloon"].active = false;
isInflated = false;
}
}
}

Link to comment
Share on other sites

Quick question I don't see answered in any of the obvious places:

If I have a company that manufactures my add-on parts, and I want them to have an icon in the editors' parts menu, but I DON'T want them to offer contracts, how can I disable contracts from a particular agency? Or is making an agency the wrong thing to do in the first place?

Link to comment
Share on other sites

The editor will auto generate a category for every different manufacturer listed in the part .cfg's in GameData. No need to list an agency, just make the "manufacturer = " line in your parts the name you want. If you want it to have a proper icon, you'll need a plugin to load it (either your own, or through Filter Extensions)

Edited by Crzyrndm
Link to comment
Share on other sites

Hey all, quick and hopefully simple question;

I'm creating a PartModule, a single class with a field called "Manageable"; in the config file this is set to true, so my module definition looks as described below.


MODULE
{
Name = KSP_Manager
Manageable = true
}

Now, I can loop through the parts and find each one that uses the defined module just fine; but how do I find the part that has "Manageable" set to true? I was under the impression that you'd do something like below.


Part currentPart = (Part)vesselParts[i];

if (bool.Parse(currentPart.Modules["KSP_Manager"].Fields.GetValue("Manageable").ToString()))
{
// Stuff.
}

Any help is much appreciated, thank you.

Link to comment
Share on other sites

IIRC you would need to tag Manageable with [KSPField] and it needs to be public (see this simple example). Alternatively, since you are likely doing this from inside the same plugin, you can cast it to the correct type and access values that way (it still needs to be public)

((KSP_Manager)currentPart.Modules["KSP_Manager"]).Manageable

Link to comment
Share on other sites

IIRC you would need to tag Manageable with [KSPField] and it needs to be public (see this simple example). Alternatively, since you are likely doing this from inside the same plugin, you can cast it to the correct type and access values that way (it still needs to be public)

((KSP_Manager)currentPart.Modules["KSP_Manager"]).Manageable

Thanks for this, works as intended.

Link to comment
Share on other sites

Hi ! I am helping Tabakhase with his mod ProbeControlRoom and we are trying to shut aero/ship sound while in IVA. I figured a way by setting GameSettings.SHIP_VOLUME and GameSettings.AMBIENCE_VOLUME to 0 in the plugin code and restoring them when getting out of IVA.

Before that, we wanted to stop IVA camera wobbles and we succeeded this way (GameSettings.FLT_CAMERA_WOBBLES = 0) but unfortunately it doesn't seem to work as good for sound.

Actually, it would work if it wasn't for a thing : for changes to happen, I have to pause the game and go to in game settings. I don't have to modify anything, I go there, I quit settings, I unpause then sound is as it should be (as I programmed it to be at least).

Surprisingly enough, it doesn't happen for the camera so I'm a bit confused.

So here are my questions :

Is there a way to make the game apply game settings for sure ?

Is there a cleaner way than modifying GameSettings.SHIP_VOLUME and GameSettings.AMBIENCE_VOLUME to shut those two sound groups ?

My modifications to the mod are here : https://github.com/tabakhase/KSP-ProbeControlRoom/pull/2

You'd make my day if you could answer that ! Thanks in advance.

Edited by Dexter9313
Link to comment
Share on other sites

A small question:

How can I access the functions that are used by the Debug Menu (alt-F12) from a plugin?

To be more specific, I am trying to find "toggle heat overlay display". I want to relocate that handy function to a bound key...

So I can quickly toggle the display with a single keystroke.

Squad added exactly what I wanted to do in 1.0.1. :)

Link to comment
Share on other sites

Hey all, me again.

Is it possible to access a modules kspfield value if that module is proto, accessed from a protopart within a protovessel?

If the field is persistent then I think you can access it from protoPartSnapshots.modules.moduleValues (the snapshots and modules are both IEnumerables, so you'll need to sort out which one you want). That gives you a ConfigNode, I think it's the same as what gets added to the save file for each PartModule.

If the field isn't persistent the only way I know of is to get the part's config file through the protoPartSnapshot.partInfo.partConfig, then grab the right value.

This is how I'm handling it:


var scanners = from pref in vessel.protoVessel.protoPartSnapshots
where pref.modules.Any(a => a.moduleName == "ModuleResourceScanner")
select pref;

if (scanners.Count() == 0)
continue;

foreach (var p in scanners)
{
if (p.partInfo == null)
continue;

ConfigNode node = p.partInfo.partConfig;

if (node == null)
continue;

var moduleNodes = from nodes in node.GetNodes("MODULE")
where nodes.GetValue("name") == "ModuleResourceScanner"
select nodes;

foreach (ConfigNode moduleNode in moduleNodes)
{
if (moduleNode == null)
continue;

if (moduleNode.HasValue("MaxAbundanceAltitude"))
{
string alt = moduleNode.GetValue("MaxAbundanceAltitude");

Link to comment
Share on other sites

If the field is persistent then I think you can access it from protoPartSnapshots.modules.moduleValues (the snapshots and modules are both IEnumerables, so you'll need to sort out which one you want). That gives you a ConfigNode, I think it's the same as what gets added to the save file for each PartModule.

If the field isn't persistent the only way I know of is to get the part's config file through the protoPartSnapshot.partInfo.partConfig, then grab the right value.

This is how I'm handling it:


var scanners = from pref in vessel.protoVessel.protoPartSnapshots
where pref.modules.Any(a => a.moduleName == "ModuleResourceScanner")
select pref;

if (scanners.Count() == 0)
continue;

foreach (var p in scanners)
{
if (p.partInfo == null)
continue;

ConfigNode node = p.partInfo.partConfig;

if (node == null)
continue;

var moduleNodes = from nodes in node.GetNodes("MODULE")
where nodes.GetValue("name") == "ModuleResourceScanner"
select nodes;

foreach (ConfigNode moduleNode in moduleNodes)
{
if (moduleNode == null)
continue;

if (moduleNode.HasValue("MaxAbundanceAltitude"))
{
string alt = moduleNode.GetValue("MaxAbundanceAltitude");

Thanks DMagic, I'll give that a try in a bit.

Link to comment
Share on other sites

Hello, I have a quick question:

is it possible to make a vessel uncontrollable in a way that the player can't even switch to it / "fly" it?

I have no idea how it would be done code-wise, but you could set the vessel to be unowned (like asteroids). I think there's a parameter for that in VESSEL{} in persistent.sfs

Link to comment
Share on other sites

Is it possible to load a ConfigNode directly from a string without writing it to a file first?

A ConfigNode can be serialized to a string using the ToString() overload, but I can't seem to find the proper method to reverse that.

The only method I found is ConfigNode.Load(string fullFileName), which reads it back from a file.

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