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

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.