Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

2 hours ago, AliceTheGorgon said:

I don't suppose there's any simple way to display a message box in the middle of the screen with some text and a close button?

PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Title", "Text", "OK", false, HighLogic.UISkin);

Link to comment
Share on other sites

Has anyone got any idea of how to make a vessel rendezvous with another vessel, and then set the velocity relative to the target at ~50m/s. Rendezvous in kind of like the in-game cheat rendezvous which sets the vessel 150m away from the target.

Help please?

Edited by JuhaJGamer
Link to comment
Share on other sites

On 1/9/2017 at 10:34 AM, JuhaJGamer said:

Has anyone got any idea of how to make a vessel rendezvous with another vessel, and then set the velocity relative to the target at ~50m/s. Rendezvous in kind of like the in-game cheat rendezvous which sets the vessel 150m away from the target.

Now, I don't know much about plugin work (read: I'm a complete neophyte), but it seems like you could do it in two steps:
1. Rendezvous: Either trigger the stock debug tool, or copy the data from one to the other via save-file or vessel data.
2. Velocity: Add a velocity to the vessel. Probably done through the vessel data and some trig.

Link to comment
Share on other sites

2 minutes ago, 0111narwhalz said:

Now, I don't know much about plugin work (read: I'm a complete neophyte), but it seems like you could do it in two steps:
1. Rendezvous: Either trigger the stock debug tool, or copy the data from one to the other via save-file or vessel data.
2. Velocity: Add a velocity to the vessel. Probably done through the vessel data and some trig.

Ok, these are the two methods that I have tried. Directly editing the "quicksave" file takes time. There could be more vessels of the same name. And after that you must load it which may give you a quick fps-spike. The stock debug tool I cant find. Anywhere. No docs, no classes, no functions, It's like it doesn't exist. Velocity, I learned it actually today so that's great 

Link to comment
Share on other sites

4 minutes ago, 0111narwhalz said:

@JuhaJGamer
Some things that might be useful:

Vessel.obt_velocity 
Vessel.SetPosition()
Vessel.GetWorldPos3D()
And the Vector3d and Orbit classes.

Vessel.obt_velocity is of the type Vector3d. for some reason VS2015 wants KSPUtil for this (KSP cant recognise KSPUtil.dll anymore, because it was all moved to Assembly-CSharp.dll)

Link to comment
Share on other sites

Just now, JuhaJGamer said:

Vessel.obt_velocity is of the type Vector3d. for some reason VS2015 wants KSPUtil for this (KSP cant recognise KSPUtil.dll anymore, because it was all moved to Assembly-CSharp.dll)

It was moved back into Assembly-CSharp.  Remove the reference to KSPUtil and make sure your reference to Assembly-CSharp points to an up-to-date DLL

Link to comment
Share on other sites

3 minutes ago, blowfish said:

It was moved back into Assembly-CSharp.  Remove the reference to KSPUtil and make sure your reference to Assembly-CSharp points to an up-to-date DLL

I have the newest version of KSP and its Assembly-CSharp. VS still insists on the KSPUtil refrence

 

http://imgur.com/gallery/GJlMq

 

Edited by JuhaJGamer
Pic
Link to comment
Share on other sites

4 minutes ago, JuhaJGamer said:

I have the newest version of KSP and its Assembly-CSharp. VS still insists on the KSPUtil refrence

Might try quitting and re-starting Visual Studio.  Also verify that when you click on the Assembly-CSharp reference, it actually points to where you think it should (it'll show the path in the bottom right pane)

Link to comment
Share on other sites

1 minute ago, blowfish said:

Might try quitting and re-starting Visual Studio.  Also verify that when you click on the Assembly-CSharp reference, it actually points to where you think it should (it'll show the path in the bottom right pane)

Tried it. It points to "J:\Ohjelmat\Pelit\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll" which is my KSP Install. It is up-to-date(Steam) and rebooting VS didn't really help. 

Link to comment
Share on other sites

4 minutes ago, JuhaJGamer said:

Tried it. It points to "J:\Ohjelmat\Pelit\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll" which is my KSP Install. It is up-to-date(Steam) and rebooting VS didn't really help. 

Okay, maybe try removing the Assembly-CSharp reference and re-adding it.  Also, if you open the .csproj file in a text editor, can you find KSPUtil in it anywhere?

Link to comment
Share on other sites

31 minutes ago, blowfish said:

Okay, maybe try removing the Assembly-CSharp reference and re-adding it.  Also, if you open the .csproj file in a text editor, can you find KSPUtil in it anywhere?

None of this helped, even rebooted my computer(dont know why I did that tbh.)

hello?

Link to comment
Share on other sites

Have you tried right clicking on that dependency and clicking "remove"?

In a separate topic, I'm trying to help upgrade RP-0.  Looks like there was some old code like this:

        protected double ResourceRate()
        {
            if (part.Modules.Contains("ModuleCommand"))
            {
                ModuleCommand mC = (ModuleCommand)part.Modules["ModuleCommand"];
                foreach(ModuleResource r in mC.inputResources)
                {
                    if(r.name.Equals("ElectricCharge"))
                    {
                        commandChargeResource = r;
                        if (enabledkW < 0)
                            enabledkW = (float)r.rate;
                        return r.rate;
                    }
                }
            }
            return -1;
        }

However, ModuleCommand no longer has inputResources.  I can do mC.part.resources, and filter where mC.flowMode is FlowMode.In, but 1) I don't know if that's the right way to do it, and 2) those objects still don't have a rate field.  Suggestions?

Link to comment
Share on other sites

12 hours ago, rsparkyc said:

However, ModuleCommand no longer has inputResources.  I can do mC.part.resources, and filter where mC.flowMode is FlowMode.In, but 1) I don't know if that's the right way to do it, and 2) those objects still don't have a rate field.  Suggestions?

The ModuleCommand has a resHandler of type ModuleResourceHandler. It contains the inputResources.

So :

        protected double ResourceRate()
        {
            ModuleCommand mC = part.FindModuleImplementing<ModuleCommand>()
            if (mC != null)
            {                
                foreach(ModuleResource r in mC.resHandler.inputResources)
                {
                    if(r.id == PartResourceLibrary.ElectricityHashcode)
                    {
                        commandChargeResource = r;
                        if (enabledkW < 0)
                            enabledkW = (float)r.rate;
                        return r.rate;
                    }
                }
            }
            return -1;
        }

 

Link to comment
Share on other sites

 

5 hours ago, sarbian said:

The ModuleCommand has a resHandler of type ModuleResourceHandler. It contains the inputResources.

So :


        protected double ResourceRate()
        {
            ModuleCommand mC = part.FindModuleImplementing<ModuleCommand>()
            if (mC != null)
            {                
                foreach(ModuleResource r in mC.resHandler.inputResources)
                {
                    if(r.id == PartResourceLibrary.ElectricityHashcode)
                    {
                        commandChargeResource = r;
                        if (enabledkW < 0)
                            enabledkW = (float)r.rate;
                        return r.rate;
                    }
                }
            }
            return -1;
        }

 

Gotta love one line changes :)

Link to comment
Share on other sites

Are Bill and Val hardcoded into KSP somewhere? I'm trying to update KerbalRenamer, but get a NRE after I try to update their names:


NullReferenceException: Object reference not set to an instance of an object
  at regexKSP.IconChanger.changeKerbalIcon (KSP.UI.CrewListItem cic) [0x00000] in <filename unknown>:0
  at regexKSP.IconChanger.BuildCrewAssignmentDialogue () [0x00000] in <filename unknown>:0
  at CallbackUtil+<DelayedCallback>c__IteratorEC.MoveNext () [0x00000] in <filename unknown>:0
  at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0

 

You can see what I'm doing here: https://github.com/rsparkyc/KerbalRenamer/blob/JebBillBobValRename/Renamer/Renamer.cs#L137

 

Link to comment
Share on other sites

Hello,

I'm new to ksp modding, but have done quite a lot of personnal mods in other games, in various technical environnements.

A simple question : are there some ground explanations on the principles behind ksp code?

Obviously, in modding there is always some thinking and trial-and-error needed find things out (and forum help :p), especially for the most obscure and rarely used stuff.

On the other hand, I spent time digging in the various classes in Assembly-CSharp.dll, https://kerbalspaceprogram.com/api/, the wiki, ... and I found no entry-level explanations.

For example : are there any high level explanations of the logic of the flight model ?

Vessel class has quite a lot of 3dvectors (acceleration, gravitic_acceleration, angular velocity, east...), some are probably computed from others and / or taking other factors into account (atmosphere and so on).

Obviously, describing the complete logic is a daunting (if not impossible without the source code) task, yet, I'm sure the community has a working knowledge of it.

 

I don't mind doing research, for now I understand already quite a lot (not counting the flight model :p), there are a lot of mod sources code available to help, but if something exist, it would help.

 

Thanks :)

Link to comment
Share on other sites

1 hour ago, JeanLucJ said:

For example : are there any high level explanations of the logic of the flight model ?

Vessel class has quite a lot of 3dvectors (acceleration, gravitic_acceleration, angular velocity, east...), some are probably computed from others and / or taking other factors into account (atmosphere and so on).

No, there are no documentation of the inner working of most stuff. The best doc is usually the community API wiki, a few post laying around and IRC talks.

As for your example most of the flight model is done in the FlightIntegrator

Link to comment
Share on other sites

I have a trouble updating the contents of a PopupDialog.

I have a PopupDialog monitorWindow field in my class, which I create and fill with a MultiOptionDialog. It works ok. Then I use this code in Update():

if ((monitorWindow != null) && (monitorWindow.isActiveAndEnabled))
	monitorWindow.dialogToDisplay = new MultiOptionDialog("a dynamically generated message here", "Health Monitor", HighLogic.UISkin);

However, the message doesn't update on-screen. I don't see monitorWindow.Update() or anything like that. I could destroy the window and create a new one, but doing it every tick or every frame sounds bad.

UPD: The only way to update the popup window I found is to destroy and draw it again every Update. But then it becomes undraggable because it always spawns in the same location and I couldn't figure out how to access window's position.

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