Jump to content

Recommended Posts

Would it be possible to give a character backpack inventory without having a backpack equipped? Like say when my character goes insane I want him to get that inventory the krampus sack gives without having to equip anything, would that be possible? Of course it would probably conflict with my character being able to wear backpacks if it's possible but I assume the easy fix would just be to remove the ability to equip backpacks for my character when he goes insane.

Anyways, I would really, really love if someone could answer this because this's something i've been wanting to do for a long time but all the times I tried to do it failed... So, it'd be great if someone could actually tell me if this would be possible or not :D.

Thanks for reading my question :D!!!

 

Problem's down below VVV

 

Edited by SuperDavid

why not actually give your character krampus bagback ? And remove it, when sanity is higher again.
But don't forget to save the items in inventory.

Anyway, I don't think this is a good idea. Since it is hard to control the sanity ingame. And suddenly you are loosing items stored in this bag, just because you got some sanity.
And of course you will put your previous bagback down everytime you become insane... this is not very nice gameplay I think.

Edited by Serpens
2 hours ago, Serpens said:

why not actually give your character krampus bagback ? And remove it, when sanity is higher again.
But don't forget to save the items in inventory

The problem's that if I equip him a invisible krampus sack when he goes insane then he won't be able to equip stuff like armor or else the invisible krampus sack would fall off, so that's why I wanted to know if I can just give him the backpack stuff without needing to equip anything...but it seems that may not be possible :(...

I hope it can be possible if only someone would be able to know to tell me xD...

Ah yes... I always play with a mod that allows armor + backpack, that's why I did not thought about armor
steamcommunity.com/sharedfiles/filedetails/?id=496249680

I'm quite sure it is possible, but I don't know how. And I think it will be quite complicated and error prone... so you should think carefully if this is worth the hassle..

Well, I tried adding these codes in my character.lua

inst.components.container:Open(inst)
MakeInventoryPhysics(inst)
inst:AddTag("backpack")
inst:AddComponent("container")
inst.components.container:WidgetSetup("krampus_sack")

and it just crashes the game saying


"[00:00:22]: [string "../mods/Adam DST Mod/scripts/prefabs/adam.l..."]:816: attempt to index field 'container' (a nil value)"

I don't understand why it crashes :(... I'd really appreciate some guidance :D!

Edited by SuperDavid

character.lua:

local function CloseInsaneContainer(inst)
	inst.insanecontainer.components.container:DropEverything()
	inst.insanecontainer.components.container:Close()
end

local function OpenInsaneContainer(inst)
	inst.insanecontainer.components.container:Open(inst)
end

local function AttachInsaneContainer(inst, data)
	if inst.insanecontainer ~= nil then
		inst.insanecontainer:Remove()
		inst.insanecontainer = nil
	end
	inst.insanecontainer = data and SpawnSaveRecord(data.insanecontainer) or SpawnPrefab("insanecontainer")
	inst.insanecontainer.entity:SetParent(inst.entity)
	inst.insanecontainer.entity:AddFollower()
	inst.insanecontainer.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0)
end

local function OnDespawn(inst)
	if inst.insanecontainer ~= nil then
		inst.savedata_insanecontainer = inst.insanecontainer:GetSaveRecord()
		inst.insanecontainer:Remove()
	end
end

local function OnSave(inst, data)
	if inst.insanecontainer ~= nil then
		data.insanecontainer = inst.savedata_insanecontainer or inst.insanecontainer:GetSaveRecord()
	end
end

local function OnLoad(inst, data)
	if data ~= nil and data.insanecontainer ~= nil then
		AttachInsaneContainer(inst, data)
	end
	if inst.components.sanity:IsSane() then
		CloseInsaneContainer(inst)
	else
		OpenInsaneContainer(inst)
	end
end

local function master_postinit(inst)
	AttachInsaneContainer(inst)

	inst.OnDespawn = OnDespawn
	inst.OnSave = OnSave
	inst.OnLoad = OnLoad

	inst:ListenForEvent("gosane", CloseInsaneContainer)
	inst:ListenForEvent("goinsane", OpenInsaneContainer)
end

Merge it properly with your OnSave, OnLoad, OnDespawn functions, if they exist.

Pay attention as my OnSave, OnLoad functions make use of the data argument, so include it if you don't have it.

This code takes care of handling the container.

 

prefabs/insanecontainer.lua:

local data_insanecontainer = {
	widget = {
		slotpos = {},
		animbank = "ui_krampusbag_2x8",
		animbuild = "ui_krampusbag_2x8",
		pos = Vector3(-5, -120, 0),
	},
	issidewidget = true,
	type = "insanepack",
}

for y = 0, 6 do
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162, -75 * y + 240, 0))
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0))
end

local function OnEntityReplicated(inst)
	inst.replica.container:WidgetSetup("insanecontainer", data_insanecontainer)
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddNetwork()

	inst:AddTag("CLASSIFIED")
	inst:AddTag("NOCLICK")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		inst.OnEntityReplicated = OnEntityReplicated
		return inst
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.canbepickedup = false

	inst:AddComponent("container")
	inst.components.container:WidgetSetup("insanecontainer", data_insanecontainer)

	return inst
end

return Prefab("insanecontainer", fn)

This code is the container itself.

It makes use of the data parameter of WidgetSetup to initialize a similar widget to the krampus sack.

 

This can coexist with armor and backpacks.

@DarkXero Wow :D!!! Thank you so, so, so much DarkXero you're so awesome :D!!!! I'm very sorry but i'm getting this crash when I try to start the game, i'm very sorry to bother you so, so much :(...

[00:00:22]: [string "../mods/Adam DST Mod/scripts/prefabs/adam.l..."]:780: attempt to index field 'insanecontainer' (a nil value)
LUA ERROR stack traceback:
    ../mods/Adam DST Mod/scripts/prefabs/adam.lua:780 in (upvalue) AttachInsaneContainer (Lua) <774-783>
    ../mods/Adam DST Mod/scripts/prefabs/adam.lua:842 in (upvalue) master_postinit (Lua) <838-2017>
    scripts/prefabs/player_common.lua:1803 in (field) fn (Lua) <1536-1844>
    scripts/mainfunctions.lua:146 in () ? (Lua) <135-177>

I added the code to go in my character's lua & merged the code with any of the functions that already existed.

And I copied & pasted my character.lua & deleted all the code, renamed it "insanecontainer" & added all the insane container code into it & put it in my prefabs folder but this crash then happened. I'm really sorry I must've done something wrong but I don't what... Please forgive me & thank you so much for making so much code for me :D:D, I really thank you :D:D!!!!!!!!!!!

PS. If you need me to post my character just tell me I do it right away!

Edited by SuperDavid
10 minutes ago, DarkXero said:

Did you add "insanecontainer" to PrefabFiles on modmain?

It works now & it's gorgeous :D!!!!!! Thank you so, so, so, so, so much DarkXero, you should be called the DarkHero of all modders :D:D:D:D!!!!!!

@DarkXero If you have any time to spare anytime could you maybe please help me fix 2 problems with "insanecontainer" :wilson_smile:?

#1 - It happens when my character goes in the darkness for some reason the insanecontainer closes & doesn't get open again until he goes insane again & is in light... Look!

Only DarkXero Can Fix This.gif

#2 - Also, you remember gelid mode? In gelid mode my character's inventory becomes a fridge! Would it be possible if you could also tell me how I make the insanecontainer act as a fridge when it's owner has " act.target.noactualfreezing:set(true) " and when the owner becomes " act.target.noactualfreezing:set(false) " it loses the fridge tag?

I would really, really appreciate your help DarkXero because I have no idea why the container closes in darkness & I have no idea how to make it act as a fridge if the owner has "  act.target.noactualfreezing:set(true) "... So, I beg for your help if you can help me anytime I really, really would be so happy :wilson_cry:!!!

This's all the code she has related to insanecontainer

insanecontainer.lua

local data_insanecontainer = {
	widget = {
		slotpos = {},
		animbank = "ui_krampusbag_2x8",
		animbuild = "ui_krampusbag_2x8",
		pos = Vector3(-5, -120, 0),
	},
	issidewidget = true,
	type = "insanepack",
}

for y = 0, 6 do

table.insert(data_insanecontainer.widget.slotpos, Vector3(-162, -75 * y + 240, 0))
table.insert(data_insanecontainer.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0))

end

local function OnEntityReplicated(inst)

inst.replica.container:WidgetSetup("insanecontainer", data_insanecontainer)

end

local function fn()

local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddNetwork()

inst:AddTag("CLASSIFIED")
inst:AddTag("NOCLICK")

inst.entity:SetPristine()

if not TheWorld.ismastersim then
inst.OnEntityReplicated = OnEntityReplicated
return inst
end

inst:AddComponent("inventoryitem")
inst.components.inventoryitem.canbepickedup = false

inst:AddComponent("container")
inst.components.container:WidgetSetup("insanecontainer", data_insanecontainer)

return inst

end

return Prefab("insanecontainer", fn)

adam.lua

-------------------------------------------------------\
-- All credit for "InsaneContainer" belong to DarkXero! ]
-------------------------------------------------------/
local function CloseInsaneContainer(inst)
	inst.insanecontainer.components.container:DropEverything()
	inst.insanecontainer.components.container:Close()
end


local function OnLoad(inst, data)
	if data ~= nil and data.insanecontainer ~= nil then
	AttachInsaneContainer(inst, data)
	end
	if inst.components.sanity:IsSane() then
	CloseInsaneContainer(inst)
	else
	OpenInsaneContainer(inst)
	end
end

local function OpenInsaneContainer(inst)
	inst.insanecontainer.components.container:Open(inst)
end

local function AttachInsaneContainer(inst, data)
	if inst.insanecontainer ~= nil then
	inst.insanecontainer:Remove()
	inst.insanecontainer = nil
	end
	inst.insanecontainer = data and SpawnSaveRecord(data.insanecontainer) or SpawnPrefab("insanecontainer")
	inst.insanecontainer.entity:SetParent(inst.entity)
	inst.insanecontainer.entity:AddFollower()
	inst.insanecontainer.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0)
end

local function OnDespawn(inst)
	if inst.insanecontainer ~= nil then
	inst.savedata_insanecontainer = inst.insanecontainer:GetSaveRecord()
	inst.insanecontainer:Remove()
	end
end

local function OnSave(inst, data)
	if inst.insanecontainer ~= nil then
	data.insanecontainer = inst.savedata_insanecontainer or inst.insanecontainer:GetSaveRecord()
	end
end

local master_postinit = function(inst)
-- All credit for "InsaneContainer" belong to DarkXero!
AttachInsaneContainer(inst)
inst.OnDespawn = OnDespawn
inst.OnSave = OnSave
inst.OnLoad = OnLoad
inst:ListenForEvent("gosane", CloseInsaneContainer)
inst:ListenForEvent("goinsane", OpenInsaneContainer)
end

 

Edited by SuperDavid
On 12/9/2016 at 4:58 AM, SuperDavid said:

#1 - It happens when my character goes in the darkness for some reason the insanecontainer closes & doesn't get open again until he goes insane again & is in light... Look!

That happens to all containers.

insanecontainer.lua:

local data_insanecontainer = {
	widget = {
		slotpos = {},
		animbank = "ui_krampusbag_2x8",
		animbuild = "ui_krampusbag_2x8",
		pos = Vector3(-5, -120, 0),
	},
	issidewidget = true,
	type = "insanepack",
}

for y = 0, 6 do
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162, -75 * y + 240, 0))
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0))
end

-- new function
local function SpecialClose(inst)
	local container = inst.components.container or inst.replica.container
	local _Close = container.Close
	container.Close = function(self)
		if self.inst:HasTag("cantbeclosed") then
			return
		end
		_Close(self)
	end
end

local function OnEntityReplicated(inst)
	inst.replica.container:WidgetSetup("insanecontainer", data_insanecontainer)
	-- new code
	SpecialClose(inst)
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddNetwork()

	inst:AddTag("CLASSIFIED")
	inst:AddTag("NOCLICK")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		inst.OnEntityReplicated = OnEntityReplicated
		return inst
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.canbepickedup = false

	inst:AddComponent("container")
	inst.components.container:WidgetSetup("insanecontainer", data_insanecontainer)
	-- new code
	SpecialClose(inst)

	return inst
end

return Prefab("insanecontainer", fn)

adam.lua:

local function AttachInsaneContainer(inst, data)
	if inst.insanecontainer ~= nil then
		inst.insanecontainer:Remove()
		inst.insanecontainer = nil
	end
	inst.insanecontainer = data and SpawnSaveRecord(data.insanecontainer) or SpawnPrefab("insanecontainer")
	inst.insanecontainer.entity:SetParent(inst.entity)
	inst.insanecontainer.entity:AddFollower()
	inst.insanecontainer.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0)
end

local function CloseInsaneContainer(inst)
	-- new code
	inst.insanecontainer:RemoveTag("cantbeclosed")
	inst.insanecontainer.components.container:DropEverything()
	inst.insanecontainer.components.container:Close()
end

local function OpenInsaneContainer(inst)
	inst.insanecontainer.components.container:Open(inst)
	-- new code
	inst.insanecontainer:AddTag("cantbeclosed")
end

local function OnLoad(inst, data)
	if data ~= nil and data.insanecontainer ~= nil then
		AttachInsaneContainer(inst, data)
	end
	if inst.components.sanity:IsSane() then
		CloseInsaneContainer(inst)
	else
		OpenInsaneContainer(inst)
	end
end

local function OnDespawn(inst)
	if inst.insanecontainer ~= nil then
		inst.savedata_insanecontainer = inst.insanecontainer:GetSaveRecord()
		inst.insanecontainer:Remove()
	end
end

local function OnSave(inst, data)
	if inst.insanecontainer ~= nil then
		data.insanecontainer = inst.savedata_insanecontainer or inst.insanecontainer:GetSaveRecord()
	end
end

local master_postinit = function(inst)
	AttachInsaneContainer(inst)
	inst.OnDespawn = OnDespawn
	inst.OnSave = OnSave
	inst.OnLoad = OnLoad
	inst:ListenForEvent("gosane", CloseInsaneContainer)
	inst:ListenForEvent("goinsane", OpenInsaneContainer)
end

This should do it.

On 12/9/2016 at 4:58 AM, SuperDavid said:

#2 - Also, you remember gelid mode? In gelid mode my character's inventory becomes a fridge! Would it be possible if you could also tell me how I make the insanecontainer act as a fridge when it's owner has " act.target.noactualfreezing:set(true) " and when the owner becomes " act.target.noactualfreezing:set(false) " it loses the fridge tag?

local function common_postinit(inst)
	-- add "noactualfreezingdirty" to inst.noactualfreezing so we have an event to listen to
	inst.noactualfreezing = net_bool(inst.GUID, "player.noactualfreezing", "noactualfreezingdirty")
end

local function ApplyFridgeTag(inst)
	if inst.noactualfreezing:value() then
		inst.insanecontainer:AddTag("fridge")
	else
		inst.insanecontainer:RemoveTag("fridge")
	end
end

local function master_postinit(inst)
	-- after the container is attached
	AttachInsaneContainer(inst)
	-- listen to event pushed when the net variable changes
	inst:ListenForEvent("noactualfreezingdirty", ApplyFridgeTag)
end

 

@DarkXero I'm sorry to bother you but i'm having trouble with making the insanecontainer fridge part..

So, I added the code like this but when I try to log into a world it instant crashes & there's nothing in the log :shock:!

local function common_postinit(inst)
NoGelidFreezing(inst) -- When I remove this code the game doesn't crash instantly
inst:AddTag("perfect")
inst:AddComponent("keyhandler")
inst.MiniMapEntity:SetIcon("adam.tex")
inst:ListenForEvent("keypressed", OnKeyPressed)
inst.noactualfreezing = net_bool(inst.GUID, "player.noactualfreezing", "noactualfreezingdirty")
inst.components.frostybreather.gelidbreath = net_bool(inst.GUID, "player.gelidbreath", "gelidbreathdirty")
inst.components.frostybreather.gelidbreath:set(false)
inst:ListenForEvent("gelidbreathdirty", GelidFrostyBreather)
end

function ApplyFridgeTag(inst)
	if inst.noactualfreezing:value() then
	inst.insanecontainer:AddTag("fridge")
    else
	inst.insanecontainer:RemoveTag("fridge")
end
end
local master_postinit = function(inst)

AttachInsaneContainer(inst)
AttachInsaneContainer(inst)
inst.OnDespawn = OnDespawn
inst.OnSave = OnSave
inst.OnLoad = OnLoad
inst:ListenForEvent("gosane", CloseInsaneContainer)
inst:ListenForEvent("goinsane", OpenInsaneContainer)
inst:ListenForEvent("noactualfreezingdirty", ApplyFridgeTag)


inst:ListenForEvent("firedamage", function(inst, data)
if not inst.components.health:IsDead() and inst.gelid_mode == true then -- Break Gelid mode when take fire damage.
inst.gelid_mode = nil
inst:RemoveTag("fridge")
inst.sg:GoToState("hit")
inst.noactualfreezing:set(false, "noactualfreezingdirty")
end
end

The code when I remove crash goes away.

local function NoGelidFreezing(inst)
	inst.noactualfreezing = net_bool(inst.GUID, "player.noactualfreezing")
	inst.noactualfreezing:set(false)
	local _IsFreezing = inst.IsFreezing
	inst.IsFreezing = function(inst)
	if inst.noactualfreezing:value() then
	return false
	end
	return _IsFreezing(inst)
	end
end

 

 

Also, by 

3 hours ago, DarkXero said:

-- add "noactualfreezingdirty" to inst.noactualfreezing so we have an event to listen to

you mean something like  " inst.noactualfreezing:set(true, "noactualfreezingdirty") " &  " inst.noactualfreezing:set(false, "noactualfreezingdirty") " right?

Edited by SuperDavid
local function NoGelidFreezing(inst)
	inst.noactualfreezing = net_bool(inst.GUID, "player.noactualfreezing", "noactualfreezingdirty")
	inst.noactualfreezing:set(false)
	local _IsFreezing = inst.IsFreezing
	inst.IsFreezing = function(inst)
		if inst.noactualfreezing:value() then
			return false
		end
		return _IsFreezing(inst)
	end
end

local function common_postinit(inst)
	NoGelidFreezing(inst)

	inst:AddTag("perfect")
	inst:AddComponent("keyhandler")
	inst.MiniMapEntity:SetIcon("adam.tex")
	inst:ListenForEvent("keypressed", OnKeyPressed)

	inst.components.frostybreather.gelidbreath = net_bool(inst.GUID, "player.gelidbreath", "gelidbreathdirty")
	inst.components.frostybreather.gelidbreath:set(false)
	inst:ListenForEvent("gelidbreathdirty", GelidFrostyBreather)
end

local function ApplyFridgeTag(inst)
	if inst.noactualfreezing:value() then
		inst.insanecontainer:AddTag("fridge")
    else
		inst.insanecontainer:RemoveTag("fridge")
	end
end

local function OnTakingFireDamage(inst, data)
	if not inst.components.health:IsDead() and inst.gelid_mode == true then
		inst.gelid_mode = nil
		inst:RemoveTag("fridge")
		inst.sg:GoToState("hit")
		inst.noactualfreezing:set(false)
	end
end

local function master_postinit(inst)
	AttachInsaneContainer(inst)
	inst.OnDespawn = OnDespawn
	inst.OnSave = OnSave
	inst.OnLoad = OnLoad

	inst:ListenForEvent("gosane", CloseInsaneContainer)
	inst:ListenForEvent("goinsane", OpenInsaneContainer)
	inst:ListenForEvent("noactualfreezingdirty", ApplyFridgeTag)
	inst:ListenForEvent("firedamage", OnTakingFireDamage)
end

 

@DarkXero ..................I'm so, so, so, sorry DarkXero for bothering you for the third time :wilson_facepalm:....but there's nothing else I can do.....

For some reason the InsaneContainer doesn't close anymore when I become sane!

HELP.gif

I will once again show you all the code I have for InsaneContainer because I must've done something wrong :wilson_facepalm:...........

 

EDIT: I found out that the InsaneContainer closes properly on worlds without a cave but on worlds with caves the InsaneContainer never closes :shock:!

 

 

insanecontainer.lua

local data_insanecontainer = {
	widget = {
	slotpos = {},
	animbank = "ui_krampusbag_2x8",
	animbuild = "ui_krampusbag_2x8",
	pos = Vector3(-5, -120, 0),
	},
	issidewidget = true,
	type = "insanepack",
}

for y = 0, 6 do
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162, -75 * y + 240, 0))
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0))
end

local function SpecialClose(inst)
	local container = inst.components.container or inst.replica.container
	local _Close = container.Close
	container.Close = function(self)
	if self.inst:HasTag("cantbeclosed") then
	return
	end
	_Close(self)
	end
end

local function OnEntityReplicated(inst)
	inst.replica.container:WidgetSetup("insanecontainer", data_insanecontainer)
	SpecialClose(inst)
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddNetwork()

	inst:AddTag("CLASSIFIED")
	inst:AddTag("NOCLICK")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
	inst.OnEntityReplicated = OnEntityReplicated
	return inst
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.canbepickedup = false

	inst:AddComponent("container")
	inst.components.container:WidgetSetup("insanecontainer", data_insanecontainer)
	
	SpecialClose(inst)

	return inst
end

return Prefab("insanecontainer", fn)

 

 

adam.lua

local function AttachInsaneContainer(inst, data)
	if inst.insanecontainer ~= nil then
	inst.insanecontainer:Remove()
	inst.insanecontainer = nil
	end
	inst.insanecontainer = data and SpawnSaveRecord(data.insanecontainer) or SpawnPrefab("insanecontainer")
	inst.insanecontainer.entity:SetParent(inst.entity)
	inst.insanecontainer.entity:AddFollower()
	inst.insanecontainer.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0)
end

local function CloseInsaneContainer(inst)
	inst.insanecontainer:RemoveTag("cantbeclosed")
	inst.insanecontainer.components.container:DropEverything()
	inst.insanecontainer.components.container:Close()
end

local function OpenInsaneContainer(inst)
	inst.insanecontainer.components.container:Open(inst)
	inst.insanecontainer:AddTag("cantbeclosed")
end

local function OnLoad(inst, data)
	if data ~= nil and data.insanecontainer ~= nil then
	AttachInsaneContainer(inst, data)
	end
	if inst.components.sanity:IsSane() then
	CloseInsaneContainer(inst)
	else
	OpenInsaneContainer(inst)
	end
end

local function OnDespawn(inst)
	if inst.insanecontainer ~= nil then
	inst.savedata_insanecontainer = inst.insanecontainer:GetSaveRecord()
	inst.insanecontainer:Remove()
	end
end

local function OnSave(inst, data)
	if inst.insanecontainer ~= nil then
	data.insanecontainer = inst.savedata_insanecontainer or inst.insanecontainer:GetSaveRecord()
	end
end

local function NoGelidFreezing(inst)
inst.noactualfreezing = net_bool(inst.GUID, "player.noactualfreezing", "noactualfreezingdirty")
inst.noactualfreezing:set(false)
local _IsFreezing = inst.IsFreezing
inst.IsFreezing = function(inst)
if inst.noactualfreezing:value() then
return false
end
return _IsFreezing(inst)
end
end

local function common_postinit(inst)
NoGelidFreezing(inst)

inst:AddTag("perfect")
inst:AddComponent("keyhandler")
inst.MiniMapEntity:SetIcon("adam.tex")
inst:ListenForEvent("keypressed", OnKeyPressed)

inst.components.frostybreather.gelidbreath = net_bool(inst.GUID, "player.gelidbreath", "gelidbreathdirty")
inst.components.frostybreather.gelidbreath:set(false)
inst:ListenForEvent("gelidbreathdirty", GelidFrostyBreather)
end

local function ApplyFridgeTag(inst)
if inst.noactualfreezing:value() then
inst.insanecontainer:AddTag("fridge")
else
inst.insanecontainer:RemoveTag("fridge")
end
end

local function FireBreakGelid(inst, data)
if not inst.components.health:IsDead() and inst.gelid_mode == true then -- Break Gelid mode when take fire damage.
inst.gelid_mode = nil
inst:RemoveTag("fridge")
inst.sg:GoToState("hit")
inst.noactualfreezing:set(false)
inst.components.sanity:DoDelta(-15)
inst.components.health:DoDelta(-30)
inst.components.hunger:DoDelta(-15)
inst.components.temperature.hurtrate = 4
inst.components.temperature.maxtemp = 100
inst.components.freezable:SetResistance(1)
inst.components.freezable:SpawnShatterFX(4)
inst.components.freezable:StartWearingOff(10)
inst.components.combat.min_attack_period = 0.1
inst.components.talker:Say(GetString(inst, "ANNOUNCE_GELID_BREAK"))
end
end


local master_postinit = function(inst)
AttachInsaneContainer(inst)
inst.OnDespawn = OnDespawn
inst.OnSave = OnSave
inst.OnLoad = OnLoad

inst:ListenForEvent("gosane", CloseInsaneContainer)
inst:ListenForEvent("goinsane", OpenInsaneContainer)
inst:ListenForEvent("noactualfreezingdirty", ApplyFridgeTag)
inst:ListenForEvent("firedamage", FireBreakGelid)
end

 

Edited by SuperDavid
9 hours ago, SuperDavid said:

EDIT: I found out that the InsaneContainer closes properly on worlds without a cave but on worlds with caves the InsaneContainer never closes :shock:!

insanecontainer.lua:

local data_insanecontainer = {
	widget = {
	slotpos = {},
	animbank = "ui_krampusbag_2x8",
	animbuild = "ui_krampusbag_2x8",
	pos = Vector3(-5, -120, 0),
	},
	issidewidget = true,
	type = "insanepack",
}

for y = 0, 6 do
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162, -75 * y + 240, 0))
	table.insert(data_insanecontainer.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0))
end

local function SpecialClose(inst)
	local container = inst.components.container or inst.replica.container
	local _Close = container.Close
	container.Close = function(self)
		if self.inst:HasTag("cantbeclosed") then
			return
		end
		_Close(self)
	end
end

local function CloseIt(inst)
	inst.replica.container:Close()
end

local function OnEntityReplicated(inst)
	inst.replica.container:WidgetSetup("insanecontainer", data_insanecontainer)
	SpecialClose(inst)
	inst:ListenForEvent("closepls", CloseIt)
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddNetwork()

	inst:AddTag("CLASSIFIED")
	inst:AddTag("NOCLICK")

	inst.closepls = net_event(inst.GUID, "closepls")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		inst.OnEntityReplicated = OnEntityReplicated
		return inst
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.canbepickedup = false

	inst:AddComponent("container")
	inst.components.container:WidgetSetup("insanecontainer", data_insanecontainer)
	
	SpecialClose(inst)

	return inst
end

return Prefab("insanecontainer", fn)

adam.lua:

-- new function
local function CloseInsaneContainer(inst)
	inst.insanecontainer:RemoveTag("cantbeclosed")
	inst.insanecontainer.components.container:DropEverything()
	inst.insanecontainer.components.container:Close()
	inst.insanecontainer.closepls:push()
end

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