Jump to content

Cage Trap refunds all ingredients when broken


Tykvesh

Recommended Posts

  • 41.65
  • Singleplayer
  • No mods

Currently Cage Traps drop pristine wire when broken, allowing you to infinitely recycle them.

 

screenshot_29-01-2022_09-55-44.png.592d213c1dd0c3235ed987bc6e1b00f5.png

 

Considering that there's a special case for Twine, maybe the same logic should be applied to Wire?

function STrapGlobalObject.SpawnDestroyItems(trapType, square, object)
    if square then
        local item = "Base.UnusableWood";

        --traptype might be nil, in that case check isoobject
        if (not trapType) and object and object:hasModData() then
            trapType = object:getModData()["trapType"];
        end

        if trapType then
            for i,v in ipairs(Traps) do
                if v.type == trapType and v.destroyItem then
                    item = v.destroyItem;
                    break;
                end
            end
        end

        if type(item)=="table" then
            for i,v in ipairs(item) do
                local spawnItem = square:AddWorldInventoryItem(v, ZombRand(0.1, 0.5), ZombRand(0.1, 0.5), 0);
                if v=="Base.Twine" then
                    spawnItem:setUsedDelta(spawnItem:getUseDelta());
                end
            end
        else
            local spawnItem = square:AddWorldInventoryItem(item, ZombRand(0.1, 0.5), ZombRand(0.1, 0.5), 0);
            if item=="Base.Twine" then
                spawnItem:setUsedDelta(spawnItem:getUseDelta());
            end
        end
    else
        print("no square for spawnDestroyItems");
    end
end

I'm not sure which one of these is correct, but in theory it should drain any drainables spawned by broken traps:

if spawnItem:IsDrainable() then
	spawnItem:setUsedDelta(spawnItem:getUseDelta())
end
if instanceof(spawnItem, "Drainable") then
	spawnItem:setUsedDelta(spawnItem:getUseDelta())
end
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
×
×
  • Create New...