Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Note that if you are using the PauseGame and UnpauseGame methods, I'm pretty sure they include the necessary control locks for you.

You can check and see if you show the Locks Stack in the Alt-F12 cheats window.

D.

Link to comment
Share on other sites

I want to create a mod, but don't know if someone else has already done it.  I have searched both the available mods and these forums and nothing comes up.  Maybe someone in the community knows if it's already been done or can point me in the direction I need to go to find out.  The mod is a simple one, a general search to find kerbals by name or type (engineer, scientist, etc.), then jump to their vessel.  The closest thing I could find was Quicksearch by malahx, but it doesn't allow search for kerbals.

Does anyone know of such a mod?

Thanks, N3RdP4W

Link to comment
Share on other sites

18 hours ago, N3RdP4W said:

I want to create a mod, but don't know if someone else has already done it.  I have searched both the available mods and these forums and nothing comes up.  Maybe someone in the community knows if it's already been done or can point me in the direction I need to go to find out.  The mod is a simple one, a general search to find kerbals by name or type (engineer, scientist, etc.), then jump to their vessel.  The closest thing I could find was Quicksearch by malahx, but it doesn't allow search for kerbals.

Does anyone know of such a mod?

Thanks, N3RdP4W

ShipManifest and RosterManager both will show you all your Kerbals, but not jump to the appropriate ship.

https://github.com/PapaJoesSoup/RosterManager/wiki

https://github.com/PapaJoesSoup/ShipManifest/wiki/1.5---Roster-Window

You might consider adding a patch to do so (either in addition to, or in place of, a standalone mod).

Edited by hab136
Link to comment
Share on other sites

Hopefully someone knows the answer to this and I just couldn't find it. Why is a Kerbal's transform.up not always up? If I go to a kerbal in orbit who is already on EVA then the transform.up is up, but when a kerbal is loaded from going on EVA directly transform.right is up. How can make sure a EVA kerbal's up is always up?

Link to comment
Share on other sites

Is System.IO still forbidden?

I am trying to communicate with an Arduino through a plugin using System.IO.Ports but it seems to not be loading the plugin. When I remove 'Using System.IO.Ports' the plugin loads but I need it. I thought System.IO was no longer blocked. Is there any other way around this?

Found this in the log
 

[ERR 14:04:25.092] AssemblyLoader: Exception loading 'NavballHID': System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0 

Additional information about this exception:

 System.TypeLoadException: Could not load type 'NavballHID.NavballHID' from assembly 'NavballHID, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Link to comment
Share on other sites

No, only Process was blocked in 1.0 and afaik nothing is in 1.1.

Most likely the class you require is not in the Unity Mono limited profile used by KSP. If you code on VS install the Tools for Unity and you will see more profile in the project settings. The one for KSP is the "Unity Subset". You ll should see if the class are present or not.

Link to comment
Share on other sites

In 1.0.5 I implemented EVA Propellant / Monoprop transfer from the pod to the Kerbal and back with something like this, that worked without any problem.

public class Kerbalism : MonoBehaviour
{
  // keep it alive
  Kerbalism() { DontDestroyOnLoad(this); }
  
  public void Start()
  {
    GameEvents.onCrewOnEva.Add(this.toEVA);
    GameEvents.onCrewBoardVessel.Add(this.fromEVA);
  }
  
  void toEVA(GameEvents.FromToAction<Part, Part> data)
  {
    // EVA vessels start with 5 units of eva fuel, remove them
    data.to.RequestResource("EVA Propellant", 5.0);
    
    // transfer monoprop
    data.to.RequestResource("EVA Propellant", -data.from.RequestResource("MonoPropellant", 1.0));
  }
  
  void fromEVA(GameEvents.FromToAction<Part, Part> data)
  {
    // get any leftover monoprop from EVA vessel
    double monoprop = data.from.RequestResource("EVA Propellant", 1.0); //< XXX
    
    // add the leftover monoprop back to the pod
    data.to.RequestResource("MonoPropellant", -monoprop);
  }
}

However, in 1.1.0.1230, the line tagged with 'XXX' return zero no matter how much EVA propellant / monoprop the Kerbal has at time of re-entering. The funny thing is that I'm also transfering a whole bunch of other resources and they work as expected, only monoprop show this problem. I suspect that something in the game code is resetting monoprop to zero just before the OnCrewBoardVessel callback is triggered. I found no relevant bug report in SQUAD bugtracker and I assume it doesn't allow more bug submit, as the last one is from yesterday (phun intended). I wonder if something has encountered this already. I tried all the obvious solutions, like quering the resource instead of requesting them and looking in the savegame (the EVA propellant is there). Any help is appreciated.

Link to comment
Share on other sites

14 minutes ago, Padishar said:

I would suggest you loop through data.from.Resources and print out what is in the part...

Thanks, I went ahead and run this

void fromEVA(GameEvents.FromToAction<Part, Part> data)
{
  foreach(var r in data.from.Resources.list)    
  {
    print(r.resourceName + ": " + r.amount + "/" + r.maxAmount);      
  }
  print("using RequestResource: " + data.from.RequestResource("EVA Propellant", 999.0));
}

that logged this:

[LOG 23:52:31.838] EVA Propellant: 5/5
[LOG 23:52:31.840] using RequestResource: 0

I'm baffled. The resource is here but calling RequestResource on it return 0. But this at least allow me to work around this.

Link to comment
Share on other sites

7 minutes ago, ShotgunNinja said:

I'm baffled. The resource is here but calling RequestResource on it return 0. But this at least allow me to work around this.

Yes, that does look a bit odd.  About the only thing I can think of is that the Kerbal part has already been removed from the "vessel" it is in.  Can you print the value of data.from.vessel.parts.Count?

Link to comment
Share on other sites

@Padishar , @JPLRepo Thanks guy

[LOG 00:25:07.775] data.from.vessel.parts.Count: 1
[LOG 00:25:07.775] data.from.Resources.list[0].flowMode: Both

I checked and in the GenericResource.cfg settings flow is set to NO_FLOW in both 1.1.0 and 1.0.5 for 'EVA Propellant'

That the part is here make sense because before it was returning ElectricCharge correctly in RequestResource, only Eva Propellant has this behaviour.

I'm wondering if this is just a bug, maybe not related to 'EVA Propellant' at all but to resource names with a space in them?

EDIT: I'm going to create another resource with a space in the name just to test this

Edited by ShotgunNinja
Link to comment
Share on other sites

3 minutes ago, ShotgunNinja said:

@Padishar , @JPLRepo Thanks guy


[LOG 00:25:07.775] data.from.vessel.parts.Count: 1
[LOG 00:25:07.775] data.from.Resources.list[].flowMode: Both

I checked and in the GenericResource.cfg settings flow is set to NO_FLOW in both 1.1.0 and 1.0.5 for 'EVA Propellant'

That the part is here make sense because before it was returning ElectricCharge correctly in RequestResource, only Eva Propellant has this behaviour.

I'm wondering if this is just a bug, maybe not related to 'EVA Propellant' at all but to resource names with a space in them?

EDIT: I'm going to create another resource with a space in the name just to test this

I think they changed it if NO_FLOW you get zero when you request resource.
Try changing the flow mode and see what happens.

Link to comment
Share on other sites

20 minutes ago, JPLRepo said:

I think they changed it if NO_FLOW you get zero when you request resource.

No, if they did that then solid rockets wouldn't work anymore because the ModuleEngines just does a requestResource on the part.

24 minutes ago, ShotgunNinja said:

I'm wondering if this is just a bug, maybe not related to 'EVA Propellant' at all but to resource names with a space in them?

I think it unlikely but it's possible.  "EVA Propellant".GetHashCode() should equal from.Resources[0].info.id.  If it doesn't then RequestResource will fail to find it on the part.  If spaces are a problem then you may find the "correct" id is actually "EVA".GetHashCode().

Also, have you checked the flowState property of the PartResource?  If that's false then RequestResource wouldn't work even if it managed to find it.  If that is the case then you should be able to use TransferResource instead which ignores that and also ignores all fuel flow mode stuff to just take it from the part itself.  You would have to call from.Resources.Get() with the id of the resource (name.GetHashCode()) to pass to it.

Edited by Padishar
Link to comment
Share on other sites

5 minutes ago, Padishar said:

No, if they did that then solid rockets wouldn't work anymore because the ModuleEngines just does a requestResource on the part.

I think it unlikely but it's possible.  "EVA Propellant".GetHashCode() should equal from.Resources[0].info.id.  If it doesn't then RequestResource will fail to find it on the part...

a) Yeah you're right.

b) Good thinking. the hash codes. Forgot about that.

Link to comment
Share on other sites

print("equal: " + ("EVA Propellant".GetHashCode() == data.from.Resources[].info.id));
print("flowState: " + data.from.Resources.list[].flowState);
foreach(var r in data.from.Resources.list)    
{
  print(r.resourceName + ": " + r.amount + "/" + r.maxAmount);      
}
print("using RequestResource: " + data.from.RequestResource("EVA Propellant", 999.0));

log this:

[LOG 01:01:46.393] equal: True
[LOG 01:01:46.394] flowState: False
[LOG 01:01:46.395] EVA Propellant: 5/5
[LOG 01:01:46.395] using RequestResource: 0

So it is flowState. How do I solve this in an elegant way, should I just set flowState to true in onCrewOnEva and call it a day? Thanks a lot guys

EDIT: Works like a charm! :)

@JPLRepo, @Padishar

Edited by ShotgunNinja
happiness
Link to comment
Share on other sites

12 minutes ago, ShotgunNinja said:

print("equal: " + ("EVA Propellant".GetHashCode() == data.from.Resources[].info.id));
print("flowState: " + data.from.Resources.list[].flowState);
foreach(var r in data.from.Resources.list)    
{
  print(r.resourceName + ": " + r.amount + "/" + r.maxAmount);      
}
print("using RequestResource: " + data.from.RequestResource("EVA Propellant", 999.0));

log this:


[LOG 01:01:46.393] equal: True
[LOG 01:01:46.394] flowState: False
[LOG 01:01:46.395] EVA Propellant: 5/5
[LOG 01:01:46.395] using RequestResource: 0

So it is flowState. How do I solve this in an elegant way, should I just set flowState to true in onCrewOnEva and call it a day? Thanks a lot guys

EDIT: Works like a charm! :)

@JPLRepo, @Padishar

Well there you go. Makes we wonder how the SRBs work then. Might take a look at that.
I'd change the flow state to what you need. Get the resource, then change it back.

Edited by JPLRepo
Link to comment
Share on other sites

1 minute ago, ShotgunNinja said:

So it is flowState. How do I solve this in an elegant way, should I just set flowState to true in onCrewOnEva and call it a day? Thanks a lot guys

Cool, that explains it then.  I can't think of any obvious issue from forcing it true just before you call RequestResource.  I'd be interested in knowing what changed from 1.0.5 though.  Presumably, the flowState used to be true because RequestResource did used to check it.  flowState was a plain bool in 1.0.5 but is now a property (so changing it can fire an event) but I can't see how that would cause this without some other change elsewhere.  I'm not sure how the Kerbal part and vessel are built when you EVA but I suspect it builds a ConfigNode and Loads it so presumably the setup of that must have changed.

Link to comment
Share on other sites

@Padishar, @JPLRepo

You are both right I'm gonna take the safe road and set it just before calling RequestResource, and setting it back just after. Why a change like this was required from SQUAD I can't phantom. Especially undocumented one. This is gonna bite everybody that want to mess with eva fuel, and every old mod that did that. At least there is some info here now. Cheers!

Link to comment
Share on other sites

4 minutes ago, ShotgunNinja said:

@Padishar, @JPLRepo

You are both right I'm gonna take the safe road and set it just before calling RequestResource, and setting it back just after. Why a change like this was required from SQUAD I can't phantom. Especially undocumented one. This is gonna bite everybody that want to mess with eva fuel, and every old mod that did that. At least there is some info here now. Cheers!

You seem surprised by undocumented changes?? There are hundreds of them. Hence all my mods are still broken in 1.1. Welcome to the world of modding KSP.
BTW: I think changing the flowstate will now fire this GameEvent: onPartResourceFlowStateChange. Not sure but @Padishar's comment made me remember something about a new GameEvent so I went through them.

Link to comment
Share on other sites

@JPLRepo How can I avoid that event? What if I call TransferResource instead, that i understand must be some kind of old version of RequestResource without flow mechanics...

EDIT: nope, it seems to obey flowState. Screw that, lets this damn event fire and who cares

Edited by ShotgunNinja
Link to comment
Share on other sites

24 minutes ago, ShotgunNinja said:

@JPLRepo How can I avoid that event? What if I call TransferResource instead, that i understand must be some kind of old version of RequestResource without flow mechanics...

EDIT: nope, it seems to obey flowState. Screw that, lets this damn event fire and who cares

Why don't you just take the resource yourself? Just do the math and add/subtract the resource.amount yourself from each.
you don't "Have to" use RequestResource or TransferResource

Edited by JPLRepo
Link to comment
Share on other sites

@JPLRepo So these RequestResource/TransferResource only use is if I care about flow states, flow modes and stacking.... I didn't realize I could just do this:

void fromEVA(GameEvents.FromToAction<Part, Part> data)
{
  // add the leftover monoprop back to the pod
  data.to.RequestResource("MonoPropellant", -data.from.Resources.list[].amount);
}

 

Edited by ShotgunNinja
Link to comment
Share on other sites

45 minutes ago, ShotgunNinja said:

How can I avoid that event? What if I call TransferResource instead, that i understand must be some kind of old version of RequestResource without flow mechanics...

EDIT: nope, it seems to obey flowState. Screw that, lets this damn event fire and who cares

I suspect very little will get upset about the event firing.  Someone was asking about how to detect when the user toggled the flowState on a part the other day but I doubt you would upset whatever they were doing.

However, TransferResource definitely shouldn't take any notice of flowState.  E.g.

data.from.TransferResource("EVA Propellant".GetHashCode(), amount);

...should definitely work in this case though you should probably only get the id of the resource once and store it.

22 minutes ago, JPLRepo said:

Why don't you just take the resource yourself? Just do the math and add/subtract the resource.amount yourself from each.
you don't "Have to" use RequestResource or TransferResource

Please don't even consider doing this.  TransferResource (that RequestResource and various other bits of KSP code calls to actually add or remove resources) now fires some very important events when parts change from full<->non-full and empty<->non-empty and you doing it yourself will skip this which will break stock and mod code (perhaps not immediately, but certainly when the resource overhaul happens in 1.2).

 

 

5 minutes ago, ShotgunNinja said:

So these RequestResource/TransferResource only use is if I care about flow states, flow modes and stacking.... I didn't realize I could just do this

No, all TransferResource cares about is flowMode (in, out, both, none).  RequestResource also honours the flowState and the ResourceFlowMode (stack, all vessel etc.).

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