Jump to content

Recommended Posts

I'm trying to make a custom structure that's kind of like the meat effigy where u can revive with it, heals everyone nearby when interacted with and can only be seen by my modded character. I have tried everything and all it does is give me the "Dedicated server failed to start" every time. I'm no coder and all I can do is the drawing part

https://steamcommunity.com/sharedfiles/filedetails/?id=445182091&searchtext=example+structure

 

Sample structure if this helps lol. The first 2 easily sound doable but idk how you'd make something only visible to a specific character.

I had my hand at making a custom structure for the first time recently, and Idk if it was just me but the sample structure on the workshop didn't work properly for me (It DOES work, but I had issues with stuff like the placer)

Instead I used the code for potted ferns as a base, here's the code if you want it

Spoiler
require "prefabutil"

local assets =
{
    Asset("ANIM", "anim/YOURPREFAB.zip"),
}

local prefabs =
{
    "collapse_small",
}

local function onsave(inst, data)
    data.anim = inst.animname
end

local function onload(inst, data)
    if data ~= nil and data.anim ~= nil then
        inst.animname = data.anim
        inst.AnimState:PlayAnimation(inst.animname)
    end
    if inst.skinname then
        inst.AnimState:PlayAnimation("c")
    end
end

local function onhammered(inst)
    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("pot") -- Sound it will make when destroyed, meat effigy uses "wood"
    inst.components.lootdropper:DropLoot()
    inst:Remove()
end

local function fn()
    local inst = CreateEntity()

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

	inst:SetDeploySmartRadius(0.45) --recipe min_spacing/2

    inst.AnimState:SetBank("YOURPREFAB")
    inst.AnimState:SetBuild("YOURPREFAB")
  
    inst:AddTag("YOURPREFAB")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")

    MakeSmallBurnable(inst)
    MakeSmallPropagator(inst)
    MakeHauntableWork(inst)

    inst:AddComponent("workable")
    inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
    inst.components.workable:SetWorkLeft(1)
    inst.components.workable:SetOnFinishCallback(onhammered)

    inst:AddComponent("lootdropper")

    MakeHauntableWork(inst)

    --------SaveLoad
    inst.OnSave = onsave
    inst.OnLoad = onload

    return inst
end

return Prefab("YOURPREFAB", fn, assets, prefabs),
    MakePlacer("YOURPREFAB_placer", "YOURPREFAB", "YOURPREFAB", "idle")

 

modmain:

Spoiler
PrefabFiles = {
 	-- Other stuff
  "YOURPREFAB",
 }

Assets = {
 	-- Other stuff
 	Asset("ATLAS", "images/inventoryimages/YOURPREFAB.xml"),
    Asset("IMAGE", "images/inventoryimages/YOURPREFAB.tex"),
 }

AddMinimapAtlas("images/inventoryimages/YOURPREFAB.xml")

RegisterInventoryItemAtlas("images/inventoryimages/YOURPREFAB.xml", "YOURPREFAB.tex") -- Add this if the icon isn't appearing

-- Put at bottom

local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local TECH = GLOBAL.TECH	

AddCharacterRecipe("YOURPREFAB", -- If you want other characters to craft it too, use AddRecipe2 instead
	{ -- ingredients
		GLOBAL.Ingredient("twigs", 2),
		GLOBAL.Ingredient("cutgrass", 2),
	},
	GLOBAL.TECH.SCIENCE_ONE, -- NONE, SCIENCE_ONE, SCIENCE_TWO, MAGIC_TWO, MAGIC_THREE, etc.
	{ -- config
		builder_tag = "YOURCHARACTER", -- Keep if only your character can build this, otherwise delete this line
		atlas = "images/inventoryimages/YOURPREFAB.xml",
		placer = "YOURPREFAB_placer",
	}, 
	{ -- filters
		"STRUCTURES",
		"MODS",
	}
)

 

Sorry if there's any mistakes

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