Jump to content

Recommended Posts

I tried to put addclasspostconstruct in modmain.lua to modify scripts/messagebottletreatments.lua,

but it didn't work.

I guess my addclasspostconstruct may be used incorrectly.

AddClassPostConstruct("messagebottletreasures", function(self)
	local old_templates = self.treasure_templates
    self.treasure_templates = new_templates
end)

local new_templates =
{
    --somethingSome treasure_templates content
}

Thanks all you guys.

:spidercowers:

The problem with your code is that messagebottletreasures is not a class, so you can't override it with AddClassPostConstruct.

local new_templates =
{
    --somethingSome treasure_templates content
}

local messagebottletreasures = require "messagebottletreasures"
local old_templates = messagebottletreasures.treasure_templates
messagebottletreasures.treasure_templates = new_templates

But you can access it directly by using require.

This code snippet has the effect that you want.

  • Like 2

@Monti18

Thank you very much for your help!

But there is a table called weighted_treasure_prefabs  in messagebottletreasures, which determines what's in the sunkenchest, weighted_ treasure_ prefabs is a local variable, so still can't customize the content of sunnkenchest in this way.

I'm looking for other ways to modify messagebottlemanager. lua or messagebottletreatments.Generatetreatment().

If you want to modify the treasures of sunkenchest, you can either make your own GenerateTreasure function and replace it with the one from the original file or use rezecibs upvaluehacker to change the local treasure_templates so that the changes are transferred to the GenerateTreasure function.

The upvaluehacker method makes it more compatible to future changes but costs more computing power.

  • Like 2

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...