Jump to content

It doesn't seem to work, why?


Recommended Posts

I am trying to make maxwell uses double the durability of a book on read, but it just doesn't work.

When i enter the game and i read a book it just loses the ordinary durability, the game doesn't even crash or something else.

Why?

Every advice is appreciated (:

image.png.e24c4a46662840fb0c16cc36a2b7c775.png

Link to comment
Share on other sites

After looking into it a bit, it seems that the code that the "efficientuser" component needs inside the "finiteuses" component doesn't run in this specific case, specifically in the OnUsedAsItem() function. It's because books don't use SetConsumption() to set an action and the uses it takes, they instead lose durability manually from the "book" component, in the ConsumeUse() function.

You definitely had a good idea, unfortunately the code can be a bit messy and confusing. I don't know why Klei didn't just go with SetConsumption() for books as well, but perhaps there's something I'm missing.

I tried coding a solution, but I'm not exactly too happy with it. I hooked into the "book" component and made it consume an use again if Maxwell is doing the reading. Maybe that can give you an idea on how to approach this problem, it's up to you!

AddComponentPostInit("book", function(self)
	local _old_interact = self.Interact
	
	function self:Interact(fn, reader, ...)
		local success, reason = _old_interact(self, fn, reader, ...)
		
		if success and reader.prefab == "waxwell" then
			self:ConsumeUse()
		end
		
		return success, reason
	end
end)

 

  • Health 1
Link to comment
Share on other sites

24 minutes ago, ariadnesGambit said:

After looking into it a bit, it seems that the code that the "efficientuser" component needs inside the "finiteuses" component doesn't run in this specific case, specifically in the OnUsedAsItem() function. It's because books don't use SetConsumption() to set an action and the uses it takes, they instead lose durability manually from the "book" component, in the ConsumeUse() function.

You definitely had a good idea, unfortunately the code can be a bit messy and confusing. I don't know why Klei didn't just go with SetConsumption() for books as well, but perhaps there's something I'm missing.

I tried coding a solution, but I'm not exactly too happy with it. I hooked into the "book" component and made it consume an use again if Maxwell is doing the reading. Maybe that can give you an idea on how to approach this problem, it's up to you!

AddComponentPostInit("book", function(self)
	local _old_interact = self.Interact
	
	function self:Interact(fn, reader, ...)
		local success, reason = _old_interact(self, fn, reader, ...)
		
		if success and reader.prefab == "waxwell" then
			self:ConsumeUse()
		end
		
		return success, reason
	end
end)

 

wow it worked!

I don't know how you managed to do it but it actually worked!

Thanks a lot!

  • GL Happy 1
Link to comment
Share on other sites

11 minutes ago, Sacco said:

I don't know how you managed to do it but it actually worked!

I tried explaining my thought process, but if something isn't clear, feel free to ask! I'm more than happy to teach people about modding, it's why I visit this section of the forums.

12 minutes ago, Sacco said:

Thanks a lot!

Any time!

  • Like 1
Link to comment
Share on other sites

11 minutes ago, ariadnesGambit said:

I tried explaining my thought process, but if something isn't clear, feel free to ask! I'm more than happy to teach people about modding, it's why I visit this section of the forums.

Unfortunately i don't know very well how to mod, i am new to this "world" and for this reason i'm posting on the forum to get some needed help.

I'm trying to understand what you wrote but i'm having problems to understand it just because i just don't know how to mod well.

Link to comment
Share on other sites

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
 Share

×
  • Create New...