Jump to content

Crash when searching for player entities


Recommended Posts

I'm trying to make an item that modifies a component when a player is near it. I'm experiencing a crash and there's no log. I know how to check for one- there is no log. At all. Sooo....I'm stumped. Any thoughts of what could be wrong?

 

Spoiler

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

local prefabs =
{

}

function FindEntity(inst)          
	local x, y, z = inst.Transform:GetWorldPosition()        
	local ents = TheSim:FindEntities(x, y, z, 20, {"player"})
	for i, v in ipairs(ents) do
		ents.components.rads.current = ents.components.rads.current + 0.05
	end
end

local function onhammered(inst, worker)
	local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("rock")
    local pos = inst:GetPosition()
    local broken = SpawnPrefab("rocks")
    broken.Transform:SetPosition(pos:Get())
    inst:Remove()
end

	local function common_fn(anim)
        local inst = CreateEntity()

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

        MakeObstaclePhysics(inst, .5)

        --inst.MiniMapEntity:SetPriority(5)
        --inst.MiniMapEntity:SetIcon(name..".png")

        inst.AnimState:SetBank("radrubble")
        inst.AnimState:SetBuild("radrubble")
        inst.AnimState:PlayAnimation(anim)
		
		inst:AddTag("antlion_sinkhole_blocker")
		inst:AddTag("radioactive")
		
		inst.entity:SetPristine()
		
        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("inspectable")

        inst:AddComponent("workable")
        inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
        
        inst.components.workable:SetOnFinishCallback(onhammered)
		
		inst:DoPeriodicTask(1, FindEntity(inst), nil)

        return inst
    end
	
local function radrubble1_fn()
    local inst = common_fn("radrubble1")

    if not TheWorld.ismastersim then
        return inst
    end

    inst.components.workable:SetWorkLeft(1)

    return inst
end

local function radrubble2_fn()
    local inst = common_fn("radrubble2")

    if not TheWorld.ismastersim then
        return inst
    end

    inst.components.workable:SetWorkLeft(3)

    return inst
end

local function radrubble3_fn()
    local inst = common_fn("radrubble3")

    if not TheWorld.ismastersim then
        return inst
    end

    inst.components.workable:SetWorkLeft(3)

    return inst
end

return Prefab("radrubble1", radrubble1_fn, assets, prefabs),
	Prefab("radrubble2", radrubble2_fn, assets, prefabs),
	Prefab("radrubble3", radrubble3_fn, assets, prefabs)

 

 

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