回答如下:以下是饥荒中路灯的代码:
local assets=
{
Asset("ANIM", "anim/lamp_post.zip"),
Asset("ANIM", "anim/lamp_post2.zip"),
Asset("ANIM", "anim/candelabra.zip"),
Asset("ANIM", "anim/mushroom_light.zip"),
Asset("ANIM", "anim/orangestaff.zip"),
Asset("ANIM", "anim/atrium_light.zip"),
Asset("ANIM", "anim/atrium_light_small.zip"),
Asset("ANIM", "anim/campfire_fire.zip"),
Asset("ANIM", "anim/campfire_firepit.zip"),
Asset("ANIM", "anim/torch.zip"),
Asset("ANIM", "anim/torch_flame.zip"),
Asset("ANIM", "anim
ightlight.zip"),
Asset("ANIM", "anim/fireflies.zip"),
Asset("ANIM", "anim/evergreen_burnt_build.zip"),
Asset("SOUND", "sound/common.fsb"),
}
local prefabs =
{
"collapse_small",
"fireflies",
}
local function onhammered(inst, worker)
inst.components.lootdropper:DropLoot()
local fx = SpawnPrefab("collapse_small")
fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
fx:SetMaterial("wood")
inst:Remove()
end
local function onhit(inst, worker)
inst.AnimState:PlayAnimation("hit")
inst.AnimState:PushAnimation("idle")
end
local function onbuilt(inst)
inst.AnimState:PlayAnimation("place")
inst.AnimState:PushAnimation("idle")
end
local function newpostfx()
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
inst.entity:AddLight()
inst:AddTag("DECOR")
inst:AddTag("NOCLICK")
inst:AddTag("NOBLOCK")
inst.AnimState:SetBank("lamp_post")
inst.AnimState:SetBuild("lamp_post")
inst.AnimState:PlayAnimation("idle")
inst.Light:SetIntensity(.75)
inst.Light:SetRadius(1.5)
inst.Light:SetFalloff(.8)
inst.Light:SetColour(180/255, 195/255, 150/255)
inst.Light:Enable(true)
inst:AddComponent("inspectable")
inst:AddComponent("lootdropper")
inst:AddComponent("workable")
inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
inst.components.workable:SetWorkLeft(2)
inst.components.workable:SetOnFinishCallback(onhammered)
inst.components.workable:SetOnWorkCallback(onhit)
inst:ListenForEvent("onbuilt", onbuilt)
return inst
end
return Prefab( "common/objects/lamppost", newpostfx, assets, prefabs)