Jump to content

Colourcube for Clients/Cave world?


Recommended Posts

Hi! I'm sure this question has been asked a lot but I couldn't find anything that helps me, My code works perfectly on Caveless worlds/Host, But it does not work for Clients/Cave worlds, If anyone could help me i'd be grateful.

This is my code
 

local assets =
{
	Asset("ANIM", "anim/hat_gogglesshoot.zip"),		
	Asset("ATLAS", "images/colour_cubes/shooting_goggles_cc.xml"),
	Asset("IMAGE", "images/colour_cubes/shooting_goggles_cc.tex"),
	
	Asset("ATLAS", "images/inventoryimages/wagstaffshootgoggles.xml"),
	Asset("IMAGE", "images/inventoryimages/wagstaffshootgoggles.tex"),
}

local COLOURCUBE = resolvefilepath("images/colour_cubes/shooting_goggles_cc.tex")

local COLOURCUBE_TABLE =
{
    day = COLOURCUBE ,
    dusk = COLOURCUBE ,
    night = COLOURCUBE ,
    full_moon = COLOURCUBE ,
}

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


local function perish(inst)
	inst:Remove()
end

local function onequip(inst, owner)
	SetShootVision(owner, true)
	if owner.components.talker then
		owner.components.talker:Say(GetString(owner.prefab, "ANNOUNCE_PUTONGOGGLES_GOGGLESSHOOTHAT"))
	end
	owner.AnimState:OverrideSymbol("swap_hat", "hat_gogglesshoot", "swap_hat")
    owner.AnimState:Show("HAT")
	if owner:HasTag("wagstaff_inventor") then
		inst.components.weapon:CanRangedAttack(function() return true end)
	    --inst.components.weapon:SetProjectile("fryfocals_charge")
	else
	    --inst.components.weapon:SetProjectile()
	   inst.components.weapon:CanRangedAttack(function() return false end)
	end
end

local function onunequip(inst, owner)
	SetShootVision(owner, false)
    owner.AnimState:ClearOverrideSymbol("swap_hat")
    owner.AnimState:Hide("HAT")
    --if TheWorld and TheWorld.components.colourcube then
        --TheWorld.components.colourcubemanager:SetOverrideColourCube(nil, .5)
    --end        
end

local function onattack_shoot(inst, attacker, target, owner)
	if target.components.burnable and not target.components.burnable:IsBurning() then
	    if target.components.freezable and target.components.freezable:IsFrozen() then           
	        target.components.freezable:Unfreeze()            
	    else            
	        if target.components.fueled and target:HasTag("campfire") and target:HasTag("structure") then
	            -- Rather than worrying about adding fuel cmp here, just spawn some fuel and immediately feed it to the fire
	            local fuel = SpawnPrefab("cutgrass")
	            if fuel then target.components.fueled:TakeFuelItem(fuel) end
	        else
	            target.components.burnable:Ignite(true)
	        end
	    end   
	end

	if target:HasTag("aquatic") and not target.components.burnable then 
	    local pt = target:GetPosition()
	    local smoke = SpawnPrefab("smoke_out")
	    smoke.Transform:SetPosition(pt:Get())

	    if target.SoundEmitter then 
	        target.SoundEmitter:PlaySound("dontstarve_DLC002/common/fire_weapon_out") 
	    end 
	end 

	if target.components.freezable then
	    target.components.freezable:AddColdness(-1) --Does this break ice staff?
	    if target.components.freezable:IsFrozen() then
	        target.components.freezable:Unfreeze()            
	    end
	end

	if target.components.sleeper and target.components.sleeper:IsAsleep() then
	    target.components.sleeper:WakeUp()
	end
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()
	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("gogglesshoothat")
	inst.AnimState:SetBuild("hat_gogglesshoot")
	inst.AnimState:PlayAnimation("anim")

	--inst:AddTag("goggles")
	inst:AddTag("venting")

	if GROUND.OCEAN_SHALLOW then
		MakeInventoryFloatable(inst, "idle_water", "anim")
	end

	inst:AddTag("hat") 
	inst:AddTag("Shockwhenwet")
	inst:AddTag("nearsighted_glasses")
	inst:AddTag("projectile")
	inst:AddTag("wagstaffgoggles")
	inst:AddTag("shootvision")
	
	inst.entity:SetPristine()
	
	if not TheWorld.ismastersim then
        return inst
    end
	
	inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(50)
    inst.components.weapon:SetRange(8, 10)    	
    inst.components.weapon:SetProjectile("fryfocals_charge")
    inst.components.weapon:SetOnAttack(onattack_shoot)
	
	inst:AddComponent("finiteuses")
	inst.components.finiteuses:SetMaxUses(TUNING.GOGGLES_SHOOT_USES)
	inst.components.finiteuses:SetUses(TUNING.GOGGLES_SHOOT_USES)
	inst.components.finiteuses:SetOnFinished( perish )

	inst:AddComponent("inspectable")

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

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD

	inst.components.equippable:SetOnEquip( onequip )

	inst.components.equippable:SetOnUnequip( onunequip )

	return inst
end

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

 

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