Autotrap with caves


Recommended Posts

Hi

 

I've tried to ameliorate the mod "autotrap" to works with caves (goal of this mod : drop automatically the trap, teeth trap,... when you get the animal in the trap, ...) but i'ven't succeed to understand where is the problem. Can you help me? Code is :

local TheSim = GLOBAL.TheSim
local Vector3 = GLOBAL.Vector3
local SpawnPrefab = GLOBAL.SpawnPrefab

local function TrapComponentPostInit(self)
    function self:Harvest(doer)
        if self.issprung then
            self.inst:PushEvent("harvesttrap")
            if self.onharvest then
                self.onharvest(self.inst)
            end
            
            local timeintrap = self.inst.components.timer and self.inst.components.timer:GetTimeElapsed("foodspoil")
            if self.lootprefabs and doer.components.inventory then
                for k,v in ipairs(self.lootprefabs) do
                    local loot = SpawnPrefab(v)
                    if loot then
                        doer.components.inventory:GiveItem(loot, nil, Vector3(TheSim:GetScreenPos(self.inst.Transform:GetWorldPosition())))
                        if loot.components.perishable and timeintrap then
                            loot.components.perishable:LongUpdate(timeintrap)
                        end
                    end
                end
            end
            self:Reset()
            self.inst:PushEvent("ondropped") -->-- MOD
        else                                 --<-- MOD
            if self.inst.components.finiteuses and self.inst.components.finiteuses:GetUses() > 0 then
                doer.components.inventory:GiveItem(self.inst, nil, Vector3(TheSim:GetScreenPos(self.inst.Transform:GetWorldPosition())))
            end
        end
    end
end

AddComponentPostInit("trap", TrapComponentPostInit)

Regards

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.