Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

19 minutes ago, NermNermNerm said:

Anybody know how to inject code into the "Recover Vessel" scenario?  I want to give some extra prestige rewards for certain cargos.

I would suggest registering for these events:

  • GameEvents.OnVesselRecoveryRequested 
  • GameEvents.onVesselRecovered
  • GameEvents.onVesselRecoveryProcessing
  • GameEvents.onVesselRecoveryProcessingComplete
  • GameEvents.onGUIRecoveryDialogSpawn

Confirm for yourself what order they are called and what each one does. There's a couple of them that give a handle on the ProtoVessel being recovered as well as the MissionRecoveryDialog so you may be able to do something there, update some values to reflect your extra rewards, maybe inject some additional UI into the dialog to provide feedback to player, all that jazz.

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

Apologies, disregard. 

  

 

Edited by Red Stapler

Share this post


Link to post
Share on other sites
Posted (edited)

Is there a way to check if there is a CommNet path between two vessels that are not necessarily connected to Home, and get the total distance and signal strength? I can't find anything of use here in the CommNet classes and I wouldn't know how to make this myself.

Edit: seems like asking this improved my chances of finding the right thing, because I think

override void CommNet.CommNetwork.CreateShortestPathTree(CommNode start, CommNode end) 	

or

override bool FindPath(CommNode start, CommPath path, CommNode end)

might be what I was looking for, though I don't understand how to use these (getting a path from a pathtree that is not returned? find the best path when I don't have a path? findpath returns bool instead of path?)

Edited by ExtremeTrader

Share this post


Link to post
Share on other sites
1 hour ago, ExtremeTrader said:

find the best path when I don't have a path?

CreateShortestPathTree is protected, I don't think you're supposed to use it the way you're probably imagining.

 

1 hour ago, ExtremeTrader said:

findpath returns bool instead of path

FindPath's bool return value is probably a success/failure flag, for instance there may not be any path between the given start and end nodes.

The path param probably behaves like an out or ref param.

Try something like this? (Note: purely speculative from reading API and not actually tested)

CommNode start = vessel1.Connection.Comm;
CommNode end = vessel2.Connection.Comm;
CommPath path = null; // may need to instantiate if this causes null reference exceptions

CommNetwork network = CommNetNetwork.Instance.CommNet;
// not sure if needed, seems like a good precaution:
if (network.IsDirty)
    network.Rebuild();

if (!network.FindPath(start, path, end))
{
    // did not find a path
    Debug.Log($"Failed to find a path between {vessel1.vesselName} and {vessel2.vesselName}")
    // ...
}
else
{
    // do things with path, like
    Debug.Log($"Signal strength between {vessel1.vesselName} and {vessel2.vesselName} is {path.signalStrength}");
}

 

hth

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, cakepie said:

FindPath's bool return value is probably a success/failure flag, for instance there may not be any path between the given start and end nodes.

The path param probably behaves like an out or ref param.

That does make sense, but it's not set as out or ref or even optional (https://kerbalspaceprogram.com/api/class_comm_net_1_1_comm_network.html#ab3c35970caed4e281ded1612770acdfe).

When I try to use CommNetwork as a type visual studio mostly flips out and breaks control loops for some reason (edit: your code doesn't give errors however, not sure what happened).

 

edit 2: threw your code in a method and found this in the log:

[ERR 16:35:03.203] Module ResourceTransceiver threw during OnUpdate: System.NullReferenceException: Object reference not set to an instance of an object
  at CommNet.CommNetwork.FindPath (CommNet.CommNode start, CommNet.CommPath path, CommNet.CommNode end) [0x00000] in <filename unknown>:0 
  at ResourceBeamer.ResourceHandler.somemethod (.Vessel vessel1, .Vessel vessel2) [0x00000] in <filename unknown>:0 
  at ResourceBeamer.ResourceTransceiver.OnUpdate () [0x00000] in <filename unknown>:0 
  at Part.ModulesOnUpdate () [0x00000] in <filename unknown>:0 

I'm pretty sure that's a nullref about the path being null, I don't know how to get a path though

Edited by ExtremeTrader

Share this post


Link to post
Share on other sites
On 5/25/2019 at 6:34 AM, ExtremeTrader said:

I don't know how to get a path though

Hmm yeah, that's a problem, I don't see anything in the API that helps with that either. :/

Share this post


Link to post
Share on other sites

Hi, is there a way that I can make every monoprop that uses monopropellant use another monoprop gas(I have real fuels and RO+RSS, and quite an amount of my monoprop from mods use monopropellant)?

Share this post


Link to post
Share on other sites
On 6/12/2019 at 8:01 PM, JPGSP said:

Hi, is there a way that I can make every monoprop that uses monopropellant use another monoprop gas(I have real fuels and RO+RSS, and quite an amount of my monoprop from mods use monopropellant)?

You can do this using ModuleManager (you already have it installed if you have RO+RSS). If you want to edit engines you can make a new .cfg in your gamedata folder and use this (I haven't tested it):

@MODULE[ModuleEngines]
{
    @PROPELLANT[MonoPropellant]
    {
        @name = otherMonopropGas
    }
}

for RCS, something like this should work:

@MODULE[ModuleRCSFX]
{
    @resourceName = otherMonopropGas
}

Of course, you need to make sure that your otherMonopropGas is actually defined in a resourcedefinition cfg somewhere, but if you change it to one of the real fuels resources you don't need to think about that.

I suggest that you practice writing MM patches, they can be very useful. Some syntax explanation can be found here: https://github.com/sarbian/ModuleManager/wiki/Module-Manager-Syntax

Share this post


Link to post
Share on other sites

I came to realize that using GameDatabase.Instance.GetConfigNode(Part.partInfo.partUrl) is a very handy way to get exactly what the ConfigNode of a part is in memory.

But it happens that spaces on the partUrl make it borks. I can inspect any part on the GameDatabase using the partUrl, except by the ones using spaces somewhere on the URL.

There's a workaround for this, as replacing "_" by "." on the partNames?

Share this post


Link to post
Share on other sites

If I remember correctly, \uxxxx notation is supported now, so you can write \u0020 for space.

Share this post


Link to post
Share on other sites
14 hours ago, Lisias said:

I came to realize that using GameDatabase.Instance.GetConfigNode(Part.partInfo.partUrl) is a very handy way to get exactly what the ConfigNode of a part is in memory.

But it happens that spaces on the partUrl make it borks. I can inspect any part on the GameDatabase using the partUrl, except by the ones using spaces somewhere on the URL.

There's a workaround for this, as replacing "_" by "." on the partNames?

Try Part.partInfo.partConfig, turns out KSP saves it directly.

Share this post


Link to post
Share on other sites
Posted (edited)
On 5/25/2019 at 5:59 AM, ExtremeTrader said:

Is there a way to check if there is a CommNet path between two vessels that are not necessarily connected to Home, and get the total distance and signal strength? I can't find anything of use here in the CommNet classes and I wouldn't know how to make this myself.

Edit: seems like asking this improved my chances of finding the right thing, because I think


override void CommNet.CommNetwork.CreateShortestPathTree(CommNode start, CommNode end) 	

or


override bool FindPath(CommNode start, CommPath path, CommNode end)

might be what I was looking for, though I don't understand how to use these (getting a path from a pathtree that is not returned? find the best path when I don't have a path? findpath returns bool instead of path?)

Did you end up figuring this out? I'm also trying to see if a path exists between two vessels that aren't connected to home. In the map view in game it is possible to see this, so I would expect that each vessel should know what other vessels it is currently connected to, but from the docs, it seems like this information is never stored anywhere...since I guess it gets recalculated every frame.

Maybe you could use 

TryConnect (CommNode a, CommNode b, double distance, bool aCanRelay, bool bCanRelay, bool bothRelay)

 

Edited by subyng

Share this post


Link to post
Share on other sites

Can anybody tell me how to change one of the strategies to change its values? I could probably do it directly in the game files, but I want to make it available for other people as a plugin and learn a bit of coding along the way.

Edit: OK, done. This was easier than I expected.

Edited by Wjolcz

Share this post


Link to post
Share on other sites

New problem: I created a resources exchanger (just like the Research Rights Sell-Out), but I get some silly values. I wanted to buy science with funds, but the problem is science is now super cheap and it takes a % from what I have. I want the prices to be constant. For example, when I set the slider to 1% it buys me 1 science for 1000 funds. Either that or I need somebody to explain me how the minShare, maxShare, minRate, maxRate values work.

Btw, can I somehow refresh/reload the game once it's launched or do I need to restart it each time I change something in the mod?

EDIT: I DID IT! Now all I need to know is how to change the name of the strategy.

Edited by Wjolcz

Share this post


Link to post
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.