Custom Contracts API broken behavior

Patrick Heney shared this bug 23 months ago
Reported

When using the modding API to add a custom contract to contract blocks, the contracts do not appear for contract blocks on Economy stations. They do appear for contract blocks that have been placed by a player or admin, even after changing ownership of the blocks to an NPC faction. But the contracts will not appear on the contract blocks on stations and bases spawned by the Economy system. As a modder, the expected behavior is that when adding a contract to a contract block, it will appear. (I have ensured the NPC factions that own the contract blocks on the Economy stations have enough money to cover the contract.)

Custom Contracts do not award or penalize reputation when they are completed or failed.

Both of these issues affect one of my mods, which allows players to haul actual grids between destinations, using the contract system. Unfortunately the two issues above cause problems. I need to spawn in a completely separate set of trading stations with contract blocks in order for players to find the contracts. And the reputation issue means that none of the contracts will modify reputation, simple as that.

Lastly, there is a bug in the contract type system. When creating a new type of contract, the name is not displayed correctly in the contract type dropdown. This is the dropdown where you select "Acquisition" or "Escort" or "Search" or whatever. The new contracts display as this "ContractType NameLocalizationKey." Some investigation in the Keen discord led me to believe I needed to provide a .resx file and another file to provide that localization information, but after creating it, the display name did not change. I later learned that in this specific case, the contract system does not actually read from the .resx file. So there's no way to actually set that displayed information.

Please let me know if you need any additional information or would like to look at the code I'm using.

This is the Freight Contracts mod: https://steamcommunity.com/sharedfiles/filedetails/?id=2915223144&tscn=1673372483


Thank you very much!

Replies (12)

photo
2

I believe Keen made some gestures in 2022 to make the game more modder friendly... especially working with modders. This is, again, one of those situations. Here's a feature that should have better hooks in the API since NPC faction disposition factors into any modded game or SCENARIO with NPCs. Completing a modded task or quest for the NPC as well as query the disposition allows for better world building.

photo
5

More npc interactions and more things you can do in game like accepting greatly expanded contract offerings would lead to much more enjoyable gameplay for a good number of SE players.

photo
photo
2

This is very important for new content. It should be on the list.

photo
1

Here is a code for loading localization:


private void LoadLocalization(string folder) {
 var path = Path.Combine(ModContext.ModPathData, folder);
 var supportedLanguages = new HashSet<MyLanguagesEnum>();
 MyTexts.LoadSupportedLanguages(path, supportedLanguages);

 var currentLanguage = supportedLanguages.Contains(MyAPIGateway.Session.Config.Language) ? MyAPIGateway.Session.Config.Language : MyLanguagesEnum.English;
 if (Language != null && Language == currentLanguage) {
 return;
 }

 Language = currentLanguage;
 var languageDescription = MyTexts.Languages.Where(x => x.Key == currentLanguage).Select(x => x.Value).FirstOrDefault();
 if (languageDescription != null) {
 var cultureName = string.IsNullOrWhiteSpace(languageDescription.CultureName) ? null : languageDescription.CultureName;
 var subcultureName = string.IsNullOrWhiteSpace(languageDescription.SubcultureName) ? null : languageDescription.SubcultureName;
 MyTexts.LoadTexts(path, cultureName, subcultureName);
 }
}

photo
1

Hi Gregory!

Thanks for providing this code. Is there anywhere I can get additional information?

In the middle, there is a line "if (Language != null..." but "Language" is not defined anywhere. Is there somewhere I can see a working example?

Also, it looks like I need to pass in the subdirectory in my mod where I have some file, is that correct? Or is the argument supposed to be the file name?

Also, what is the file I'm supposed to provide? Is it that .resx file I mentioned or something else?

Where does this need to be called? Init()? LoadData()? Does it matter?

I see in a follow-up comment you mentioned the following. Where does this fit in to the above code?

> You need translate "ContractType_NameLocalizationKey_FreightContract" key, instead of "FreightContract".

I'm sure all this is very obvious to someone that has used this before, but this is my first experience where I have had to deal with localization in this game. I have no references to draw upon.

This format may be a bit awkward to exchange information, so you are welcome to join my Discord where we can talk more easily. I'm also open to other alternatives, if that suits you better.

Thanks!

photo
photo
2

Yes its i wanted feature ! Pls if we can fix it that would be great !

photo
2

I love this mod idea and it would be great if the API could be fixed so it worked with economy stations

photo
1

Hello Patrick Heney,


Localization works fine.

You need translate "ContractType_NameLocalizationKey_FreightContract" key, instead of "FreightContract".

Also in your scripts, I dont see localization loading logic (something that I posted above)

photo
1

Yeah, I removed the code. It didn't work and then someone on the Keen discord mentioned that the contract system specifically had a bug and didn't read the localization data like it is supposed to.

I'll try again with the code you provided above.

photo
2

I had successfully translated it.

It is not obvious that it is "ContractType_NameLocalizationKey_FreightContract", as you dont see that part "_FreightContract", but everything works

photo
photo
3

Hello, Patrick and other Engineers!

Thank you so much for reporting this.

This thread can be basically split to three topics:

1) the contracts do not appear in the contract blocks on economy stations

2) when contracts are placed manually in player spawned station, it is not affecting reputation

3) the localization issue

I've reported the first two issues.

The third one should be solved if you use the piece of code and information from Gregory, which you can find above.

Kind Regards

Keen Software House: QA Department

photo
2

Hi Ondrej! Thank you very much for taking the time to look at this issue. Please let me know if you need any additional information from me. :)

photo
1

Hello, Patrick,

so, our programmer team took a look on this thread and these issues.

They came to conclusion that only the second part bugged. I needed to close the first one (contract do not appear in the stations), as contracts on stations are only for that specific NPC faction not for players.

Still keeping this thread on Reported state though, because of the second issue (reputation not changing).

Kind Regards

Keen Software House: QA Department

photo
13

Hi Ondrej! I'm sorry for the confusion, but you have misunderstood the first part. I am creating NPC contracts. The contracts are assigned to the faction that owns the stations I am trying to put them on. These NPC contracts are not appearing in the NPC Economy stations. It is not working as intended.

photo
photo
4

Hello, I tried to implement custom contract in a simmilar manner. Contracts are being added properly to NPC contract blocks that are on NPC encounters or that are manually placed for example, but aren't added to the economy trade station contract blocs.

photo
4

The steps to replicate the issue (done via MyApiGateway.ContractSystem API)


  1. I created an NPC contract that belongs to an NPC faction.
  2. I attempt to add that contract to an Economy station that is owned by the same NPC faction.
  3. The contract is not added to the contract block.

Expected result

NPC contract owned by NPC faction is added to contract block on Economy station owned by same NPC faction.

Actual result

Contract does not appear in the contract block.

photo
1

Issues with the modding API for custom contracts include missing contracts on Economy stations and reputation not changing upon completion. Workarounds involve spawning new trading stations for contracts. Additionally, contract type names show localization errors despite attempts to fix them. This resembles gaming challenges like Moto X3M tricky levels—engaging yet frustrating. Feel free to review the code if needed!

Leave a Comment
 
Attach a file