Jump to content

probably easy question


Recommended Posts

as a prerequisite to my mod, i simply need to make every item (preferably just every item with durability) "give"-able, by adding the component tradeable.

i have tried

if not inst.components.tradable then
    inst:AddComponent("tradable")
end     

but that doesnt seem to work. i have seem people individually add the components tradable for many items, but that seems downright ridiculous for every single item, and it wouldn't work for mod items.

reasons why that doesn't work and a solution would be greatly appreciated.

Link to comment
Share on other sites

i saw code like that before, and that indeed makes rope and nightmarefuel tradeable, but is there truly no way to apply it to groups or all items at once? 

i was hoping there would be something like

 

AddPrefabPostInit("inst.components.finiteuses", MakeTradable

but that just crashes my game.

Link to comment
Share on other sites

by "do stuff" do you mean to add

local function MakeTradable(inst)
	if not inst.components.tradable then
    	inst:AddComponent("tradable")
    end
end

to make the end result

AddComponentPostInit("finiteuses", function(self)
  local function MakeTradable(inst)
    if not inst.components.tradable then
        inst:AddComponent("tradable")
    end
end
end)

?

because that doesn't do anything at all

Link to comment
Share on other sites

local function MakeTradable(inst)
	if not inst.components.tradable then
		inst:AddComponent("tradable")
	end
end

AddComponentPostInit("finiteuses", function(self)
	local inst = self.inst
	MakeTradable(inst)
end)

 

Link to comment
Share on other sites

unfortunatly that still doesn't work. i'm not sure if the code doesn't work or i just put it in wrong. my whole modmain is

local function OnGetItemFromPlayer(prefab, giver, inst)
    prefab.components.prototyper.onactivate()
        prefab:DoTaskInTime(1.5, MakeLoot)
            prefab.components.dropper:MakeLoot("goldnugget")
        
end

--recycler:
local function recycleengine(prefab)
    prefab:AddComponent("trader")
    prefab:AddComponent("dropper")

    prefab.components.trader:SetAcceptTest(
        function(prefab, inst)
            return inst.components.finiteuses
        end)
    prefab.components.trader.onaccept = OnGetItemFromPlayer
    prefab.components.trader.onrefuse = OnRefuseItem
end
    
AddPrefabPostInit("researchlab", recycleengine)

local function MakeTradable(inst)
    if not inst.components.tradable then
        inst:AddComponent("tradable")
    end
end

AddComponentPostInit("finiteuses", function(self)
    local inst = self.inst
    MakeTradable(inst)
end)

 

 

 

it doesn't crash or anything, but it doesn't show a give prompt or do anything when i hover, say, an axe over the science machine or the pig king. other tradable items like a spear are succesfully put into the sciencemachine and return a peice of gold.

Link to comment
Share on other sites

Your code didn't make me crash, but made my HUD disappear, then freeze when opening the log.

"dropper" is not a component.

OnRefuseItem is a nil value.

local function MakeLoot(inst)
	inst.components.lootdropper:SpawnLootPrefab("goldnugget")
end

local function OnGetItemFromPlayer(inst, giver, item)
	inst.components.prototyper.onactivate()
	inst:DoTaskInTime(1.5, MakeLoot)
end

local function AcceptTest(inst, item, giver)
	return item.components.finiteuses
end

-- recycler:
local function recycleengine(inst)
	if not inst.components.lootdropper then
		inst:AddComponent("lootdropper")
	end

	inst:AddComponent("trader")
	inst.components.trader:SetAcceptTest(AcceptTest)
	inst.components.trader.onaccept = OnGetItemFromPlayer
end

AddPrefabPostInit("researchlab", recycleengine)

local function MakeTradable(inst)
	if not inst.components.tradable then
		inst:AddComponent("tradable")
	end
end

AddComponentPostInit("finiteuses", function(self)
	local inst = self.inst
	MakeTradable(inst)
end)

Use this.

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.

×
  • Create New...