Jump to content

Inventoryimage problems. Again x_x


Recommended Posts

Edit: Opps, a friend reminded me of something I forgot awhile ago and found the problem. Im silly.

 

Well regardless the problem is solved now but I'll continue bumping this thread for my custom chester problems.

 

The inventoryimages:

k927tTj.png

 

 

The custom eyebone:

local assets ={    Asset("ANIM", "anim/dogoo_eyebone.zip"),    Asset("ANIM", "anim/dogoo_eyebone_build.zip"),    Asset("ANIM", "anim/dogoo_eyebone_snow_build.zip"),    Asset("ANIM", "anim/dogoo_eyebone_shadow_build.zip"),}local SPAWN_DIST = 30local function OpenEye(inst)    inst.isOpenEye = true    inst.components.inventoryitem:ChangeImageName(inst.openEye)endlocal function CloseEye(inst)    inst.isOpenEye = nil    inst.components.inventoryitem:ChangeImageName(inst.closedEye)endlocal function RefreshEye(inst)    if inst.isOpenEye then        OpenEye(inst)    else        CloseEye(inst)    endendlocal function MorphShadowEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_shadow_build")    inst.openEye = "dogoo_eyebone_shadow"    inst.closedEye = "dogoo_eyebone_closed_shadow"    RefreshEye(inst)    inst.EyeboneState = "SHADOW"endlocal function MorphSnowEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_snow_build")    inst.openEye = "dogoo_eyebone_snow"    inst.closedEye = "dogoo_eyebone_closed_snow"    RefreshEye(inst)    inst.EyeboneState = "SNOW"end--[[local function MorphNormalEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_build")    inst.openEye = "dogoo_eyebone"    inst.closedEye = "dogoo_eyebone_closed"        RefreshEye(inst)    inst.EyeboneState = "NORMAL"end]]local function GetSpawnPoint(pt)    local theta = math.random() * 2 * PI    local radius = SPAWN_DIST    local offset = FindWalkableOffset(pt, theta, radius, 12, true)    return offset ~= nil and (pt + offset) or nilendlocal function SpawnDogoo(inst)	if not inst.owner then		print("Error: Eyebone has no linked player!")		return	end    --print("dogoo_eyebone - SpawnDogoo")    local pt = inst:GetPosition()    --print("    near", pt)            local spawn_pt = GetSpawnPoint(pt)    if spawn_pt ~= nil then        --print("    at", spawn_pt)        local dogoo = SpawnPrefab("personal_dogoo")        if dogoo ~= nil then            dogoo.Physics:Teleport(spawn_pt:Get())            dogoo:FacePoint(pt:Get())			if inst.owner then				inst.owner.dogoo = dogoo			end            return dogoo        end    --else        -- this is not fatal, they can try again in a new location by picking up the bone again        --print("dogoo_eyebone - SpawnDogoo: Couldn't find a suitable spawn point for dogoo")    endendlocal StartRespawnlocal function StopRespawn(inst)    --print("dogoo_eyebone - StopRespawn")    if inst.respawntask ~= nil then        inst.respawntask:Cancel()        inst.respawntask = nil        inst.respawntime = nil    endendlocal function RebindDogoo(inst, dogoo)    dogoo = dogoo or (inst.owner and inst.owner.dogoo)    if dogoo ~= nil then		if inst.owner then			dogoo.components.named:SetName(inst.owner.name.."'s Dogoo")		end        inst.AnimState:PlayAnimation("idle_loop", true)        OpenEye(inst)        inst:ListenForEvent("death", function()			if inst.owner then				inst.owner.dogoo = nil			end			StartRespawn(inst, TUNING.CHESTER_RESPAWN_TIME)		end, dogoo)        if dogoo.components.follower.leader ~= inst then            dogoo.components.follower:SetLeader(inst)        end        return true    endendlocal function RespawnDogoo(inst)    --print("dogoo_eyebone - RespawnDogoo")    StopRespawn(inst)    RebindDogoo(inst, (inst.owner and inst.owner.dogoo) or SpawnDogoo(inst))endStartRespawn = function(inst, time)    StopRespawn(inst)    time = time or 0    inst.respawntask = inst:DoTaskInTime(time, RespawnDogoo)    inst.respawntime = GetTime() + time    inst.AnimState:PlayAnimation("dead", true)    CloseEye(inst)endlocal function FixDogoo(inst)	inst.fixtask = nil	--take an existing dogoo if there is one	if not RebindDogoo(inst) then        inst.AnimState:PlayAnimation("dead", true)        CloseEye(inst)				if inst.components.inventoryitem.owner ~= nil then			local time_remaining = 0			local time = GetTime()			if inst.respawntime and inst.respawntime > time then				time_remaining = inst.respawntime - time					end			StartRespawn(inst, time_remaining)		end	endendlocal function OnPutInInventory(inst)    if inst.fixtask == nil then        inst.fixtask = inst:DoTaskInTime(1, FixDogoo)    endendlocal function OnSave(inst, data)    --print("dogoo_eyebone - OnSave")    --data.EyeboneState = inst.EyeboneState    if inst.respawntime ~= nil then        local time = GetTime()        if inst.respawntime > time then            data.respawntimeremaining = inst.respawntime - time        end    endendlocal function OnLoad(inst, data)    if data == nil then        return    end    if data.EyeboneState == "SHADOW" then        MorphShadowEyebone(inst)    elseif data.EyeboneState == "SNOW" then        MorphSnowEyebone(inst)    end    if data.respawntimeremaining ~= nil then        inst.respawntime = data.respawntimeremaining + GetTime()    endendlocal function GetStatus(inst)    --print("smallbird - GetStatus")    if inst.respawntask ~= nil then        return "WAITING"    endendlocal function fn()    local inst = CreateEntity()    inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddNetwork()    --so I can find the thing while testing    --inst.entity:AddMiniMapEntity()    --inst.MiniMapEntity:SetIcon("treasure.png")    MakeInventoryPhysics(inst)    inst:AddTag("personal_dogoo_eyebone")    inst:AddTag("irreplaceable")    inst:AddTag("nonpotatable")	    inst:AddTag("_named")    inst.AnimState:SetBank("eyebone")    inst.AnimState:SetBuild("dogoo_eyebone_build")    inst.AnimState:PlayAnimation("idle_loop", true)    inst.entity:SetPristine()    if not TheWorld.ismastersim then        return inst    end		-- Dogoo will not be saved normally. He is saved with the player.	inst.persists = false    inst:AddComponent("inventoryitem")    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)    inst.EyeboneState = "NORMAL"    inst.openEye = "dogoo_eyebone"    inst.closedEye = "dogoo_eyebone_closed"    inst.isOpenEye = nil    OpenEye(inst)    inst:AddComponent("inspectable")    inst.components.inspectable.getstatus = GetStatus    inst.components.inspectable:RecordViews()    inst.components.inspectable.nameoverride = "dogoo_eyebone"    inst:AddComponent("leader")		    inst:AddComponent("named")    MakeHauntableLaunch(inst)    --inst.MorphNormalEyebone = MorphNormalEyebone    inst.MorphSnowEyebone = MorphSnowEyebone    inst.MorphShadowEyebone = MorphShadowEyebone    inst.OnLoad = OnLoad    inst.OnSave = OnSave    inst.fixtask = inst:DoTaskInTime(1, FixDogoo)	inst.RebindDogoo = RebindDogoo    return instendreturn Prefab("common/inventory/personal_dogoo_eyebone", fn, assets)

 

 

dogoo inventory.zip

Edited by rons0n
Link to comment
Share on other sites

@rons0n,

local assets ={    Asset("ANIM", "anim/dogoo_eyebone.zip"),    Asset("ANIM", "anim/dogoo_eyebone_build.zip"),    Asset("ANIM", "anim/dogoo_eyebone_snow_build.zip"),    Asset("ANIM", "anim/dogoo_eyebone_shadow_build.zip"),		Asset("ATLAS", "images/inventoryimages/dogoo_eyebone.xml"),	Asset("ATLAS", "images/inventoryimages/dogoo_eyebone_closed.xml"),	Asset("ATLAS", "images/inventoryimages/dogoo_eyebone_snow.xml"),	Asset("ATLAS", "images/inventoryimages/dogoo_eyebone_closed_snow.xml"),	Asset("ATLAS", "images/inventoryimages/dogoo_eyebone_shadow.xml"),	Asset("ATLAS", "images/inventoryimages/dogoo_eyebone_closed_shadow.xml"),} local SPAWN_DIST = 30 local function OpenEye(inst)    inst.isOpenEye = true	inst.components.inventoryitem.atlasname = "images/inventoryimages/"..inst.openEye..".xml"    inst.components.inventoryitem:ChangeImageName(inst.openEye)end local function CloseEye(inst)    inst.isOpenEye = nil	inst.components.inventoryitem.atlasname = "images/inventoryimages/"..inst.closedEye..".xml"    inst.components.inventoryitem:ChangeImageName(inst.closedEye)end local function RefreshEye(inst)    if inst.isOpenEye then        OpenEye(inst)    else        CloseEye(inst)    endend local function MorphShadowEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_shadow_build")     inst.openEye = "dogoo_eyebone_shadow"    inst.closedEye = "dogoo_eyebone_closed_shadow"    RefreshEye(inst)     inst.EyeboneState = "SHADOW"end local function MorphSnowEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_snow_build")     inst.openEye = "dogoo_eyebone_snow"    inst.closedEye = "dogoo_eyebone_closed_snow"    RefreshEye(inst)     inst.EyeboneState = "SNOW"end --[[local function MorphNormalEyebone(inst)    inst.AnimState:SetBuild("dogoo_eyebone_build")     inst.openEye = "dogoo_eyebone"    inst.closedEye = "dogoo_eyebone_closed"       RefreshEye(inst)     inst.EyeboneState = "NORMAL"end]] local function GetSpawnPoint(pt)    local theta = math.random() * 2 * PI    local radius = SPAWN_DIST    local offset = FindWalkableOffset(pt, theta, radius, 12, true)    return offset ~= nil and (pt + offset) or nilend local function SpawnDogoo(inst)    if not inst.owner then        print("Error: Eyebone has no linked player!")        return    end    --print("dogoo_eyebone - SpawnDogoo")     local pt = inst:GetPosition()    --print("    near", pt)             local spawn_pt = GetSpawnPoint(pt)    if spawn_pt ~= nil then        --print("    at", spawn_pt)        local dogoo = SpawnPrefab("personal_dogoo")        if dogoo ~= nil then            dogoo.Physics:Teleport(spawn_pt:Get())            dogoo:FacePoint(pt:Get())            if inst.owner then                inst.owner.dogoo = dogoo            end            return dogoo        end     --else        -- this is not fatal, they can try again in a new location by picking up the bone again        --print("dogoo_eyebone - SpawnDogoo: Couldn't find a suitable spawn point for dogoo")    endend local StartRespawn local function StopRespawn(inst)    --print("dogoo_eyebone - StopRespawn")    if inst.respawntask ~= nil then        inst.respawntask:Cancel()        inst.respawntask = nil        inst.respawntime = nil    endend local function RebindDogoo(inst, dogoo)    dogoo = dogoo or (inst.owner and inst.owner.dogoo)    if dogoo ~= nil then        if inst.owner then            dogoo.components.named:SetName(inst.owner.name.."'s Dogoo")        end        inst.AnimState:PlayAnimation("idle_loop", true)        OpenEye(inst)        inst:ListenForEvent("death", function()            if inst.owner then                inst.owner.dogoo = nil            end            StartRespawn(inst, TUNING.CHESTER_RESPAWN_TIME)        end, dogoo)         if dogoo.components.follower.leader ~= inst then            dogoo.components.follower:SetLeader(inst)        end        return true    endend local function RespawnDogoo(inst)    --print("dogoo_eyebone - RespawnDogoo")    StopRespawn(inst)    RebindDogoo(inst, (inst.owner and inst.owner.dogoo) or SpawnDogoo(inst))end StartRespawn = function(inst, time)    StopRespawn(inst)     time = time or 0    inst.respawntask = inst:DoTaskInTime(time, RespawnDogoo)    inst.respawntime = GetTime() + time    inst.AnimState:PlayAnimation("dead", true)    CloseEye(inst)end local function FixDogoo(inst)    inst.fixtask = nil    --take an existing dogoo if there is one    if not RebindDogoo(inst) then        inst.AnimState:PlayAnimation("dead", true)        CloseEye(inst)                 if inst.components.inventoryitem.owner ~= nil then            local time_remaining = 0            local time = GetTime()            if inst.respawntime and inst.respawntime > time then                time_remaining = inst.respawntime - time                    end            StartRespawn(inst, time_remaining)        end    endend local function OnPutInInventory(inst)    if inst.fixtask == nil then        inst.fixtask = inst:DoTaskInTime(1, FixDogoo)    endend  local function OnSave(inst, data)    --print("dogoo_eyebone - OnSave")    --data.EyeboneState = inst.EyeboneState    if inst.respawntime ~= nil then        local time = GetTime()        if inst.respawntime > time then            data.respawntimeremaining = inst.respawntime - time        end    endend local function OnLoad(inst, data)    if data == nil then        return    end     if data.EyeboneState == "SHADOW" then        MorphShadowEyebone(inst)    elseif data.EyeboneState == "SNOW" then        MorphSnowEyebone(inst)    end     if data.respawntimeremaining ~= nil then        inst.respawntime = data.respawntimeremaining + GetTime()    endend  local function GetStatus(inst)    --print("smallbird - GetStatus")    if inst.respawntask ~= nil then        return "WAITING"    endend local function fn()    local inst = CreateEntity()     inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddNetwork()     --so I can find the thing while testing    --inst.entity:AddMiniMapEntity()    --inst.MiniMapEntity:SetIcon("treasure.png")     MakeInventoryPhysics(inst)     inst:AddTag("personal_dogoo_eyebone")    inst:AddTag("irreplaceable")    inst:AddTag("nonpotatable")         inst:AddTag("_named")     inst.AnimState:SetBank("eyebone")    inst.AnimState:SetBuild("dogoo_eyebone_build")    inst.AnimState:PlayAnimation("idle_loop", true)     inst.entity:SetPristine()     if not TheWorld.ismastersim then        return inst    end         -- Dogoo will not be saved normally. He is saved with the player.    inst.persists = false     inst:AddComponent("inventoryitem")	inst.components.inventoryitem.atlasname = "images/inventoryimages/dogoo_eyebone.xml"	inst.components.inventoryitem:ChangeImageName("dogoo_eyebone")    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)     inst.EyeboneState = "NORMAL"    inst.openEye = "dogoo_eyebone"    inst.closedEye = "dogoo_eyebone_closed"     inst.isOpenEye = nil    OpenEye(inst)     inst:AddComponent("inspectable")    inst.components.inspectable.getstatus = GetStatus    inst.components.inspectable:RecordViews()    inst.components.inspectable.nameoverride = "dogoo_eyebone"     inst:AddComponent("leader")              inst:AddComponent("named")     MakeHauntableLaunch(inst)     --inst.MorphNormalEyebone = MorphNormalEyebone    inst.MorphSnowEyebone = MorphSnowEyebone    inst.MorphShadowEyebone = MorphShadowEyebone     inst.OnLoad = OnLoad    inst.OnSave = OnSave     inst.fixtask = inst:DoTaskInTime(1, FixDogoo)    inst.RebindDogoo = RebindDogoo     return instend return Prefab("common/inventory/personal_dogoo_eyebone", fn, assets)

Edited by DarkXero
Link to comment
Share on other sites

@DarkXero, Thanks, I actually did mess up one step and your solution fixed it. Thanks!

 

I've made some progress making it only follow my specific charatcer only.

 

Along the way I've hit a few snags:

 

Whenever I do LongUpdate() to fast forward time the client crashes.

Error log:

 

[00:05:26]: [string "../mods/plutia/modmain.lua"]:105: attempt to call upvalue 'OnSave_prev' (a nil value)LUA ERROR stack traceback:../mods/plutia/modmain.lua:105 in (field) OnSave (Lua) <104-133>   inst = 100078 - plutia (valid:true)   data = table: 180E5320scripts/entityscript.lua:1405 in (method) GetPersistData (Lua) <1373-1422>   self (valid:true) =      GUID = 100078      inlimbo = false      GetMoistureRateScale = function - scripts/prefabs/player_common.lua:97      ghostenabled = true      EnableMovementPrediction = function - scripts/prefabs/player_common.lua:407      ReturnEyebone = function - ../mods/plutia/modmain.lua:197      playercolour = table: 1408E178      AnimState = AnimState (3EDD5CC0)      Light = Light (3EDD5D80)      Network = Network (3EDD5BC0)      OnRemoveEntity = function - scripts/prefabs/player_common.lua:530      GetMoisture = function - scripts/prefabs/player_common.lua:77      pendingtasks = table: 1408DD18      LightWatcher = LightWatcher (3EDD5DA0)      DetachClassified = function - scripts/prefabs/player_common.lua:525      sg = sg="wilson_client", state="idle", time=32.97, tags = "idle,"      spawntime = 18.400000959635      ondetachclassified = function - scripts/prefabs/player_common.lua:521      player_classified = 100659 - player_classified (valid:true)      SetGhostMode = function - scripts/prefabs/player_common.lua:446      CanExamine = function - scripts/prefabs/player_common.lua:20      HUD = HUD      inherentactions = table: 2304C450      Transform = Transform (3EDD5B40)      userid = KU_Gl4sTPnP      IsActionsVisible = function - scripts/prefabs/player_common.lua:1020      actionreplica = table: 1408D9D0      event_listening = table: 1408D728      OnLoad = function - ../mods/plutia/modmain.lua:137      actioncomponents = table: 2304C518      OnSave = function - ../mods/plutia/modmain.lua:104      lower_components_shadow = table: 1408D390      GetMaxMoisture = function - scripts/prefabs/player_common.lua:87      OnNewSpawn = function - ../mods/plutia/modmain.lua:174      entity = Entity (0B9E5360)      name = Silhh      prefab = plutia      updatecomponents = table: 2E60C1E8      AttachClassified = function - scripts/prefabs/player_common.lua:519      OnDespawn = function - ../mods/plutia/modmain.lua:63      Physics = Physics (3EDD5A80)      ShakeCamera = function - scripts/prefabs/player_common.lua:1056      MiniMapEntity = MiniMapEntity (3EDD5B20)      event_listeners = table: 1408D750      DynamicShadow = DynamicShadow (3EDD5DC0)      IsOverheating = function - scripts/prefabs/player_common.lua:67      IsFreezing = function - scripts/prefabs/player_common.lua:57      persists = true      SoundEmitter = SoundEmitter (3EDD5E00)      replica = table: 1408D200      components = table: 1408D228      GetTemperature = function - scripts/prefabs/player_common.lua:47   references = nil   data = table: 180E5320scripts/entityscript.lua:269 in (method) GetSaveRecord (Lua) <234-272>   self (valid:true) =      GUID = 100078      inlimbo = false      GetMoistureRateScale = function - scripts/prefabs/player_common.lua:97      ghostenabled = true      EnableMovementPrediction = function - scripts/prefabs/player_common.lua:407      ReturnEyebone = function - ../mods/plutia/modmain.lua:197      playercolour = table: 1408E178      AnimState = AnimState (3EDD5CC0)      Light = Light (3EDD5D80)      Network = Network (3EDD5BC0)      OnRemoveEntity = function - scripts/prefabs/player_common.lua:530      GetMoisture = function - scripts/prefabs/player_common.lua:77      pendingtasks = table: 1408DD18      LightWatcher = LightWatcher (3EDD5DA0)      DetachClassified = function - scripts/prefabs/player_common.lua:525      sg = sg="wilson_client", state="idle", time=32.97, tags = "idle,"      spawntime = 18.400000959635      ondetachclassified = function - scripts/prefabs/player_common.lua:521      player_classified = 100659 - player_classified (valid:true)      SetGhostMode = function - scripts/prefabs/player_common.l[00:05:26]: [string "../mods/plutia/modmain.lua"]:105: attempt to call upvalue 'OnSave_prev' (a nil value)LUA ERROR stack traceback:    ../mods/plutia/modmain.lua:105 in (field) OnSave (Lua) <104-133>    scripts/entityscript.lua:1405 in (method) GetPersistData (Lua) <1373-1422>    scripts/entityscript.lua:269 in (method) GetSaveRecord (Lua) <234-272>    scripts/networking.lua:125 in (global) SerializeUserSession (Lua) <122-129>    scripts/components/autosaver.lua:59 in (upvalue) OnSave (Lua) <46-61>    scripts/components/autosaver.lua:90 in (local) fn (Lua) <78-93>    scripts/entityscript.lua:938 in (method) PushEvent (Lua) <932-955>    scripts/mainfunctions.lua:284 in () ? (Lua) <281-286>	[00:05:26]: SCRIPT ERROR! Showing error screen	[00:05:39]: Force aborting...

 

And secondly, my Dogoo chester performs the transformation scene chester does but does not transform into the desired dogoo chester.

 

If you have the time and if you dont mind, can you look at this code? I can't provide the files to the public as of yet, but I can post code here if you want. Push comes to shove, I'll PM you the files.

 

Modmain:

PrefabFiles = {	"plutia", 	"personal_dogoo_eyebone",	"personal_dogoo",}Assets = {    Asset( "IMAGE", "images/saveslot_portraits/plutia.tex" ),    Asset( "ATLAS", "images/saveslot_portraits/plutia.xml" ),    Asset( "IMAGE", "images/selectscreen_portraits/plutia.tex" ),    Asset( "ATLAS", "images/selectscreen_portraits/plutia.xml" ),	    Asset( "IMAGE", "images/selectscreen_portraits/plutia_silho.tex" ),    Asset( "ATLAS", "images/selectscreen_portraits/plutia_silho.xml" ),    Asset( "IMAGE", "bigportraits/plutia.tex" ),    Asset( "ATLAS", "bigportraits/plutia.xml" ),		Asset( "IMAGE", "images/map_icons/plutia.tex" ),	Asset( "ATLAS", "images/map_icons/plutia.xml" ),		Asset( "IMAGE", "images/avatars/avatar_plutia.tex" ),    Asset( "ATLAS", "images/avatars/avatar_plutia.xml" ),		Asset( "IMAGE", "images/avatars/avatar_ghost_plutia.tex" ),    Asset( "ATLAS", "images/avatars/avatar_ghost_plutia.xml" ),}local require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGS-- Custom itemsSTRINGS.NAMES.PERSONAL_DOGOO = "Personal Dogoo"STRINGS.NAMES.PERSONAL_DOGOO_EYEBONE = "Personal Dogoo Bone"-- An eyebone is given every time player is spawned/loaded. It's not savedlocal function GiveEyebone(inst)	local eyebone = GLOBAL.SpawnPrefab("personal_dogoo_eyebone")	if eyebone then		eyebone.owner = inst		inst.eyebone = eyebone		inst.components.inventory.ignoresound = true		inst.components.inventory:GiveItem(eyebone)		inst.components.inventory.ignoresound = false		eyebone.components.named:SetName(inst.name.."'s Dogoo Bone")	return eyebone	endendlocal function GetSpawnPoint(pt)	local theta = math.random() * 2 * GLOBAL.PI	local radius = 4	local offset = GLOBAL.FindWalkableOffset(pt, theta, radius, 12, true)	return offset ~= nil and (pt + offset) or nilendlocal function PersonalDogoo(inst)	if not inst:HasTag("specialdogooowner") then		return	end	local OnDespawn_prev = inst.OnDespawn	local OnDespawn_new = function(inst)		-- Remove dogoo		if inst.dogoo then			-- Don't allow dogoo to despawn with irreplaceable items			inst.dogoo.components.container:DropEverythingWithTag("irreplaceable")						-- We need time to save before despawning.			inst.dogoo:DoTaskInTime(0.1, function(inst)				if inst and inst:IsValid() then					inst:Remove()				end			end)					end				if inst.eyebone then			-- Eyebone drops from whatever its in			local owner = inst.eyebone.components.inventoryitem.owner			if owner then				if owner.components.container then					owner.components.container:DropItem(inst.eyebone)				elseif owner.components.inventory then					owner.components.inventory:DropItem(inst.eyebone)				end			end			-- Remove eyebone			inst.eyebone:DoTaskInTime(0.1, function(inst)				if inst and inst:IsValid() then					inst:Remove()				end			end)		else			print("Error: Player has no linked eyebone!")		end		if OnDespawn_prev then			return OnDespawn_prev(inst)		end	end	inst.OnDespawn = OnDespawn_new		local OnSave_prev = inst.OnSave	local OnSave_new = function(inst, data)		local references = OnSave_prev(inst, data)		if inst.dogoo then			-- Save dogoo			local refs = {}			if not references then				references = {}			end			data.dogoo, refs = inst.dogoo:GetSaveRecord()			if refs then				for k,v in pairs(refs) do					table.insert(references, v)				end 			end						end		if inst.eyebone then			-- Save eyebone			local refs = {}			if not references then				references = {}			end			data.eyebone, refs = inst.eyebone:GetSaveRecord()			if refs then				for k,v in pairs(refs) do					table.insert(references, v)				end 			end			end		return references	end    inst.OnSave = OnSave_new		local OnLoad_prev = inst.OnLoad	local OnLoad_new = function(inst, data, newents)		if data.dogoo ~= nil then			-- Load dogoo			inst.dogoo = GLOBAL.SpawnSaveRecord(data.dogoo, newents)		else			--print("Warning: No dogoo was loaded from save file!")		end				if data.eyebone ~= nil then			-- Load dogoo			inst.eyebone = GLOBAL.SpawnSaveRecord(data.eyebone, newents)						-- Look for eyebone at spawn point and re-equip			inst:DoTaskInTime(0, function(inst)				if inst.eyebone and inst:IsNear(inst.eyebone,4) then					inst.components.inventory:GiveItem(inst.eyebone)				end			end)		else			print("Warning: No eyebone was loaded from save file!")		end				-- Create new eyebone if none loaded		if not inst.eyebone then			GiveEyebone(inst)		end				inst.eyebone.owner = inst						if OnLoad_prev then			return OnLoad_prev(inst, data, newents)		end	end    inst.OnLoad = OnLoad_new		local OnNewSpawn_prev = inst.OnNewSpawn	local OnNewSpawn_new = function(inst)		-- Give new eyebone. Let dogoo spawn naturally.		GiveEyebone(inst)		if OnNewSpawn_prev then			return OnNewSpawn_prev(inst)		end	end    inst.OnNewSpawn = OnNewSpawn_new		if GLOBAL.TheNet:GetServerGameMode() == "wilderness" then		local function ondeath(inst, data)			-- Kill player's dogoo in wilderness mode 			if inst.dogoo then				inst.dogoo.components.health:Kill()			end			if inst.eyebone then				inst.eyebone:Remove()			end		end		inst:ListenForEvent("death", ondeath)	end		-- Debug function to return eyebone	inst.ReturnEyebone = function()		if inst.eyebone and inst.eyebone:IsValid() then			if inst.eyebone.components.inventoryitem.owner ~= inst then				inst.components.inventory:GiveItem(inst.eyebone)			end		else			GiveEyebone(inst)		end		if inst.dogoo and not inst:IsNear(inst.dogoo, 20) then			local pt = inst:GetPosition()			local spawn_pt = GetSpawnPoint(pt)			if spawn_pt ~= nil then				inst.dogoo.Physics:Teleport(spawn_pt:Get())				inst.dogoo:FacePoint(pt:Get())			end		end	endendGLOBAL.c_returneyebone = function(inst)	if not inst then		inst = GLOBAL.ThePlayer or GLOBAL.AllPlayers[1]	end	if not inst or not inst.ReturnEyebone then 		print("Error: Cannot return eyebone")		return 	end	inst:ReturnEyebone()endAddPlayerPostInit(PersonalDogoo)-- The character select screen linesSTRINGS.CHARACTER_TITLES.plutia = "The Sample Character"STRINGS.CHARACTER_NAMES.plutia = "Esc"STRINGS.CHARACTER_DESCRIPTIONS.plutia = "*Perk 1\n*Perk 2\n*Perk 3"STRINGS.CHARACTER_QUOTES.plutia = "\"Quote\""-- Custom speech stringsSTRINGS.CHARACTERS.PLUTIA = require "speech_plutia"-- The character's name as appears in-game STRINGS.NAMES.PLUTIA = "Esc"-- The default responses of examining the characterSTRINGS.CHARACTERS.GENERIC.DESCRIBE.PLUTIA = {	GENERIC = "It's Esc!",	ATTACKER = "That Esc looks shifty...",	MURDERER = "Murderer!",	REVIVER = "Esc, friend of ghosts.",	GHOST = "Esc could use a heart.",}AddMinimapAtlas("images/map_icons/plutia.xml")-- Add mod character to mod character list. Also specify a gender. Possible genders are MALE, FEMALE, ROBOT, NEUTRAL, and PLURAL.AddModCharacter("plutia", "FEMALE")

 

Custom chesters prefab file

require "prefabutil"local brain = require "brains/chesterbrain"local WAKE_TO_FOLLOW_DISTANCE = 14local SLEEP_NEAR_LEADER_DISTANCE = 7local assets ={    Asset("ANIM", "anim/ui_chester_shadow_3x4.zip"),    Asset("ANIM", "anim/ui_chest_3x3.zip"),    Asset("ANIM", "anim/chester.zip"),    Asset("ANIM", "anim/dogoo_build.zip"),    Asset("ANIM", "anim/dogoo_shadow_build.zip"),    Asset("ANIM", "anim/dogoo_snow_build.zip"),    Asset("SOUND", "sound/chester.fsb"),}local prefabs ={    "personal_dogoo_eyebone",    "chesterlight"}local function ShouldWakeUp(inst)    return DefaultWakeTest(inst) or not inst.components.follower:IsNearLeader(WAKE_TO_FOLLOW_DISTANCE)endlocal function ShouldSleep(inst)    --print(inst, "ShouldSleep", DefaultSleepTest(inst), not inst.sg:HasStateTag("open"), inst.components.follower:IsNearLeader(SLEEP_NEAR_LEADER_DISTANCE))    return DefaultSleepTest(inst) and not inst.sg:HasStateTag("open") and inst.components.follower:IsNearLeader(SLEEP_NEAR_LEADER_DISTANCE) and not TheWorld.state.isfullmoonendlocal function ShouldKeepTarget()    return false -- dogoo can't attack, and won't sleep if he has a targetendlocal function OnOpen(inst)    if not inst.components.health:IsDead() then        inst.sg:GoToState("open")    endendlocal function OnClose(inst)    if not inst.components.health:IsDead() and inst.sg.currentstate.name ~= "transition" then        inst.sg:GoToState("close")    endend-- eye bone was killed/destroyedlocal function OnStopFollowing(inst)    --print("dogoo - OnStopFollowing")    inst:RemoveTag("companion")endlocal function OnStartFollowing(inst)    --print("dogoo - OnStartFollowing")    inst:AddTag("companion")endlocal function MorphShadowDogoo(inst)    inst.AnimState:SetBuild("dogoo_shadow_build")    inst:AddTag("spoiler")    inst.components.container:WidgetSetup("shadowchester")    local leader = inst.components.follower.leader        if leader ~= nil then        inst.components.follower.leader:MorphShadowEyebone()    end    inst.DogooState = "SHADOW"    inst._isshadowdogoo:set(true)endlocal function MorphSnowDogoo(inst)    inst.AnimState:SetBuild("dogoo_snow_build")    inst:AddTag("fridge")    local leader = inst.components.follower.leader    if leader ~= nil then        inst.components.follower.leader:MorphSnowEyebone()    end    inst.DogooState = "SNOW"    inst._isshadowdogoo:set(false)endlocal function MorphNormalDogoo(inst)    inst.AnimState:SetBuild("dogoo_build")    inst:RemoveTag("fridge")    inst:RemoveTag("spoiler")    inst.components.container:WidgetSetup("chester")    local leader = inst.components.follower.leader        if leader ~= nil then        inst.components.follower.leader:MorphNormalEyebone()    end    inst.DogooState = "NORMAL"    inst._isshadowdogoo:set(false)end--local function CanMorph(inst)    if inst.DogooState ~= "NORMAL" or not TheWorld.state.isfullmoon then        return false, false    end    local container = inst.components.container    if container:IsOpen() then        return false, false    end    local canShadow = true    local canSnow = true    for i = 1, container:GetNumSlots() do        local item = container:GetItemInSlot(i)        if item == nil then            return false, false        end        canShadow = canShadow and item.prefab == "nightmarefuel"        canSnow = canSnow and item.prefab == "bluegem"        if not (canShadow or canSnow) then            return false, false        end    end    return canShadow, canSnowendlocal function CheckForMorph(inst)    local canShadow, canSnow = CanMorph(inst)    if canShadow or canSnow then        inst.sg:GoToState("transition")    endendlocal function DoMorph(inst, fn)    inst.MorphDogoo = nil    inst:StopWatchingWorldState("isfullmoon", CheckForMorph)    inst:RemoveEventCallback("onclose", CheckForMorph)    fn(inst) endlocal function MorphDogoo(inst)    local canShadow, canSnow = CanMorph(inst)    if not (canShadow or canSnow) then        return    end    local container = inst.components.container    for i = 1, container:GetNumSlots() do        container:RemoveItem(container:GetItemInSlot(i)):Remove()    end    DoMorph(inst, canShadow and MorphShadowDogoo or MorphSnowDogoo)endlocal function OnSave(inst, data)    data.DogooState = inst.DogooStateendlocal function OnPreLoad(inst, data)    if data == nil then        return    elseif data.DogooState == "SHADOW" then        DoMorph(inst, MorphShadowDogoo)    elseif data.DogooState == "SNOW" then        DoMorph(inst, MorphSnowDogoo)    endendlocal function OnIsShadowDogooDirty(inst)    if inst._isshadowdogoo:value() ~= inst._clientshadowmorphed then        inst._clientshadowmorphed = inst._isshadowdogoo:value()        inst.replica.container:WidgetSetup(inst._clientshadowmorphed and "shadowchester" or nil)    endendlocal function create_dogoo()    --print("dogoo - create_dogoo")    local inst = CreateEntity()        inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    inst.entity:AddDynamicShadow()    inst.entity:AddMiniMapEntity()    inst.entity:AddNetwork()    MakeCharacterPhysics(inst, 75, .5)    inst.Physics:SetCollisionGroup(COLLISION.CHARACTERS)    inst.Physics:ClearCollisionMask()    inst.Physics:CollidesWith(COLLISION.WORLD)    inst.Physics:CollidesWith(COLLISION.OBSTACLES)    inst.Physics:CollidesWith(COLLISION.CHARACTERS)    inst:AddTag("companion")    inst:AddTag("character")    inst:AddTag("scarytoprey")    inst:AddTag("personal_dogoo")    inst:AddTag("notraptrigger")	    inst:AddTag("_named")    inst.MiniMapEntity:SetIcon("dogoo.png")    inst.MiniMapEntity:SetCanUseCache(false)    inst.AnimState:SetBank("dogoo")    inst.AnimState:SetBuild("dogoo_build")    inst.DynamicShadow:SetSize(2, 1.5)    inst.Transform:SetFourFaced()    inst._isshadowdogoo = net_bool(inst.GUID, "_isshadowdogoo", "onisshadowdogoodirty")		    inst.entity:SetPristine()	    if not TheWorld.ismastersim then		inst:DoTaskInTime(0.1, function(inst)			inst.replica.container:WidgetSetup(inst._isshadowdogoo:value() and "shadowchester" or "chester")		end)        inst._clientshadowmorphed = false        inst:ListenForEvent("onisshadowdogoodirty", OnIsShadowDogooDirty)        return inst    end		-- Dogoo will not be saved normally. He is saved with the player.	inst.persists = false    ------------------------------------------    --print("   combat")    inst:AddComponent("combat")    inst.components.combat.hiteffectsymbol = "dogoo_body"    inst.components.combat:SetKeepTargetFunction(ShouldKeepTarget)	local self = inst.components.combat	local old = self.GetAttacked	function self:GetAttacked(attacker, damage, weapon, stimuli)		if attacker then			return true		end		return old(self, attacker, damage, weapon, stimuli)	end    --inst:ListenForEvent("attacked", OnAttacked)    --print("   health")    inst:AddComponent("health")    inst.components.health:SetMaxHealth(TUNING.CHESTER_HEALTH)    inst.components.health:StartRegen(TUNING.CHESTER_HEALTH_REGEN_AMOUNT, TUNING.CHESTER_HEALTH_REGEN_PERIOD)    inst:AddTag("noauradamage")    --print("   inspectable")    inst:AddComponent("inspectable")    inst.components.inspectable:RecordViews()    --inst.components.inspectable.getstatus = GetStatus    inst.components.inspectable.nameoverride = "dogoo"    --print("   locomotor")    inst:AddComponent("locomotor")    inst.components.locomotor.walkspeed = 3    inst.components.locomotor.runspeed = 7    --print("   follower")    inst:AddComponent("follower")    inst:ListenForEvent("stopfollowing", OnStopFollowing)    inst:ListenForEvent("startfollowing", OnStartFollowing)    --print("   knownlocations")    inst:AddComponent("knownlocations")    --print("   burnable")    MakeSmallBurnableCharacter(inst, "dogoo_body")    --("   container")    inst:AddComponent("container")    inst.components.container:WidgetSetup("chester")    inst.components.container.onopenfn = OnOpen    inst.components.container.onclosefn = OnClose    --print("   sleeper")    inst:AddComponent("sleeper")    inst.components.sleeper:SetResistance(3)    inst.components.sleeper.testperiod = GetRandomWithVariance(6, 2)    inst.components.sleeper:SetSleepTest(ShouldSleep)    inst.components.sleeper:SetWakeTest(ShouldWakeUp)	    inst:AddComponent("named")    MakeHauntableDropFirstItem(inst)    AddHauntableCustomReaction(inst, function(inst, haunter)        if math.random() <= TUNING.HAUNT_CHANCE_ALWAYS then            inst.components.hauntable.panic = true            inst.components.hauntable.panictimer = TUNING.HAUNT_PANIC_TIME_SMALL            inst.components.hauntable.hauntvalue = TUNING.HAUNT_SMALL            return true        end        return false    end, false, false, true)    --print("   sg")    inst:SetStateGraph("SGchester")    inst.sg:GoToState("idle")    --print("   brain")    inst:SetBrain(brain)    inst.DogooState = "NORMAL"    inst.MorphDogoo = MorphDogoo    inst:WatchWorldState("isfullmoon", CheckForMorph)    inst:ListenForEvent("onclose", CheckForMorph)    inst.OnSave = OnSave    inst.OnPreLoad = OnPreLoad    --print("dogoo - create_dogoo END")			    return instendreturn Prefab("common/personal_dogoo", create_dogoo, assets, prefabs)

 

Yet again, Its appreciated!

Edited by rons0n
Link to comment
Share on other sites

@rons0n,

The error is that you are indexing a nil value because apparently there is no prev OnSave in that case.

 

Do

local references = OnSave_prev and OnSave_prev(inst, data)

I see that after that the references is taken care of if it's nil.

 

Also you can PM me for whatever you don't want to disclose.

 

Edited by DarkXero
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...