Jump to content

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
https://forums.kleientertainment.com/forums/topic/69097-probably-easy-question/
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.

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

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.

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.

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