TheReadPanda Posted May 29, 2015 Share Posted May 29, 2015 I am having trouble with basically the last step of my attempt to make a new hiring application.The GUI is pretty much done, as are the logic checks to set things.However I am hitting a brick wall when it comes to the actual 'create a kerbal' code.I have looked at both the code behind Ship Manifest (kerbal roster part) and the code behind Draft Twitch Viewers. Neither seems to be working for me. Long story short I have a method call that goes to make the new kerbal.The method needs to create a valid kerbal, give it a name, set the various fields and then set it so that it shows in the active roster. Now I have almost gotten there a few times in that I had my test for if the roster was full some how say yes even when it was not showing in the roster. Even had it show up in the save file some how, but still not show on the roster. I feel like I am just missing one core step. But as my code is all over the place in all the things I have tried can someone help? I can't find good documentation on this process...Should I be using protokerbal? Kerbal? Classes?If someone could just outline a basic framework for making a new kerbal I am sure I could fill in the rest.Thanks in advance for any help anyone out there can provide!!OakTree42http://www.twitch.tv/oaktree42/ Link to comment Share on other sites More sharing options...
MrHappyFace Posted May 29, 2015 Share Posted May 29, 2015 I think you'd do use HighLogic.CurrentGame.Roster.GetNextApplicant() or something like that. I remember that it is just 1 method somewhere in the HighLogic.CurrentGame.Roster, and that it creates a new random kerbal as an applicant. If you want to edit the kerbal, then I'm pretty sure that method returns a crew object that you can use. Link to comment Share on other sites More sharing options...
TheReadPanda Posted May 29, 2015 Author Share Posted May 29, 2015 (edited) I've tried all kinds of variations:ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();The above does not seem to work.I've tried pretty much every permutation I could find by poking the object browser. I have to think I'm missing something simple here... but I am not sure what.Ah, stupid me, yeah, no, that wouldn't work. Trying a few other things now.What I keep thinking I need is something like:ProtoCrewMember newKerb = new (insert type here)But no variation of protocrew member seems to work nor HighLogic.x as the only variations I can get there at that kind of reference is LogEntry and VK.- - - Updated - - -Here is some code I was trying... and failed to get to work: ProtoCrewMember newKerb = CrewGenerator.RandomCrewMemberPrototype(); newKerb.type = ProtoCrewMember.KerbalType.Crew; if (KGender == 0) { newKerb.gender = ProtoCrewMember.Gender.Male; newKerb.name = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Male) + "Pilot"; } if (KGender == 1) { newKerb.gender = ProtoCrewMember.Gender.Female; newKerb.name = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Female) + "Pilot"; } newKerb.experience = 0; newKerb.experienceLevel = 0; newKerb.courage = Courage; newKerb.stupidity = Stupidity; if (Fearless) { newKerb.isBadass = true; } MethodInfo dynMethod = HighLogic.CurrentGame.CrewRoster.GetType().GetMethod("AddCrewMember", BindingFlags.NonPublic | BindingFlags.Instance); newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available; dynMethod.Invoke(HighLogic.CurrentGame.CrewRoster, new object[] { newKerb });I've also tried such approaches asProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();Or even things like:ProtoCrewMember newKerb = new HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();And variations on:Kerbal newKerb = .......So something here is just... not working. And I am unsure the 'correct' approach to use to instantiate a new kerbal into the system so I can modify the proper attributes.I also tried: ProtoCrewMember newKerbal = roster.GetNewKerbal(); newKerbal.name = realUsername + " Kerman"; KerbalRoster.SetExperienceTrait(newKerbal);Which was the core code I could find in the draft twitch viewers but again, no luck. And yes, I do have the roster set earlier in the code... so that isn't it. *shrugs*Any help here would be greatly appreciated as I am bashing my head against this code wall with little luck so far. Edited May 29, 2015 by OakTree42 Link to comment Share on other sites More sharing options...
TheReadPanda Posted May 29, 2015 Author Share Posted May 29, 2015 Okay turns out it /is/ creating the kerbals but the crew roster side of the screen is not updating, which means if I leave the game then return, it is updated.... So now I have to figure out how to refresh that when a kerbal is hired but that seems to be giving me grief now too. Whee. Link to comment Share on other sites More sharing options...
TheReadPanda Posted May 29, 2015 Author Share Posted May 29, 2015 For those interested I have some code that works but it is failing to update the crew half of the screen right now: private void kHire() { ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew); newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available; if (KGender == 0) { newKerb.gender = ProtoCrewMember.Gender.Male; newKerb.name = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Male) + "Pilot"; } if (KGender == 1) { newKerb.gender = ProtoCrewMember.Gender.Female; newKerb.name = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Female) + "Pilot"; } ScreenMessages.PostScreenMessage(newKerb.experienceTrait.TypeName + "" + newKerb.name + " has been created?"); // This is a debug message that is not needed but was for my testing purposes. newKerb.experience = 0; newKerb.experienceLevel = 0; newKerb.courage = Courage; newKerb.stupidity = Stupidity; if (Fearless) { newKerb.isBadass = true; } newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available; roster.GetNewKerbal(newKerb.type); KerbalRoster.SetExperienceTrait(newKerb);}Getting the right 'career' will be tricky as will setting xp level based on career type and flight logs etc. But I shall chug through that. But for now I have to leave and return to get things to show. I suspect this has more to do with the GUI override I'm doing than the hiring code. But I thought I would share this code here as I hadn't seen anything quite like it on the forums yet. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now