pikafan8 Posted January 30, 2015 Share Posted January 30, 2015 I'm going to make this quick.When I save and exit the game, my item's fuel percentage goes back up to 100%.local assets={ Asset("ANIM", "anim/flareblade.zip"), Asset("ANIM", "anim/swap_flareblade.zip"), Asset("ATLAS", "images/inventoryimages/flareblade.xml"), Asset("IMAGE", "images/inventoryimages/flareblade.tex"),}prefabs = {}local function FuelFX(inst) local fx = SpawnPrefab("statue_transition_2") if fx then fx.Transform:SetPosition(inst:GetPosition():Get()) fx.AnimState:SetScale(1,2,1) end fx = SpawnPrefab("statue_transition") if fx then fx.Transform:SetPosition(inst:GetPosition():Get()) fx.AnimState:SetScale(1,1.5,1) endendlocal function turnon(inst) if not inst.components.fueled:IsEmpty() then if inst.components.fueled then inst.components.fueled:StartConsuming() end end inst.Light:Enable(true) inst.SoundEmitter:PlaySound("dontstarve/wilson/torch_swing") inst.SoundEmitter:PlaySound("dontstarve/wilson/torch_LP", "flare")endlocal function turnoff(inst) if inst.components.fueled then inst.components.fueled:StopConsuming() end inst.Light:Enable(false) FuelFX(inst) inst.SoundEmitter:KillSound("flare") inst.SoundEmitter:PlaySound("dontstarve/common/fireOut")endlocal function ondropped(inst) turnoff(inst) turnon(inst) endlocal function onpickup(inst) turnon(inst)endlocal function onputininventory(inst) turnoff(inst)endlocal function nofuel(inst) local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner if owner then owner:PushEvent("torchranout", {torch = inst}) end turnoff(inst)endlocal function takefuel(inst) if inst.components.equippable and inst.components.equippable:IsEquipped() then turnon(inst) endendlocal function fuelupdate(inst) local fuelpercent = inst.components.fueled:GetPercent() inst.Light:SetIntensity(Lerp(0.3, 0.5, fuelpercent)) inst.Light:SetRadius(Lerp(2, 4, fuelpercent)) inst.Light:SetFalloff(.8)endlocal function fn() local function OnEquip(inst, owner) if not inst.components.fueled:IsEmpty() then turnon(inst) else turnoff(inst) end owner.AnimState:OverrideSymbol("swap_object", "swap_flareblade", "swap_flareblade") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function OnUnequip(inst, owner) turnoff(inst) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() local light = inst.entity:AddLight() MakeInventoryPhysics(inst) anim:SetBank("flareblade") anim:SetBuild("flareblade") anim:PlayAnimation("idle") inst:AddTag("flareblade") inst:AddTag("light") inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "flareblade" inst.components.inventoryitem.atlasname = "images/inventoryimages/flareblade.xml" inst:AddComponent("weapon") inst.components.weapon:SetDamage(54) ----- inst:AddComponent("tool") inst.components.tool:SetAction(ACTIONS.CHOP, 1.25) inst:AddComponent("equippable") inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) inst.components.inventoryitem:SetOnDroppedFn(ondropped) inst.components.inventoryitem:SetOnPutInInventoryFn(onputininventory) inst:AddComponent("fueled") inst.components.fueled.fueltype = "NIGHTMARE" inst.components.fueled:InitializeFuelLevel(TUNING.LANTERN_LIGHTTIME / 4) inst.components.fueled:SetDepletedFn(nofuel) inst.components.fueled:SetUpdateFn(fuelupdate) inst.components.fueled.ontakefuelfn = takefuel inst.components.fueled.accepting = true inst.entity:AddLight() inst.Light:SetColour(187/255, 15/255, 23/255) fuelupdate(inst) return instendreturn Prefab("common/inventory/flareblade", fn, assets, prefabs)I know it has to be something dumb. Link to comment Share on other sites More sharing options...
seronis Posted January 31, 2015 Share Posted January 31, 2015 not dumb. just simple. you need to define an onsave and onload pair of functions for your object to make it actually save its state. any prefab with a variable state already does this so there are many examples. Link to comment Share on other sites More sharing options...
Blueberrys Posted January 31, 2015 Share Posted January 31, 2015 @seronisHmm, but doesn't the fueled component handle that? I checked some armor prefabs and they don't have an OnSave or OnLoad, but the armor component does.Unless it's inconsistent throughout prefabs/components. Just checked mininglantern too, it doesn't have an onsave. The onload function isn't checked the fuel either. Link to comment Share on other sites More sharing options...
seronis Posted January 31, 2015 Share Posted January 31, 2015 inst.components.fueled:InitializeFuelLevel(TUNING.LANTERN_LIGHTTIME / 4) But your constructor is specifically setting all objects it creates to have fuel. So if you want saved/loaded ones to have "other than refueled" behavior you need to do it manually. Or not set fuel in the constructor any more. Possible im misunderstanding. I dont have the prefabs on this computer to check the vanilla files Link to comment Share on other sites More sharing options...
pikafan8 Posted January 31, 2015 Author Share Posted January 31, 2015 I finally got it working! All I needed to do was simply, just...inst.OnPreload = (inst.components.fueled:OnLoad(data))inst.OnSave = (inst.components.fueled:OnSave())I fear it might be slightly ineffective, though. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.