Nraas and Inventories?

Talk nerdy to us here.
Post Reply
User avatar
lyralei
Reactions:
Posts: 13
Joined: January 30th, 2021, 5:36 am

Nraas and Inventories?

Post by lyralei » November 5th, 2023, 4:16 pm

Hey there!

I'm currently working on a mod that grants sims the ability to get thirsty. So for that, I figured to instead have townies die of dehydration, to instead give them water bottles in their inventory!

Though, when i'm adding the bottles to the inventory, it's not... doing it? I know nraas has some inventory checking and cleaning, which makes me to think that it's not working for them because of that.

The code is simple, in case that's necessary:

Code: Select all

 

Code: Select all

ThirstObject bottle = sim.Inventory.Find<ThirstObject>();
if (bottle == null)
{
	bottle = GlobalFunctions.CreateObjectOutOfWorld(new ResourceKey(0x653F91D91B915D67, 0x319E4F1D, 0x00000000)) as ThirstObject;
	sim.Inventory.ForceAdd(bottle);
    if (!sim.Inventory.TryToAdd(bottle))
    {
        print("Bottle can't be added.");
		bottle.Destroy();
    }
    else
    {
		print("Bottle should've added...");
    }
}

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7618
Joined: December 30th, 2011, 6:00 pm
Answers: 82
Contact:

Nraas and Inventories?

Post by Chain_Reaction » November 7th, 2023, 8:52 am

Hmm. I can't think of anything that would block this off the top of my head. Have you removed NRaas and confirmed it works without? Are you sure the bottle is actually being created?

User avatar
lyralei
Reactions:
Posts: 13
Joined: January 30th, 2021, 5:36 am

Nraas and Inventories?

Post by lyralei » November 9th, 2023, 8:52 am

I did a few tests with NRaas, so here are my findings:
  1. Active sims do actually get their bottles, but townies won't. I tested this with rubber duckies as well :p
  2. Even if you just do "ForceAdd" it won't add.
  3. Once deriving your inventory item as INonPurgeableFromNPCInventory, it does seem to add it to townie's inventory now.
  4. It seems to add the bottle, but something deletes it when I check a townie's inventory... Without NRaas this isn't the case.
The way I check it is: Nraas > Debug Enabled > View Inventory.

This also seems to happen with non-custom items as well. Books, ingredients, other things townies could add as well. The only way I got it working was to use "INonPurgeableFromNPCInventory". Which was purely because I noticed the "Homework" object never got deleted, which also had this.

It's... not the best idea, but at least it makes it stick around :) That way townies won't die of dehydration lol

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7618
Joined: December 30th, 2011, 6:00 pm
Answers: 82
Contact:

Nraas and Inventories?

Post by Chain_Reaction » November 11th, 2023, 10:33 am

Oh, I assumed you were using INonPurgeableFromNPCInventory from the start. This is actually EA and not NRaas initially. In Inventory.AddInternal it nukes anything going into inactive inventories that is not derived from that interface. You can use Inventory.TryToAdd(IGameObject obj, bool testPurge) and set testPurge to false to skip this check but best to keep the the interface cause it can get nuked by anything that cleans inventories later (including NRaas methods).

Post Reply