ShotgunNinja Posted April 28, 2017 Share Posted April 28, 2017 @Brahimus In INPUT_RESOURCE / OUTPUT_RESOURCE nodes, replace Rate with Ratio. Quote Link to comment Share on other sites More sharing options...
Booots Posted April 30, 2017 Share Posted April 30, 2017 How does one create an input lock so that I can have the player left-click somewhere on the vessel in the editor but not have the part get picked up off the vessel? I've got it working when CTRL is held down (similarly to UbioZur Welding), but not without a modifier key. Any ideas? Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 8, 2017 Share Posted May 8, 2017 (edited) Hey fellow modders I have been looking at a bit of code, and this is popping out at me: double Ec = GetResourceAmount("ElectricCharge"); double req = part.RequestResource("ElectricCharge", Ec); When the variable req is used, would it automatically request all the electric charge on the vessel? Edited May 8, 2017 by Benjamin Kerman Please quote me so that I know you answered. Thanks! Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 9, 2017 Share Posted May 9, 2017 (edited) No. Once you assign to a variable, it just has that value. If you want that behavior, define a method as such: static double Req() { return part.RequestResource("ElectricCharge", GetResourceAmount("ElectricCharge")); } Edited May 9, 2017 by 0111narwhalz Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 9, 2017 Share Posted May 9, 2017 1 hour ago, 0111narwhalz said: No. Once you assign to a variable, it just has that value. If you want that behavior, define a method as such: static double Req() { return part.RequestResource("ElectricCharge", GetResourceAmount("ElectricCharge")); } So the original bit of code I have, from https://github.com/Darknesshas1/DK-BHTanks/blob/master/src/DK-BHTanks/GameData/BlackHoleTanks/Plugins/BHStorageCfg.cs should work to draw a set amount of charge, as intended? Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 9, 2017 Share Posted May 9, 2017 @Benjamin Kerman Give me a line number, wouldja? Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 9, 2017 Share Posted May 9, 2017 Just now, 0111narwhalz said: @Benjamin Kerman Give me a line number, wouldja? 185, and straight on till morning. Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 9, 2017 Share Posted May 9, 2017 Uh, no. All you're doing by line 203 is saying "Hey! Look at this!" It doesn't re-execute line 192. You can imagine the chaos that might cause. For that, you need a method. Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 9, 2017 Share Posted May 9, 2017 @0111narwhalz How would you do that? I also call on ConsumeCharge elsewhere in the program, in line 150. Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 9, 2017 Share Posted May 9, 2017 @Benjamin Kerman Just do the following in the class: static double Req() { return Part.RequestResource("ElectricCharge", GetResourceAmount("ElectricCharge")); } Then you call Req() to grab all the ElectricCharge. It also returns whatever Part.RequestResource() returns. If you want to get fancy, try: static double Req(string res) { return Part.RequestResource(res, GetResourceAmount(res)); } This will request whatever resource you name in res. Quote Link to comment Share on other sites More sharing options...
sarbian Posted May 9, 2017 Share Posted May 9, 2017 Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 9, 2017 Share Posted May 9, 2017 @0111narwhalz So this, from line 97 to 100, calling on lines 37-38 would properly require "x" amount of charge for lines 191-216? Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 9, 2017 Share Posted May 9, 2017 Should do. Quote Link to comment Share on other sites More sharing options...
Vanamonde Posted May 10, 2017 Share Posted May 10, 2017 Some glitchy posts removed for clarity. Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 10, 2017 Share Posted May 10, 2017 Hey @0111narwhalz if I could bother you (or anyone else ) again... Line 97 has Part.RequestResource(res, 0.0f) This doesn't let me put BHECCost (in line 39) in where the 0.0f is. It throws a CS0120 error. Take a look? Quote Link to comment Share on other sites More sharing options...
0111narwhalz Posted May 10, 2017 Share Posted May 10, 2017 (edited) @Benjamin Kerman Line 39: Add the static tag to BHECCost. You're trying to access a property of an object without an object. For the same reason, Req() has the tag. The only reason Start() (and the other Unity-related methods) doesn't have it is because Unity has this object (it's the GameObject, here a part). Edited May 10, 2017 by 0111narwhalz Quote Link to comment Share on other sites More sharing options...
sarbian Posted May 10, 2017 Share Posted May 10, 2017 Guys, open a thread please. Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 11, 2017 Share Posted May 11, 2017 One last thing, new dev here I successfully compiled the plugin with no errors (Yay!), but am not sure how to add it to the parts. Do I create a module in the cfg file called "ModuleBlackHole", or is there some other way? Thank you for all your help! Quote Link to comment Share on other sites More sharing options...
TheUltimateKerbonaut Posted May 14, 2017 Share Posted May 14, 2017 Hello everyone . I am making my first KSP mod, which simply displays a gui, with a label telling you how much science is stored on a vessel. However, I am stuck on trying to find out how much science is stored in each ModuleScienceContainer or ModuleScienceExperiment. Does someone know how this can be achieved, or is it impossible? Here is my code: using System; using System.Collections.Generic; using UnityEngine; using KspScienceCount.Extensions; using KSP; namespace KspScienceCount { public class ScienceCount : PartModule { private Rect _windowPosition = new Rect(); private GUIStyle _windowStyle, _labelStyle; private bool _hasInitStyles = false; public void OnGUI() { if (!_hasInitStyles) InitStyles(); if (Event.current.type != EventType.Repaint || Event.current.isMouse) { if (this.vessel == FlightGlobals.ActiveVessel && this.part.IsPrimary(this.vessel.parts, this.ClassID)) _windowPosition = GUILayout.Window(10, _windowPosition, OnWindow, "This is a title",_windowStyle); } } private void OnWindow(int windowId) { GUILayout.BeginHorizontal(); GUILayout.Label("Science on this vessel: " + CountScience(), _labelStyle); GUI.DragWindow(); GUILayout.EndHorizontal(); } private void InitStyles() { _windowStyle = new GUIStyle(HighLogic.Skin.window); _windowStyle.fixedWidth = 150f; _labelStyle = new GUIStyle(HighLogic.Skin.label); _labelStyle.stretchWidth = true; _hasInitStyles = true; } private float CountScience() { float count = 0; foreach (Part rocketPart in this.vessel.parts) { foreach (PartModule module in rocketPart.Modules) { if (module.GetComponent<ModuleScienceExperiment>() != null) { for (int i = 0; i == module.GetComponent<ModuleScienceContainer>().GetData().Length - 1; i++) { //count += module.GetComponent<ModuleScienceExperiment>().GetData()[i]. <-- this bit here } } } } return count; } } } Many thanks in advance, TheUltimateKerbonaut Quote Link to comment Share on other sites More sharing options...
ShotgunNinja Posted May 17, 2017 Share Posted May 17, 2017 @TheUltimateKerbonaut Try this: double ScienceValue(string subject_id, float size) { ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(subject_id); if (subject == null) return 0.0f; return ResearchAndDevelopment.GetScienceValue(size, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; } float CountScience(Vessel v) { float credits = 0.0f; foreach(IScienceDataContainer c in v.FindPartModulesImplementing<IScienceDataContainer>()) { foreach(ScienceData sd in c.GetData()) { credits += ScienceValue(sd.subjectID, sd.dataAmount); } } return credits; } Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted May 17, 2017 Share Posted May 17, 2017 I have a KSPField that I'm trying to only have show up in flight, however it seems to also be showing up in the editor, even after setting guiActiveEditor to false. Does guiActive override this? [KSPField(isPersistant = true, guiName = "Current EMR", guiActive = true, guiActiveEditor = false, guiUnits = ":1"), UI_FloatEdit(incrementSmall = 0.1f, incrementLarge = 1.0f, incrementSlide = 0.01f, sigFigs = 2, unit = ":1")] public float currentEMR; Quote Link to comment Share on other sites More sharing options...
blowfish Posted May 17, 2017 Share Posted May 17, 2017 15 minutes ago, rsparkyc said: I have a KSPField that I'm trying to only have show up in flight, however it seems to also be showing up in the editor, even after setting guiActiveEditor to false. Does guiActive override this? [KSPField(isPersistant = true, guiName = "Current EMR", guiActive = true, guiActiveEditor = false, guiUnits = ":1"), UI_FloatEdit(incrementSmall = 0.1f, incrementLarge = 1.0f, incrementSlide = 0.01f, sigFigs = 2, unit = ":1")] public float currentEMR; You might have to set the scene on the UI_FloatEdit to UI_Scene.Flight Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted May 17, 2017 Share Posted May 17, 2017 3 minutes ago, blowfish said: You might have to set the scene on the UI_FloatEdit to UI_Scene.Flight That was it, thanks! Quote Link to comment Share on other sites More sharing options...
Benjamin Kerman Posted May 18, 2017 Share Posted May 18, 2017 Start() runs on vessel load, correct? Also, anything that is not in a KSPField and not specifically in a saveCfgNode thing gets deleted by KSP? Quote Link to comment Share on other sites More sharing options...
Kobymaru Posted May 20, 2017 Share Posted May 20, 2017 Hi, what exactly is "World Space" and how does it relate to the position vectors in KSP? Specifically, to FlightGlobals.currentMainBody.position and FlightGlobals.ActiveVessel.transform.position ? I'm trying to draw some lines using Vectrosity from a set of coordinates. That worked using the Unity.LineRenderer, but when I try to use the very same coordinates for rendering of Vectrosity.VectorLine, the lines go out straight out of the screen and behave weirdly when rotating the camera. ps.: Is there some sort of "reference frame guide" for KSP? I keep getting confused by World/Body-Relative/Krakensbane/Surface-Relative and all kinds of coordinate systems. 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.