BlackNecro Posted June 5, 2013 Share Posted June 5, 2013 Have you tried EditorPartList.Instance.limitedParts?Sadly no luck with that one either, that list is empty all the times. Both with all parts filtered out and without any parts filtered out. Quote Link to comment Share on other sites More sharing options...
Mr Shifty Posted June 6, 2013 Share Posted June 6, 2013 Sadly no luck with that one either, that list is empty all the times. Both with all parts filtered out and without any parts filtered out.Did you try PartLoader.LoadedPartsList? I can attest to that one being filled with every available part, and though I've only looked at the name and category fields, I suspect they're all filled. Quote Link to comment Share on other sites More sharing options...
BlackNecro Posted June 6, 2013 Share Posted June 6, 2013 Did you try PartLoader.LoadedPartsList? I can attest to that one being filled with every available part, and though I've only looked at the name and category fields, I suspect they're all filled.Yes checked those - none of those fields are filled except for the name and the category. Quote Link to comment Share on other sites More sharing options...
Mr Shifty Posted June 6, 2013 Share Posted June 6, 2013 Yes checked those - none of those fields are filled except for the name and the category.Well that's unfortunate. Quote Link to comment Share on other sites More sharing options...
nyrath Posted June 10, 2013 Share Posted June 10, 2013 (edited) Stupid newbie here again with another silly question.Is is possible to dynamically add [KSPEvent] attributes and functions at runtime?I have searched the forum, but I can find no clear solution.The problem: My OrionEngine part does not use the resource system (for complicated reasons I won't go into now. Suffice it to say that discrete nuclear bombs do not act like liquid rocket fuel). Instead, it uses OrionMagazines for fuel. These magazines come in various strengths, all are OrionMagazine modules but the bomb strength is set by the parts.cfg. When you right-click on the Orion engine, a pop up menu appears. In the menu you can turn on and off the various magazine types. So if you want a fast lift-off, you turn on the 400 megaNewton bomb magazines, and turn off the 0.88MN, 3.5MN, and 10MN. Then all the 400MN magazines currently attached will feed the engine. All of this works fine.What is not fine is that the [KSPEvent] functions are hard coded in the OrionEngine code. This makes it impossible for a user to create their own OrionMagazine by editing a part.cfg file. They can create the magazine, but it will not appear on the OrionEngine pop-up menu. Not unless they are willing to edit the code and recompile the plugin.What I want is for the the OrionEngine to find all the part types of Class OrionMagazine at run-time, and dynamically create [KSPEvent] menu entries. I managed to get the PartLoader to spit out a list of the OrionMagazines, but I'm not sure how to proceed from there.My fall-back position is to hard code ten or fifteen generic [KSPEvent] in OrionEngine and make them data driven. And hope the user does not try to add more magazine types than the number of generic slots I've supplied. Edited June 11, 2013 by nyrath Quote Link to comment Share on other sites More sharing options...
Mr Shifty Posted June 10, 2013 Share Posted June 10, 2013 Curious whether there's a list anywhere of the types that a PluginConfiguration will serialize. I know it works for value types and some non-value types (e.g. Vector3), but my custom classes wouldn't serialize. Quote Link to comment Share on other sites More sharing options...
DrDima Posted June 11, 2013 Share Posted June 11, 2013 So I've been trying to modify a part's material at runtime. Unsuccessfully.I tried things like this:using System;using UnityEngine;using System.Collections.Generic;namespace KSPTestMod{ public class TestMod : Part { protected override void onEditorUpdate() { if(Input.GetKeyDown("space")){ renderer.material.color = Color.black; } base.onEditorUpdate(); } }}It gives me a Nullreference exception in the debug. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted June 11, 2013 Share Posted June 11, 2013 Is is possible to dynamically add [KSPEvent] attributes and functions at runtime?Adding them should be easy enough, this.Events.Add(new BaseEvent()). The trick would be getting unique behaviour out of them when event functions aren't called with any arguments you can check to determine the name of the calling event.One alternative is to write a PartModule that handles the event and add that instead (part.AddModule), as the adding function returns a reference you can then set which fuel container it should apply to.Curious whether there's a list anywhere of the types that a PluginConfiguration will serialize. I know it works for value types and some non-value types (e.g. Vector3), but my custom classes wouldn't serialize.If it's the same as the persistence file then it would be: string, bool, int, float, Vector2, Vector3, Vector4 or Quaternion and anything that implements iConfigNode.It gives me a Nullreference exception in the debug.There's no renderer attached to the GameObject that your part-derived class (a component) is attached to, so renderer will return null. You need to grab the renderers from the child objects of the parts of the model that have meshes. You could use FindModelTransform(s) if you know what they're called or FindModelComponent(s) to grab all mesh renderers on the model. Quote Link to comment Share on other sites More sharing options...
DrDima Posted June 11, 2013 Share Posted June 11, 2013 There's no renderer attached to the GameObject that your part-derived class (a component) is attached to, so renderer will return null. You need to grab the renderers from the child objects of the parts of the model that have meshes. You could use FindModelTransform(s) if you know what they're called or FindModelComponent(s) to grab all mesh renderers on the model.OHMYGOD thank you so much!!Finally I got it working. using System;using UnityEngine;using System.Collections.Generic;namespace KSPTestMod{ public class TestMod : Part { protected override void onEditorUpdate() { PDebug.Log(name); if(Input.GetKeyDown("space")){ Renderer[] r = this.FindModelComponents<Renderer>(); PDebug.Log(r.Length); for(int i = 0; i < r.Length; i++){ r[i].material.mainTexture = null; r[i].material.color = Color.black; } } base.onEditorUpdate(); } }}The problem I'm facing now is that it resets the renderer's color and texture upon launch. If someone could explain to me why that is I'd be extremely grateful. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted June 11, 2013 Share Posted June 11, 2013 The problem I'm facing now is that it resets the renderer's color and texture upon launch. If someone could explain to me why that is I'd be extremely grateful.The model is reloaded on each new scene, onEditorUpdate presumably only gets called in the editor so you'll need to call the code in another function that runs in the flight scene if you want to do it there (or save and reapply).I'd consider grabbing just MeshRenderer components rather than all renderers as it's also used for things like LineRenderers and particle effects. Also, it's worth considering if you really need to extend Part. There are callbacks on Part and GameEvents that allow you to create functions that only run in the editor in a PartModule derived class. Quote Link to comment Share on other sites More sharing options...
DrDima Posted June 11, 2013 Share Posted June 11, 2013 Also, it's worth considering if you really need to extend Part. There are callbacks on Part and GameEvents that allow you to create functions that only run in the editor in a PartModule derived class.So what you mean is that I could extend the partmodule class and have the same functionality?I'm very new to unity and C# btw, so sorry if I'm asking obvious questions. Quote Link to comment Share on other sites More sharing options...
nyrath Posted June 11, 2013 Share Posted June 11, 2013 Adding them should be easy enough, this.Events.Add(new BaseEvent()). The trick would be getting unique behaviour out of them when event functions aren't called with any arguments you can check to determine the name of the calling event.One alternative is to write a PartModule that handles the event and add that instead (part.AddModule), as the adding function returns a reference you can then set which fuel container it should apply to.Thanks! I'll give those a try. Quote Link to comment Share on other sites More sharing options...
ChronicSilence Posted June 11, 2013 Share Posted June 11, 2013 I would like to know where the debug menu settings are stored. For example, if "gravity hack" is done on a flight, quicksaved, then reloaded, the gravity has returned in full force. This must mean that the "no gravity" setting is not stored in the save file, so is it written somewhere in a file at all or only stored in memory?If the latter, then is it accessible through the API somehow? (i.e. could a plugin detect that it has been enabled)The same question goes for the other settings as well, like infinite fuel.Thanks! Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted June 12, 2013 Share Posted June 12, 2013 The same questionhttp://forum.kerbalspaceprogram.com/showthread.php/35336-Question-about-the-debug-menuSo what you mean is that I could extend the partmodule class and have the same functionality?I don't know the full extent of what you're doing but yes, you can almost always get the same functionality with PartModule. Quote Link to comment Share on other sites More sharing options...
DrDima Posted June 12, 2013 Share Posted June 12, 2013 I don't know the full extent of what you're doing but yes, you can almost always get the same functionality with PartModule.Thanks, I haven't made up my mind yet as to what I want to make. I'll see when my exams are over. Maybe a docking port that discriminates rotation for people with OCD like me. Quote Link to comment Share on other sites More sharing options...
Zyrac Posted June 14, 2013 Share Posted June 14, 2013 Hey people, I'm wondering if anyone can help me out. I'm trying to develop a plugin for a part that converts a particular resource into another. I know how to program the part to request a resource, but how can I program it to convert resources? At the moment I've basically got a part that consumes the input resource and continues to produce the output resource even though the input resource has run out. How can I solve this issue?Thanks. Quote Link to comment Share on other sites More sharing options...
udk_lethal_d0se Posted June 14, 2013 Share Posted June 14, 2013 (edited) Hey people, I'm wondering if anyone can help me out. I'm trying to develop a plugin for a part that converts a particular resource into another. I know how to program the part to request a resource, but how can I program it to convert resources? At the moment I've basically got a part that consumes the input resource and continues to produce the output resource even though the input resource has run out. How can I solve this issue?Thanks. Taking a look at the ModuleGenerator class would be a start.As for getting your output to stop, i'd do:if (myInputResource != 0) //If my input amount does not equal zero.{ generateOutputResource(); //Generate my resources.}else{ print("Log: My input has run dry.");}This is just an example of how it can be done. Edited June 14, 2013 by udk_lethal_d0se Quote Link to comment Share on other sites More sharing options...
Zyrac Posted June 14, 2013 Share Posted June 14, 2013 Taking a look at the ModuleGenerator class would be a start.As for getting your output to stop, i'd do:if (myInputResource != 0) //If my input amount does not equal zero.{ generateOutputResource(); //Generate my resources.}else{ print("Log: My input has run dry.");}This is just an example of how it can be done.Thanks so much! Can't believe I didn't think of it myself, it seems so obvious now! Again, thanks! Quote Link to comment Share on other sites More sharing options...
DrDima Posted June 14, 2013 Share Posted June 14, 2013 So I've been looking at the docking node code, but I just can't seem to find where the docking port magnetism is implemented. I'll keep looking, but by any chance, does anyone know where this happens? Quote Link to comment Share on other sites More sharing options...
Ezriilc Posted June 15, 2013 Share Posted June 15, 2013 Anyone know how to access any hud elements? Perhaps changing and/or adding more waypoints in the navigation ball?So, without reading every word of every page of this ungainly thread, has anyone responded to this or have any info on the HUD components and how to work with them? I've not seen any plugins do this, nor anyone discussing it, but I'm still rather new here.I'm planning/hoping to create a Heads-Up Compass, that shows which way the player's view is facing, as opposed to just the vessel's heading. Also, I'd like to be able to modify the existing HUD display components and/or make them individually moveable/zoomable. For instance, moving the gauges to a secondary monitor would be very nice - like good flight sims.I'm an experienced web (PHP/HTML/CSS/JS) programmer, but I'm just now learning C#, so any tips that anyone can offer would be awesome. Quote Link to comment Share on other sites More sharing options...
MoonHeadJohn Posted June 19, 2013 Share Posted June 19, 2013 What exactly would I need to feed into the reqID parameter of the Part.RequestFuel method?Also, is Part.getFuelReqId() no longer available?Been trying to get information from the Community API page but not sure how up to date it is. Quote Link to comment Share on other sites More sharing options...
Kreuzung Posted June 19, 2013 Share Posted June 19, 2013 don't use that anymore, go with RequestResource. Quote Link to comment Share on other sites More sharing options...
MoonHeadJohn Posted June 19, 2013 Share Posted June 19, 2013 don't use that anymore, go with RequestResource.Could do with a bit more information than just not to use it. Is it legacy code or just simply not common practice any more? Quote Link to comment Share on other sites More sharing options...
Kreuzung Posted June 20, 2013 Share Posted June 20, 2013 Well, it's from the time before part resources were implemented, so AFAIK it only consumes fuel from the old fuel tank part type and ignores part resources. Quote Link to comment Share on other sites More sharing options...
MoonHeadJohn Posted June 23, 2013 Share Posted June 23, 2013 I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.