Jump to content

Recommended Posts

this mod is the packing box that can move structure(first pack, then move to sp, finally unpack), modified by myself.

lots of people comment to me that when the game rollback to the previous save, the action of the unpack is misfunctional.  

After reviewing the code, i guess is the data do not restore when onload, so has impact on the unpack action.

 

here is the code of save part:


function Package:OnSave()
    return
    {
		content = self.content ~= nil and self.content.GUID or nil,
    },
    {
        self.content ~= nil and self.content.GUID or nil,
    }
end

function Package:LoadPostPass(newents, savedata)
    if savedata.content ~= nil then
        local content = newents[savedata.content]
        if content ~= nil then
            self.content = content.entity
        end
    end
end

-- rewrite the save/load code above, 'cause the rollback bug?

content is the entity of structure being packed. 

 

and here is the misfunctional action of unpack (seems the content is nil after rollback), this function exit on the first "return" or even return on the first "if"

local UNPACK = AddAction("UNPACK", "Unpack", function(act)
	if act.target.components.package.content ~= nil then
		if act.target.components.burnable ~= nil then
			if act.target.components.burnable:IsBurning() or act.target.components.burnable:IsSmoldering() then
				return false
			end
		end

		-- JC: should use: CanDeployRecipeAtPoint?
		local recipe = GLOBAL.GetValidRecipe(act.target.components.package.content.prefab)
		if recipe ~= nil then 
			local x, y, z = act.target.Transform:GetWorldPosition()
			local ents = TheSim:FindEntities(x, y, z, recipe.min_spacing, nil, 0, {"structure"})
			if GLOBAL.next(ents) ~= nil then
				return false, "NOROOM"
			end
		end
	
		act.target.components.package:Unpack(act.doer)
		return true
	end
end)
UNPACK.priority = 4

 

i try a lot of times but cannot make the bug appear. Most people says like that, so it may not be unreal;

Really appreciating to everybody's help and your time spent !

 

mode link is :

https://steamcommunity.com/sharedfiles/filedetails/?id=2972042646

mod files are

modmain.lua moving_box.lua package.lua

Edited by JChanger
6 hours ago, JChanger said:

this mod is the packing box that can move structure(first pack, then move to sp, finally unpack), modified by myself.

lots of people comment to me that when the game rollback to the previous save, the action of the unpack is misfunctional.  

After reviewing the code, i guess is the data do not restore when onload, so has impact on the unpack action.

 

here is the code of save part:


function Package:OnSave()
    return
    {
		content = self.content ~= nil and self.content.GUID or nil,
    },
    {
        self.content ~= nil and self.content.GUID or nil,
    }
end

function Package:LoadPostPass(newents, savedata)
    if savedata.content ~= nil then
        local content = newents[savedata.content]
        if content ~= nil then
            self.content = content.entity
        end
    end
end

-- rewrite the save/load code above, 'cause the rollback bug?

content is the entity of structure being packed. 

 

and here is the misfunctional action of unpack (seems the content is nil after rollback), this function exit on the first "return" or even return on the first "if"

local UNPACK = AddAction("UNPACK", "Unpack", function(act)
	if act.target.components.package.content ~= nil then
		if act.target.components.burnable ~= nil then
			if act.target.components.burnable:IsBurning() or act.target.components.burnable:IsSmoldering() then
				return false
			end
		end

		-- JC: should use: CanDeployRecipeAtPoint?
		local recipe = GLOBAL.GetValidRecipe(act.target.components.package.content.prefab)
		if recipe ~= nil then 
			local x, y, z = act.target.Transform:GetWorldPosition()
			local ents = TheSim:FindEntities(x, y, z, recipe.min_spacing, nil, 0, {"structure"})
			if GLOBAL.next(ents) ~= nil then
				return false, "NOROOM"
			end
		end
	
		act.target.components.package:Unpack(act.doer)
		return true
	end
end)
UNPACK.priority = 4

 

i try a lot of times but cannot make the bug appear. Most people says like that, so it may not be unreal;

Really appreciating to everybody's help and your time spent !

 

mode link is :

https://steamcommunity.com/sharedfiles/filedetails/?id=2972042646

mod files are

modmain.lua 23.12 kB · 0 downloads moving_box.lua 8.16 kB · 0 downloads package.lua 9.18 kB · 0 downloads

That bug appears when you put it in the backpack, I'm not good at coding so I can't help further

On 6/23/2024 at 10:58 PM, Haruhi Kawaii said:

That bug appears when you put it in the backpack, I'm not good at coding so I can't help further

thanks for offering help, i'll try it this weekend~

again lots of thanks~

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...