Jump to content

Contract Modding Information for Mod Authors


MrHappyFace

Recommended Posts

You can directly modify contract payments per body through RecoveryValue, just keep in mind you will also be modifying the science payout for recovering a vessel after returning from that body at the same time. Bit messy, but at least there's a way to modify it.

Yep, my [thread=80220]celestial body science parameter modifier[/thread] can be used to adjust this. I have a big warning on the thread about it affecting contract rewards though, since a few people discovered the hard way that this happens.

Link to comment
Share on other sites

Yep, my [thread=80220]celestial body science parameter modifier[/thread] can be used to adjust this. I have a big warning on the thread about it affecting contract rewards though, since a few people discovered the hard way that this happens.

Ah, cool. I've been editing those values forever both in BTSM and ATC, but never realized before today that RecoveryValue also affects the contract payouts :)

Link to comment
Share on other sites

  • 3 weeks later...

Does the info of 1st post still valid in 0.25 ?

Cause Generate is called AFTER getHashString !

+ there is no help on objectives setup => done with contract paremeter(s)

+ using numberf seems to be wrong, despite method parameter is "float days" in SetDeadlineDays(), using 'f' suffix makes numbers misparsed/misinterpreted (8f for days = 1d, 5h, 59m, 58s !)

EDIT:

does anyone know WHY MeetRequirements of a subclass of Contract class is called VERY OFTEN ? (very often = about 30 times/sec)

And even in flight mode ?? How does a contract could be not offered in flight ?

As is this what MeetRequirements method is supposed to do, work on Mission Controller building to check if a contract is offered or not, according to

In MeetRequirements(), you can check if this contract should show up in mission control, and return false is it shouldn't and true if it should.
from 1st post

An empty contract example would have been better IMHO (EDIT: working on it)

Edited by Justin Kerbice
Link to comment
Share on other sites

  • 4 weeks later...
Ok, I hope people are still following this thread as I just figured out something rather crucial about the contract system :)

I was noticing that as I was adding more and more contracts to the game, a lot of them were being generated only to be then removed by the contract system. There's a debug output that stock generates when this happens.

Playing around a bit, I figured out that the number of contracts *on offer* seems to be limited to a specific number per prestige level, that contracts above a certain prestige level are removed if the player's reputation is too low (I don't know the precise values involved as that would take a LOT of test cases to figure out), and that the number offered at a given prestige level seems to also be dependent on reputation.

So, with a bit of educated guess-work and a bunch of debugging output code, this is what I figured out:

When a contract has its Generate() function called, it already has its prestige level set to the prestige level of contract the contract system wishes to generate. In other words, if a new trivial prestige contract would create a contract that would exceed the limit on the number of trivial contracts that should be present at any given time Generate() will NOT be called with the prestige level set to trivial.

What this means is you should NOT return true from Generate() if you would be creating a contract at a prestige level other than the one specified. Either that, or you should tailor your contract generation so that it generates a contract only of the prestige level specified (i.e. you should NOT set it yourself).

A simple example from my own code where I have a contract that I only want to generate at the trivial prestige level in case any of that wasn't clear:


protected override bool Generate()
{
if ( prestige != ContractPrestige.Trivial )
{
return false;
}

// regular contract generation code here
}

This is probably also why when you create a bunch of custom contracts, certain stock ones stop being generated. The stock contracts are testing whether they should generate based on the prestige, while custom contracts that don't wind up saturating the system so that the stock ones no longer have room to generate in.

Anyways, like I said, I really hope the other contract mod authors are still following this thread, as this seems to be a rather major thing about the way the system works, and I'm still surprised I managed to figure it out given how less than obvious it is :)

Thanks flowerChild indeed I have not checked this thread for some time.. LOL I have set all my contracts to this, I had a large amount of things to help control the amount of spam already in my Mod and this will help even more. Something I can't stress enough is that its also a pretty good idea to be able to turn off all your contract types. In that case you give the player some pretty good control over what is showing up and what is not.

On a new note. Anyone yet figure out how to make a contract parameter dependent on another to be finished without using a static value to communicate hackery.

what I mean is if in the actual contract I have. Two parameters.. Lets say in my case.


this.AddParameter(new GetCrewCount(crew), null);
this.AddParameter(new PreLaunch(), null);

If I want GetCrewCount to only be checked when PreLaunch is Contract.state.complete anyone figure this out.

I tried a few things and it usually ends up bad. Seems like once a contract is generated then nothing can change from the contract point of view, only from within the parameters themselves.

DisableOnStateChange = false; seems to help within the parameters themselves if you want you State to change if something else changes while the player plays. But again this seems to be only effective if the code exist within the actual Parameter itself to take advantage of a DisableOnStateChange applied from within the contract itself. So far seems its the only thing that seems to work to effect an already generated contract. Again which would lead to a hack to get parameters to work with each other... Which is what I don't want to do at this point.

Link to comment
Share on other sites

  • 3 weeks later...

My current effort is going to be the death of me. I'm in the process of writing a mod which rescales contract payouts for RSS, to have a more sane accounting of delta-V requirements. I've having trouble, though. I think I've figured out how to do something when a new contract is offered, but I can't figure out how to find and modify the contract which was offered. I then thought of adding a dummy parameter to mark rescaled contracts, but that approach is creating duplicate contracts on me*.

*I think what is going on is that I modify, say, the Orbit Kerbin contract, KSP no longer recognizes it as the Orbit Kerbin contract and re-offers it, it gets re-scaled, and this repeats each time the contract list changes.

Thus: does anybody know how to catch new contracts as they are offered, or a good way to prevent duplication of the scripted contracts after I give them a new parameter?

Link to comment
Share on other sites

Starman4308, check out the source of this one:

contract science modifier

I'm not adding a new parameter there but getting and changing attributes of an existing one without getting anything doubled. Brief and simple.

Are you sure that works? I copied the logic, and while it worked for the first four contracts offered, it didn't do so for subsequent contracts. What I suspect may be happening is that the onDestroy() method is being called the moment you change scenes, and I suspect trying to fix that would just cause even worse problems, because you might get accumulation of multiple copies of your addon running around. In any case, I started my own thread, and it's back to "make a log of previously encountered contract GUIDs, and skip those when iterating over contracts each time the list changes" for now.

EDIT: Hallelujah, I've gotten my dictionary to work. My thread (and the GitHub source) is here: the mod still doesn't do anything useful, but AFAIK, it is functional and robust in modifying contracts once and only once. I swear I'll document it better later.

Edited by Starman4308
Link to comment
Share on other sites

Are you sure that works? I copied the logic, and while it worked for the first four contracts offered, it didn't do so for subsequent contracts.

I'm almost sure that works 'cause I use it personally for a couple of weeks having about 10 new contracts processed. May be there's something besides my logic like 64bit KSP? Would appreciate if you provided more detail about the case and contracts that failed to process in my post, some screenshots would be great.

Edited by Ser
Link to comment
Share on other sites

  • 2 months later...

On a new note. Anyone yet figure out how to make a contract parameter dependent on another to be finished without using a static value to communicate hackery.

Well see, I haven't checked this thread in a long while either now :)

If you're still having trouble with this, I can do a write up on how it to be sure, as I'm already doing it in several BTSM contracts. Let me know if that's the case (probably best via PM so we don't miss it again), but I suspect a couple of months later you may have already sorted it.

It's a bit of a shame this thread has fallen into disuse and been unstickied as there's a lot of useful information contained within, and definitely room for ongoing conversation and knowledge sharing with the integration of Fine Print into stock.

I actually just popped it open again to reference the table of relative values of contracts based on location and prestige value that DMagic posted earlier in the thread as I had forgotten something about it :)

Edited by FlowerChild
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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...