Jump to content

Help properly networking a colourcube override


Recommended Posts

So hopefully this should be straightforward. :)

I've managed to add in a colourcube override which works for the server, but I can't figure out how to get it to trigger on the client side.

I've tried a few things, but I'm at the limit of my skillset. Would anyone have any suggestions? 

local assets =
{
    Asset("ANIM", "anim/gears_hat_goggles.zip"),
    Asset("IMAGE", "images/colour_cubes/beaver_vision_cc.tex"),
}

-----------------------------------------------------------------------

local GEARVISION_COLOURCUBES =
{
    day = "images/colour_cubes/beaver_vision_cc.tex",
    dusk = "images/colour_cubes/beaver_vision_cc.tex",
    night = "images/colour_cubes/beaver_vision_cc.tex",
    full_moon = "images/colour_cubes/beaver_vision_cc.tex",
}

local function SetGearVision(inst, enable)
    if enable then
        inst.components.playervision:SetCustomCCTable(GEARVISION_COLOURCUBES)
    else
        inst.components.playervision:SetCustomCCTable(nil)
    end
end

------------------------------------------------------------------------

local function generic_perish(inst)
    local fin = SpawnPrefab("ruins_battery")
    fin.Transform:SetPosition(inst.Transform:GetWorldPosition())    
    inst:Remove()
end

local function goggles_perish(inst)
    if inst.components.equippable ~= nil and inst.components.equippable:IsEquipped() then
        local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nil
        if owner ~= nil then
            goggles_turnoff(owner)
        end
    end
    inst:Remove()
end

local function ontakefuel(inst)
    inst.SoundEmitter:PlaySound("dontstarve/common/nightmareAddFuel")
end

local function fn()
    local function onequip(inst, owner)
        SetGearVision(owner, true)
        owner.AnimState:OverrideSymbol("swap_hat", "gears_hat_goggles", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Show("HAT_HAIR")
    
        inst.components.fueled:StartConsuming()        
    end

    local function onunequip(inst, owner)
        SetGearVision(owner, false)
        owner.AnimState:Hide("HAT")
        owner.AnimState:Hide("HAT_HAIR")
    
        if owner:HasTag("player") then
            owner.AnimState:Show("HEAD")
            owner.AnimState:Hide("HEAD_HAIR")
        end
        
        inst.components.fueled:StopConsuming()      
    end
    
    local function goggles_onequip(inst, owner)
        SetGearVision(owner, true)
        onequip(inst, owner)
        owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_on")
    end

    local function goggles_onunequip(inst, owner)
        SetGearVision(owner, false)
        onunequip(inst, owner)
        owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_off")
    end
    
    local inst = CreateEntity()
    
    inst:AddTag("nightvision")
    inst:AddTag("goggles")    
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    
    MakeInventoryPhysics(inst) 

    inst.AnimState:SetBank("gears_hat_goggles")
    inst.AnimState:SetBuild("gears_hat_goggles")
    inst.AnimState:PlayAnimation("idle")    

    inst:AddTag("hat")
    
    if CurrentRelease.GreaterOrEqualTo("R08_ROT_TURNOFTIDES") then
        MakeInventoryFloatable(inst, "small", 0.2, 0.80)
    end

    inst.entity:SetPristine()    

    if not TheWorld.ismastersim then
        return inst
    end    

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/gears_hat_goggles.xml"
    
    inst:AddComponent("tradable")

    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(goggles_onequip)
    inst.components.equippable:SetOnUnequip(goggles_onunequip)

    inst:AddComponent("fueled")    
    inst.components.fueled:InitializeFuelLevel(TUNING.TOTAL_DAY_TIME*.75)
    inst.components.fueled.accepting = true
    inst.components.fueled.fueltype = FUELTYPE.NIGHTMARE
    inst.components.fueled:SetDepletedFn(generic_perish)

    
    MakeHauntableLaunch(inst)
    
    return inst
end

STRINGS.NAMES.GEARS_HAT_GOGGLES                             = "Gear Goggles"
STRINGS.RECIPE_DESC.GEARS_HAT_GOGGLES                         = "Light, fueled by darkness."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.GEARS_HAT_GOGGLES         = "Fashion for the inventor."
STRINGS.CHARACTERS.WILLOW.DESCRIBE.GEARS_HAT_GOGGLES         = "I prefer fire for lighting in the dark."
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.GEARS_HAT_GOGGLES         = "Ha! Wolfgang no longer afraid of darkness!"
STRINGS.CHARACTERS.WENDY.DESCRIBE.GEARS_HAT_GOGGLES         = "How boring. Why bother seeing through the darkness?"
STRINGS.CHARACTERS.WX78.DESCRIBE.GEARS_HAT_GOGGLES             = "A TEMPORARY VISION UPGRADE"
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.GEARS_HAT_GOGGLES     = "These goggles appear to be lost technology."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.GEARS_HAT_GOGGLES         = "Fancy technological doodad."
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.GEARS_HAT_GOGGLES         = "I forgot about these."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.GEARS_HAT_GOGGLES     = "The night no longer binds me."
STRINGS.CHARACTERS.WEBBER.DESCRIBE.GEARS_HAT_GOGGLES         = "Awesome!"
STRINGS.CHARACTERS.WINONA.DESCRIBE.GEARS_HAT_GOGGLES         = "Maybe I'll see Charlie"
STRINGS.CHARACTERS.WORTOX.DESCRIBE.GEARS_HAT_GOGGLES         = "Hyuyu! Is this cheating?"

return Prefab( "common/inventory/gears_hat_goggles", fn, assets ) 

gear_hat_goggles_mod.zip

Edited by Tosh
Formatting, oh wow...
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...