Jump to content

lack of return statement after removing entity in moon_device.lua


hoxi
  • Pending
local function meteor_invitem_behaviour(inst, v)
    local x, y, z = inst.Transform:GetWorldPosition()

    if v.components.container ~= nil then
        -- Spill backpack contents, but don't destroy backpack
        if math.random() <= TUNING.METEOR_SMASH_INVITEM_CHANCE then
            v.components.container:DropEverything()
        end
    elseif v.components.mine ~= nil and not v.components.mine.inactive then
        -- Always smash things on the periphery so that we don't end up with a ring of flung loot
        v.components.mine:Deactivate()
    elseif math.random() <= TUNING.METEOR_SMASH_INVITEM_CHANCE and not v:HasTag("irreplaceable") then
        -- Always smash things on the periphery so that we don't end up with a ring of flung loot
        local vx, vy, vz = v.Transform:GetWorldPosition()
        SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(vx, 0, vz)
        v:Remove()
        -- HERE, shouldn't we be stopping the function from progressing any further?
    end

    if not v.components.inventoryitem.nobounce then
        Launch(v, inst, TUNING.LAUNCH_SPEED_SMALL)
    elseif v.Physics ~= nil and v.Physics:IsActive() then
        local vx, vy, vz = v.Transform:GetWorldPosition()
        local dx, dz = vx - x, vz - z
        local spd = math.sqrt(dx * dx + dz * dz)
        local angle = (spd > 0 and math.atan2(dz / spd, dx / spd) + (math.random() * 20 - 10) * DEGREES)
            or math.random() * 2 * PI
        spd = 3 + math.random() * 1.5
        v.Physics:Teleport(vx, 0, vz)
        v.Physics:SetVel(math.cos(angle) * spd, 0, math.sin(angle) * spd)
    end
    v.components.inventoryitem:SetLanded(false, true)
end

Not sure if this can cause a crash or not as I haven't tested it, but it's obviously not good to continue working with an invalid entity.


Steps to Reproduce

Drop items around/on top of the lunar siphonator before completing it, and then complete it. Items that get destroyed by the ClearArea call will be the ones affected by this.




User Feedback


There are no comments to display.



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