Jump to content

Recommended Posts

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.

@seronis

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

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

Edited by seronis

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.

Edited by pikafan8

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