Jump to content

HELP! Perk to carry more!


Recommended Posts

I need help adding a perk that raises the carry limit to items. I added a code but i think it's applying for the whole server, which causes it to crash for other characters with item limits. Can anyone give me a code that increases item stacks on the modded character only? I want to raise each type of item size stack by 10 items more. Also, where do I put the code?

old code:

function stackPrefabPostInit(inst)

    inst.components.stackable.maxsize = 50

end

function makestackablePrefabPostInit(inst)

    inst:AddComponent("stackable")
        inst.components.stackable.maxsize = 50

end

TUNING.STACK_SIZE_LARGEITEM = 20
TUNING.STACK_SIZE_MEDITEM = 30
TUNING.STACK_SIZE_SMALLITEM = 50

Link to comment
Share on other sites

5 minutes ago, zUsername said:

Open modmain then add this code;


GLOBAL.TUNING.STACK_SIZE_LARGEITEM = 20
GLOBAL.TUNING.STACK_SIZE_MEDITEM = 30
GLOBAL.TUNING.STACK_SIZE_SMALLITEM = 50 

 

This would change stack sizes for the whole server.

@Boot What you want to do, is check when your character is putting a stackable item to inventory, and then change its max stack size. Also you'd need to change max stack size when you're dropping the item. Not sure how this would work (since you can have stack of let's say, 60 items and stack gets reduced to 40 when you drop it), but I guess you'll have to find some workarounds for this.

Code it in your character's prefab, not in modmain.

Link to comment
Share on other sites

In your modmain:

local function test(self)
	local _OnPutInInventory = self.OnPutInInventory
	self.OnPutInInventory = function(self, owner)
		if owner ~= nil and owner.prefab == "yourcharacter" then
			if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and not self.inst.replica.stackable.newsize then
				self.inst.replica.stackable.newsize = true
				self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize + 10
			end
		end
		return _OnPutInInventory(self, owner)
	end
	local _OnDropped = self.OnDropped
	self.OnDropped = function(self, randomdir)
		if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and self.inst.replica.stackable.newsize then
			self.inst.replica.stackable.newsize = false
			self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize - 10
			if self.inst.components.stackable.stacksize > self.inst.components.stackable.maxsize then 
				self.inst.components.stackable.stacksize = self.inst.components.stackable.maxsize
			end
		end
		return _OnDropped(self, randomdir)
	end
end
AddComponentPostInit("inventoryitem", test)

Copy stackable_replica.lua from data\scripts\components to yourmod/scripts/components then add this code:

local STACK_NEWSIZES = {30,50,20,}
local STACK_NEWSIZES_CODES = table.invert(STACK_NEWSIZES)

Then replace _ctor, SetMaxSize, MaxSize function to the code I give here:

local Stackable = Class(function(self, inst)
    self.inst = inst
	self.newsize = false
    self._stacksize = net_smallbyte(inst.GUID, "stackable._stacksize", "stacksizedirty")
    self._maxsize = net_tinybyte(inst.GUID, "stackable._maxsize")
end)

function Stackable:SetMaxSize(maxsize)
	if self.newsize then
		self._maxsize:set(STACK_NEWSIZES_CODES[maxsize] - 1)
	else
		self._maxsize:set(STACK_SIZE_CODES[maxsize] - 1)
	end
end

function Stackable:MaxSize()
	if self.newsize then
		return STACK_NEWSIZES[self._maxsize:value() + 1]
	else
		return STACK_SIZES[self._maxsize:value() + 1]
	end
end

 

Edited by zUsername
Link to comment
Share on other sites

4 hours ago, zUsername said:

 

Copy stackable_replica.lua from data\scripts\components to yourmod/scripts/components

Replacing whole files increases the chances of your mod being incompatible with future updates of DST and other mods that touch that file. Just sayin'.

Link to comment
Share on other sites

9 minutes ago, Muche said:

Replacing whole files increases the chances of your mod being incompatible with future updates of DST and other mods that touch that file. Just sayin'.

Yes I'm know. But I've tried AddComponentPostInit but it's crashes, don't know it can or not overriding replica with AddComponentPostInit.

Link to comment
Share on other sites

So what do I do? ;_; Is it really so difficult to increase item limit for a character?

Maybe it's easier to make an item like a backpack with more slots? In this case though, it should only be able to be picked up by my character. It can be dropped, but the only one that could pick it up is the character.

Link to comment
Share on other sites

1 minute ago, zUsername said:

Example: cutgrass have max stack is 40. If character picked up cutgrass is your character, the code will increase cutgrass max stack to 50.

But if I drop the stack of 50 and pick it up, will it still be 50? If I drop the stack of 50 and someone else picks it up, will they get 40 and 10? Or will it delete that extra 10 I harvested?

Link to comment
Share on other sites

Okay but... I copied the info from the stackable replica but in my mod character folder in the scripts folder, there is no "components."
(oh you mean copy the actual file. okay I did this, but in the scripts folder there is no components folder)

Edited by Boot
Link to comment
Share on other sites

First add this code to modmain.lua

local function test(self)
	local _OnPutInInventory = self.OnPutInInventory
	self.OnPutInInventory = function(self, owner)
		if owner ~= nil and owner.prefab == "yourcharacter" then
			if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and not self.inst.replica.stackable.newsize then
				self.inst.replica.stackable.newsize = true
				self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize + 10
			end
		end
		return _OnPutInInventory(self, owner)
	end
	local _OnDropped = self.OnDropped
	self.OnDropped = function(self, randomdir)
		if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and self.inst.replica.stackable.newsize then
			self.inst.replica.stackable.newsize = false
			self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize - 10
			if self.inst.components.stackable.stacksize > self.inst.components.stackable.maxsize then 
				self.inst.components.stackable.stacksize = self.inst.components.stackable.maxsize
			end
		end
		return _OnDropped(self, randomdir)
	end
end
AddComponentPostInit("inventoryitem", test)

Second download attachment file.

Third move downloaded attachment file to yourmod/scripts/components

stackable_replica.lua

Link to comment
Share on other sites

Okay. I did your coding and it seems to work fine. BUT! When I then try to load another character(wilderness mode), the server crashes. This is the error ((the same error I had before I changed any coding to the suggestions here also, btw))
 

error stacks.png

Edited by Boot
Link to comment
Share on other sites

...Is there no way to do this for only my modded character and not for the server? Maybe something to do with "local"....? This stackable coding interferes with other mods that have custom items with custom stacks (if somebody joins as the character Sans, the whole server crashes).

Link to comment
Share on other sites

    try add this code above:

if not GLOBAL.TheWorld.ismastersim then
        return inst
    end

 

local function test(self)
	if not GLOBAL.TheWorld.ismastersim then 
		return
	end
	local _OnPutInInventory = self.OnPutInInventory
	self.OnPutInInventory = function(self, owner)
		if owner ~= nil and owner.prefab == "yourcharacter" then
			if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and not self.inst.replica.stackable.newsize then
				self.inst.replica.stackable.newsize = true
				self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize + 10
			end
		end
		return _OnPutInInventory(self, owner)
	end
	local _OnDropped = self.OnDropped
	self.OnDropped = function(self, randomdir)
		if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and self.inst.replica.stackable.newsize then
			self.inst.replica.stackable.newsize = false
			self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize - 10
			if self.inst.components.stackable.stacksize > self.inst.components.stackable.maxsize then 
				self.inst.components.stackable.stacksize = self.inst.components.stackable.maxsize
			end
		end
		return _OnDropped(self, randomdir)
	end
end
AddComponentPostInit("inventoryitem", test)

 

Link to comment
Share on other sites

21 hours ago, zUsername said:

    try add this code above:

if not GLOBAL.TheWorld.ismastersim then
        return inst
    end

 


local function test(self)
	if not GLOBAL.TheWorld.ismastersim then 
		return
	end
	local _OnPutInInventory = self.OnPutInInventory
	self.OnPutInInventory = function(self, owner)
		if owner ~= nil and owner.prefab == "yourcharacter" then
			if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and not self.inst.replica.stackable.newsize then
				self.inst.replica.stackable.newsize = true
				self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize + 10
			end
		end
		return _OnPutInInventory(self, owner)
	end
	local _OnDropped = self.OnDropped
	self.OnDropped = function(self, randomdir)
		if self.inst.components.stackable ~= nil and self.inst.replica.stackable ~= nil and self.inst.replica.stackable.newsize then
			self.inst.replica.stackable.newsize = false
			self.inst.components.stackable.maxsize = self.inst.components.stackable.maxsize - 10
			if self.inst.components.stackable.stacksize > self.inst.components.stackable.maxsize then 
				self.inst.components.stackable.stacksize = self.inst.components.stackable.maxsize
			end
		end
		return _OnDropped(self, randomdir)
	end
end
AddComponentPostInit("inventoryitem", test)

 

I tried adding this but it didn't do anything. The AddComponentPostInit at the end crashed me saying it wasn't declared. 

Edited by Boot
trying again...
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...