Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Ok and now another one. (Maybe I should open my own thread here.)

In the editor I add a custom PartModule to every part which can be crewed. That works like it should. The part module has a slider control which you can change via the context menu. For reasons I don't know about, the PartModules OnUpdate() method isn't called so it can't react on the changed settings.

Did I miss something? Or aren't the PartModule's OnUpdate() methods supposed to be called in the editor?

Comparing to other mods I don't do something different.

Link to comment
Share on other sites

Hi

i'm writting a plugin, and my biggest problem is all my images are blurred !!

I use texture2D, with good resolution. I have the same problem for the main logo, in the application launcher button

code:

private WWW imgGM = new WWW("file://"+root+"Plugins/Textures/gm.png");

public static Texture2D buttonGM = newTexture2D(24,24);

(its the same with other size)

and in my awake() method:

imgGM.LoadImageIntoTexture(buttonGM);

hum test with a existing logo(mechjeb2), with texture2d 24*24, and he is blurred too :(

blurred_image.jpg

if someone can help me ??

thx

Edited by Zetla
add screenshot
Link to comment
Share on other sites

I believe that's because you have texture downsizing set in KSP settings. If you set texture resolution to full, it should appear as expected.

EDIT: *facepalm* Didn't even check the image size... */facepalm*

Edited by Crzyrndm
Link to comment
Share on other sites

Thx for repply :)

when i use mechjeb, he appear as normal, and run too with other mod

the problem appear when i make my own plugin

see in the left, mechjeb logo, used by mechjeb, and in the right, my own plugin with the mechjeb logo (for test)

blurred_image.jpg

i take the same image file, so i don't understand....

Link to comment
Share on other sites

Hi

i'm writting a plugin, and my biggest problem is all my images are blurred !!

I use texture2D, with good resolution. I have the same problem for the main logo, in the application launcher button

code:

private WWW imgGM = new WWW("file://"+root+"Plugins/Textures/gm.png");

public static Texture2D buttonGM = newTexture2D(24,24);

(its the same with other size)

and in my awake() method:

imgGM.LoadImageIntoTexture(buttonGM);

hum test with a existing logo(mechjeb2), with texture2d 24*24, and he is blurred too :(

http://s16.postimg.org/6kztxujs1/blurred_image.jpg

if someone can help me ??

thx

The textures used for the AppLauncher button are 40x40, if you instantiate them into a 24x24 texture, KSP will scale them up and loose resolution. Scale your texture to 40x40 and load them up accordingly and it should make more sense.

Link to comment
Share on other sites

Config nodes, generally no.


const string asstPreset = "PIDPreset"; // this is actually elsewhere so I can use it in multiple locations
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes(asstPreset))

Loops through all nodes of type PIDPreset (snippet from Pilot Assistant) found inside GameData

Link to comment
Share on other sites

snippet from KER FlightEngineer.cs

[COLOR=#333333][FONT=Consolas]ScienceUtil.GetExperimentBiome(vessel.mainBody, lat, long)[/FONT][/COLOR]

I'm assuming that's a KSP class since I can't check right now and I couldn't find a ScienceUtil class in KER

Link to comment
Share on other sites

Thanks.

Another one, I am creating contracts that involve landing at a specific biome.

Some biomes are much harder than others e.g. landing on the munar highlands is a lot easier than hitting the canyons. Is there already a representation of the difficulty of each biome or am I going to have to go through each every biome and put them in a config file?

In fact just getting a list of the existing biomes out of the engine would be useful.

Link to comment
Share on other sites

I am trying to write my first plugin, but am running up against a wall. I would like to resize a part via right-click, for example to shrink parts of a ship while in-flight. I tried modifying the Mesh vertices and updating the bounds, I tried modifying the collider's bounds.size directly, changing scaleFactor and rescaleFactor, but none if it seems to achieve what I want. Changing the vertices worked, but the other parts attached to the resized part remained where they used to be, still connected to the previous location, without updating to reflect the new visual size of the object. Am I missing something obvious? Can someone point me in the right direction? I've looked at some existing mods (infernal robotics, b9) but can't find the relevant part of the code. Thanks!

Link to comment
Share on other sites

Attach nodes are defined seperately to geometry. You probably need to alter their position when you do the resizing.


// Semi-psuedo code. Not at dev PC
foreach (AttchNode AN in APart.AttachNodes)
{
AN.position *= rescaleFactor;
}

Link to comment
Share on other sites

And even then, IIRC that won't move anything already attached to them; you'll need to move the attached parts yourself.

Thinking about it a little more, even if they did stick to the shifted node, you'd still have to move it yourself otherwise things will break/explode due to joints trying to snap into place.

Link to comment
Share on other sites

Thanks for the info guys!

Thinking about it a little more, even if they did stick to the shifted node, you'd still have to move it yourself otherwise things will break/explode due to joints trying to snap into place.

Can you point me at where that's best done? I've tried messing with a child-part's transform.position and it seemed to do nothing, same with offset. Is it .attPos?

Edit: It actually is transform.position. No idea what I was doing wrong before, but I tried it again now and it works.

Edited by Koobze
Link to comment
Share on other sites

Is this going in the right direction for loading configs?


public void GeneratePages()
{
foreach(ConfigNode node in GameDatabase.Instance.GetConfigNodes("WIKI"))
{
string type = node.GetValue("type");
switch (type)
{
case "celestial":
break;
case "part":
break;
case "default":
break;
case "info":
break;
default:
goto case "default";
break;
}

}
}

Edited by Robotengineer
formatting.
Link to comment
Share on other sites

While I have never seen the GameDatabase.Instance.GetConfigNodes("WIKI") method before, what comes after that looks correct.

It will load the value in the 'type' key of each node and then compare it in your switch statement.

D.

Link to comment
Share on other sites

While I have never seen the GameDatabase.Instance.GetConfigNodes("WIKI") method before, what comes after that looks correct.

It will load the value in the 'type' key of each node and then compare it in your switch statement.

D.

That's what I want it to do, thanks! It's for loading the pages of an upcoming plugin.

Link to comment
Share on other sites

I have a question regarding best practice on making a mod support other mods without including 3rd party DLLs - which I do not want to do because of common sense and I can not do due to licensing.

The following code is a method that helps me determine if a part is an intake, an airbreatherengine or both in case of modded engines. PartType is an enum that helps me processing all this.

How could I make this support for example Karbonite or Interstellar? Folks have asked for it in the Intake Build Aid dev thread and I would like to support it if possible.

My idea was to create resource-sets, one for the stock stuff and one for each modded resources and handle them independently. I'm stuck on how to implement this without the dependencies to the types. A search for these in the KSP directory would be possible, but then I would need to adjust the mod for each dependency changes. It would be better to be able to handle this in a generic way maybe via reflections.

private PartType GetPartType( Part part )
{
// find engines by ModuleEngines and ModuleEnginesFX module with intakeair propellant
// this is for modded engines that are both intakes and engines in one part
if ( ( ( part.Modules.OfType<ModuleEnginesFX>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" ) ) )
|| ( part.Modules.OfType<ModuleEngines>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" ) ) ) )
&& ( part.Modules.OfType<ModuleResourceIntake>() != null
&& part.Modules.OfType<ModuleResourceIntake>().Any( x => x.resourceName == "IntakeAir" ) )
)
{
return PartType.IntakeAndEngine;
}
// find engines by ModuleEngines and ModuleEnginesFX module with intakeair propellant
else if ( ( part.Modules.OfType<ModuleEnginesFX>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" ) ) )
|| ( part.Modules.OfType<ModuleEngines>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" ) ) )
)
{
return PartType.AirBreatherEngine;
}
// find intakes by resource intakeair
else if ( part.Modules.OfType<ModuleResourceIntake>() != null
&& part.Modules.OfType<ModuleResourceIntake>().Count() > 0
&& part.Modules.OfType<ModuleResourceIntake>().Any( x => x.resourceName == "IntakeAir" )
)
{
return PartType.Intake;
}
else
{
return PartType.SomethingElse;
}
}

So in the end I would need to get the correct ModuleEngine and ModuleResourceIntake types and the resource names from the mods.

From what I've seen with a quick look at Karbonite, it uses ModuleResourceIntake with resource name "IntakeAtm".

So, how to get all this under the hood?

Cheers,

Fjord

Link to comment
Share on other sites

if ((( part.Modules.OfType<ModuleEnginesFX>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" [COLOR=#ff0000]|| y.name == "IntakeAtm"[/COLOR])))
|| (part.Modules.OfType<ModuleEngines>().Any( x => x.propellants.Any( y => y.name == "IntakeAir" [COLOR=#FF0000]|| y.name == "IntakeAtm"[/COLOR]))
...

If all you need to check against is more resource options, just add more options. No need for any reflection or dependencies (it doesn't matter if there is no resource called IntakeAtm to your function, .Any will just return false if it can't find a match)

The issue would be if they aren't using the stock modules


// find intakes by resource intakeair
else if ([COLOR=#ff0000]part.Modules.OfType<ModuleResourceIntake>() != null[/COLOR]
[COLOR=#FF0000] && part.Modules.OfType<ModuleResourceIntake>().Count() > 0[/COLOR]
&& part.Modules.OfType<ModuleResourceIntake>().Any( x => x.resourceName == "IntakeAir"))
{
return PartType.Intake;
}

Why all these checks? .Count > 0 definitely isn't needed (.Any() has that covered) and .OfType<> won't be returning an unintialised list...

Edited by Crzyrndm
Link to comment
Share on other sites

Thanks for the quick reply. I already removed those checks, thanks for pointing that out (the first two queries didnt have them anymore, missed the last one).

My problem is: what if the other mods do not use the ModuleReourceIntake or ModuleEngine types?

From an interstellar intake's config:


MODULE
{
name = AtmosphericIntake
area = 0.04
}
RESOURCE
{
name = IntakeAtm
amount = 1
maxAmount = 1
}

AtmosphericIntake is a custom resource type or am I wrong with it?

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