Jump to content

Prefab only not showing up when I have Caves Enabled


Recommended Posts

So I have a strange issue: When I launch a server without caves my character mod works fine and all the things work as intended. However when I have caves enabled my character no longer spawns with the hat he is supposed to. What gives? Whats odd is when I am picking stuff up, the game "thinks" there is an item there: 

http://imgur.com/a/8P0d1

I can move objects into that slot, but its just odd. I can't even spawn my hat in console when I have caves enabled, but everything is fine with caves off. What gives?

Mod Link: http://steamcommunity.com/sharedfiles/filedetails/?id=858001614

 

 

Link to comment
Share on other sites

The only thing I can think of is the item is a hat that works both in the winter and the summer, and the code for the dual insulator is this part: 

inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
            inst.components.insulator:SetSummer()
	
        else
            inst.components.insulator:SetWinter()

        end
    end)

I'm guessing that since having caves are a separate server the hat might be getting confused since it'd be running these lines in both the overworld and the caves server. Not sure why it wouldn't give me an error message though. Any ideas?\

 

 

EDIT:

Just tried removing those lines to see if that was the issue. Nope. Hat still refuses to exist in caves enabled worlds, but works fine without caves. 

What confuses me is that the Custom Panflute is spawning constantly without issue, but the Hat just doesn't like caves. 

Edited by Monty_Droppings
Link to comment
Share on other sites

Usually when you have problem with caves and not with world without cave, it's because you are not the host in the world with cave, and you are the host without cave. I can't take a look at the code now, but maybe you miss something you need as a client, like an information or something, and it's why it's not ok with caves.

Link to comment
Share on other sites

6 minutes ago, Lumina said:

Usually when you have problem with caves and not with world without cave, it's because you are not the host in the world with cave, and you are the host without cave. I can't take a look at the code now, but maybe you miss something you need as a client, like an information or something, and it's why it's not ok with caves.

Are there any "common mistakes" involving that? I thought for sure it was my insulation code, but even with that removed the hat still refused to load properly. I'm not exactly sure what I am supposed to be looking for. 

http://pastebin.com/HpPTuXDn

 
Edited by Monty_Droppings
Link to comment
Share on other sites

8 minutes ago, Lumina said:

Usually, forgetting line


    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

And i think they aren't in your code, no ? I don't see them in paste bin.

I added those lines to the fn(Sim) function and it the hat still refuses to spawn, even if I removed the dual insulator thingy as well. 

 

Edited by Monty_Droppings
Link to comment
Share on other sites

17 minutes ago, Monty_Droppings said:

I added those lines to the fn(Sim) function and it the hat still refuses to spawn, even if I removed the dual insulator thingy as well. 

I'm not sure but i think maybe it's because you need to test it also for the

   inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
            inst.components.insulator:SetSummer()
   
        else
            inst.components.insulator:SetWinter()
 
        end
    end)
    

Here

Because usually the "inst.component.insulator" go here

    inst:AddComponent("insulator")
 
 
  inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
       

And this part is after the


    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

So maybe something like this ?

   inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
	if not TheWorld.ismastersim then
       	 return inst
    	end
            inst.components.insulator:SetSummer()
   
        else
  	if not TheWorld.ismastersim then
        	return inst
    	end
            inst.components.insulator:SetWinter()
 
        end
    end)
    

Note : i'm not sure how the test should work if put here, maybe i'm wrong, but i think the "component" part should be server side only, and it's probably what is wrong.

Edited by Lumina
Link to comment
Share on other sites

Generally you want your TheWorld.ismastersim check before the component logic (since most of it is handled exclusively by the server), but after adding tags and setting up the animation. The code in your last pastebin will probably be spawning your item perfectly, only it's not being rendered for clients (including the "host" in a sharded world) because anim:SetBank(), anim:SetBuild() and anim:PlayAnimation() are after the ismastersim check.

Link to comment
Share on other sites

http://pastebin.com/7QKEHqAn <- My interpretation of what you added.

Is this what you meant? Are you saying this: 

 inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
		if not TheWorld.ismastersim then
       	 return inst
    	end
            inst.components.insulator:SetSummer()
   
        else
  		if not TheWorld.ismastersim then
        	return inst
    	end
            inst.components.insulator:SetWinter()
 
        end
    end)

Should be moved to fn(sim) instead of onequip?

Link to comment
Share on other sites

15 minutes ago, Monty_Droppings said:

Should be moved to fn(sim) instead of onequip?

If you move it to fn(sim) you don't need to test "if not TheWorld.ismastersim then" because you already tested it before. But i don't know if this code works in the main function.

Also, alainmcd is right, you should have :


 
    inst:AddTag("hat")
   
        --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
    anim:SetBank("featherhat")
       
        --this is what you put in the build.bin when making the hat's .zip file
    anim:SetBuild("wodbhat")
       
        --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
    anim:PlayAnimation("anim")  
          inst.entity:SetPristine()
 
     
    if not TheWorld.ismastersim then
        return inst
    end
     

in this order. You can look at others prefabs to see where the line should be.

So you could try something like :

local assets=
{
    Asset("ANIM", "anim/wodbhat.zip"),
        Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),
    Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),
}
 
--this is what happens when you equip the hat
local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")
    owner.AnimState:Show("HAT")
    owner.AnimState:Show("HAT_HAIR")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")
 
    owner.components.health:SetAbsorptionAmount(.375)
	
    owner.components.health.maxhealth = 25
    owner.components.health:DoDelta(0, true)  -- this updates the health badge
 
   
 
    --this tells it to start losing durability when you equip it
    if inst.components.fueled then
        inst.components.fueled:StartConsuming()        
    end
      
end
 
               
 
--this is what happens when you unequip the hat
local function onunequip(inst, owner)
    owner.AnimState:Hide("HAT")
    owner.AnimState:Hide("HAT_HAIR")
    owner.AnimState:Show("HAIR_NOHAT")
    owner.AnimState:Show("HAIR")
	
	
    owner.components.health:SetAbsorptionAmount(0)
 
    owner.components.health.maxhealth = 5
    owner.components.health:DoDelta(0, true)  -- this updates the health badge
 
    if owner:HasTag("player") then
        owner.AnimState:Show("HEAD")
        owner.AnimState:Hide("HEAD_HAIR")
    end
 
    --this tells it to stop losing durability when you unequip it
    if inst.components.fueled then
        inst.components.fueled:StopConsuming()
    end
  
   
end
 
               
 
--I have no idea why this is called spider_perish but it helps the hat perish!
-- Nik Mik here! It's because the top hat and spider hat use the same function to be destroyed when they run out of fuel.
    local function spider_perish(inst)
        --spider_disable(inst) ain't needed, Fiddoop. That's telling the item to go to another function. E.G if you had the spider_disable_inst and a function with the same name that made the character fart unicorns, the code on this line would tell it to do that function.
        inst:Remove()
        -- This destroys it.
    end
 


local function fn(Sim)
        local inst = CreateEntity()
        local trans = inst.entity:AddTransform()
        local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)

 
    inst:AddTag("hat")
   
        --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
    anim:SetBank("featherhat")
       
        --this is what you put in the build.bin when making the hat's .zip file
    anim:SetBuild("wodbhat")
       
        --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
    anim:PlayAnimation("anim")

	
	inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
	 
       
    --you want to be able to be examined it right?
    inst:AddComponent("inspectable")
   
        --to be honest I don't know what this does
    inst:AddTag("irreplaceable")
 -- I think it means lureplants can't eat it, or something. Nik Mik.
   
        --this is so you can carry it in your inventory
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"
   
        --this adds a sanity boost to your hat! this is half of what top hat gives
	inst:AddComponent("waterproofer")
    inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_LARGE)
    
	
        --this is so the game knows to put it on your head
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD


     
	 inst:AddComponent("insulator")
-- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots. 
    inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
            inst.components.insulator:SetSummer()
   
        else
            inst.components.insulator:SetWinter()
 
        end
    end)
  inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
       
       
 
        --this is so the game knows there is a onequip and onunequip function
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
       
       
    return inst
end
 
return Prefab( "common/inventory/wodbhat", fn, assets)

And see how it works ?

Edited by Lumina
Link to comment
Share on other sites

I just copied your code exactly and it still is not showing up in game. I tested it and it definitely is in the game though, it is taking up an inventory slot but is completely invisible. I then tried moving it after components but its still invisible. 

http://pastebin.com/xiRi7qRJ

 

Edited by Monty_Droppings
Link to comment
Share on other sites

@Monty_Droppings

 

Ok so, if i summarize :

- First the item wasn't here in cave server, even when you tried to spawn it ?

- Now you can pick it up but it's invisible ?
- So there is a change ? The problem isn't exactly the same that at the beginning ?
- In server without cave, all is working fine ?

Could you attach your mod as it is now with the last changes ?
Thanks.

Link to comment
Share on other sites

I maybe found what is wrong.

It seems you have still components in your onequip/onunequip functions. Probably the reason of the problem.

If you look at others hats, here is how they manage that :


    local function winter()
        local inst = simple()

        if not TheWorld.ismastersim then
            return inst
        end

        inst.components.equippable.dapperness = TUNING.DAPPERNESS_TINY
        inst:AddComponent("insulator")
        inst.components.insulator:SetInsulation(TUNING.INSULATION_MED)

        inst:AddComponent("fueled")
        inst.components.fueled.fueltype = FUELTYPE.USAGE
        inst.components.fueled:InitializeFuelLevel(TUNING.WINTERHAT_PERISHTIME)
        inst.components.fueled:SetDepletedFn(inst.Remove)

        return inst
    end

    local function football_custom_init(inst)
        --waterproofer (from waterproofer component) added to pristine state for optimization
        inst:AddTag("waterproofer")
    end

    local function football()
        local inst = simple(football_custom_init)

        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("armor")
        inst.components.armor:InitCondition(TUNING.ARMOR_FOOTBALLHAT, TUNING.ARMOR_FOOTBALLHAT_ABSORPTION)

        inst:AddComponent("waterproofer")
        inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)

        return inst
    end

So you need to add the line :


        if not TheWorld.ismastersim then
            return inst
        end

Before all the part with a "component". Should be something like :

--replace wodbhat with your hat's name

local assets=
{
    Asset("ANIM", "anim/wodbhat.zip"),
        Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),
    Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),
}
 
--this is what happens when you equip the hat
local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")
    owner.AnimState:Show("HAT")
    owner.AnimState:Show("HAT_HAIR")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")
	
        if not TheWorld.ismastersim then
            return inst
        end

 
    owner.components.health:SetAbsorptionAmount(.375)
	
    owner.components.health.maxhealth = 25
    owner.components.health:DoDelta(0, true)  -- this updates the health badge
 
   
 
    --this tells it to start losing durability when you equip it
    if inst.components.fueled then
        inst.components.fueled:StartConsuming()        
    end
      
end
 
               
 
--this is what happens when you unequip the hat
local function onunequip(inst, owner)
    owner.AnimState:Hide("HAT")
    owner.AnimState:Hide("HAT_HAIR")
    owner.AnimState:Show("HAIR_NOHAT")
    owner.AnimState:Show("HAIR")
	
	
    owner.components.health:SetAbsorptionAmount(0)
 
    owner.components.health.maxhealth = 5
    owner.components.health:DoDelta(0, true)  -- this updates the health badge
 
    if owner:HasTag("player") then
        owner.AnimState:Show("HEAD")
        owner.AnimState:Hide("HEAD_HAIR")
    end
	
        if not TheWorld.ismastersim then
            return inst
        end

 
    --this tells it to stop losing durability when you unequip it
    if inst.components.fueled then
        inst.components.fueled:StopConsuming()
    end
  
   
end
 
               
 
--I have no idea why this is called spider_perish but it helps the hat perish!
-- Nik Mik here! It's because the top hat and spider hat use the same function to be destroyed when they run out of fuel.
    local function spider_perish(inst)
        --spider_disable(inst) ain't needed, Fiddoop. That's telling the item to go to another function. E.G if you had the spider_disable_inst and a function with the same name that made the character fart unicorns, the code on this line would tell it to do that function.
        inst:Remove()
        -- This destroys it.
    end
 


local function fn(Sim)
        local inst = CreateEntity()
        local trans = inst.entity:AddTransform()
        local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)

 
    inst:AddTag("hat")
   
        --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
    anim:SetBank("featherhat")
       
        --this is what you put in the build.bin when making the hat's .zip file
    anim:SetBuild("wodbhat")
       
        --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
    anim:PlayAnimation("anim")

	
	inst.entity:SetPristine()

    
        if not TheWorld.ismastersim then
            return inst
        end

	 
       
    --you want to be able to be examined it right?
    inst:AddComponent("inspectable")
   
        --to be honest I don't know what this does
    inst:AddTag("irreplaceable")
 -- I think it means lureplants can't eat it, or something. Nik Mik.
   
        --this is so you can carry it in your inventory
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"
   
        --this adds a sanity boost to your hat! this is half of what top hat gives
	inst:AddComponent("waterproofer")
    inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_LARGE)
    
	
        --this is so the game knows to put it on your head
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD


     
	 inst:AddComponent("insulator")
-- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots. 
    inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
        if TheWorld.state.temperature > 35 then
            inst.components.insulator:SetSummer()
   
        else
            inst.components.insulator:SetWinter()
 
        end
    end)
  inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
       

 
        --this is so the game knows there is a onequip and onunequip function
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
       
       
    return inst
end
 
return Prefab( "common/inventory/wodbhat", fn, assets)

But verify it first. I could have forgot things.

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