Jump to content

Recommended Posts

Hello!

I want for all my selected prefabs in the line:

     inst.components.workable: SetWorkLeft ("number")

Replace "number" with "number * TUNING.MY_FIRMNESS"
Can you help me with this?

Thank you for your attention.

Edited by Tezumoto

Using addprefabpostinit we can make a function to add this feature to all your prefabs

local workableprefabs = {"spoiled_food","spoiled_fish", "mosquitosack", "silk", "spidergland", "poop", "stinger", "cutgrass", "twigs", "guano"} --prefab examples, change to your own.
for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) 
	if GLOBAL.TheWorld.ismastersim then
		--if not inst.components.workable then inst:AddComponent("workable") end --not really needed if your prefabs have the workable component already.
		if inst.components.workable then inst.components.workable:SetWorkLeft ("number") end
	end
end) end

 

Edited by IronHunter
41 minutes ago, IronHunter said:

Using addprefabpostinit we can make a function to add this feature to all your prefabs


local workableprefabs = {"spoiled_food","spoiled_fish", "mosquitosack", "silk", "spidergland", "poop", "stinger", "cutgrass", "twigs", "guano"} --prefab examples, change to your own.
for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) 
	if GLOBAL.TheWorld.ismastersim then
		if not inst.components.disappears then inst:AddComponent("workable") end
		if inst.components.workable then inst.components.workable:SetWorkLeft ("number") end
	end
end) end

 

This function change the SetWorkLeft for all prefabs by the number that I specify?
Can not change this number from prefabs, but simply multiply by 3?

I use this code:

local workableprefabs = {
"pigtorch",
"ancient_altar_broken"
} --prefab examples, change to your own.
for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) 
	if GLOBAL.TheWorld.ismastersim then
		if not inst.components.disappears then inst:AddComponent("workable") end
		if inst.components.workable then inst.components.workable:SetWorkLeft(20) end
	end
end)
end

But these things just stopped to react to the hammer and the others. (become indestructible)

Edited by Tezumoto
44 minutes ago, Tezumoto said:

This function change the SetWorkLeft for all prefabs by the number that I specify?
Can not change this number from prefabs, but simply multiply by 3?

I use this code:


local workableprefabs = {"pigtorch","ancient_altar_broken"}
for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) 
	if GLOBAL.TheWorld.ismastersim then
		if not inst.components.disappears then inst:AddComponent("workable") end
		if inst.components.workable then inst.components.workable:SetWorkLeft(20) end
	end
end)
end

But these things just stopped to react to the hammer and the others. (become indestructible)

I made a typo when copy/pasting my similar code, instead of disappears it should be workable, as for why they are indestructable

local workableprefabs = {"pigtorch","ancient_altar_broken"}
for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) 
	if GLOBAL.TheWorld.ismastersim then
		if inst.components.workable then inst.components.workable:SetWorkLeft(2) end
	end
end)end

I just tested this it works fine for me, object updated properly and hammers correctly

Edited by IronHunter
28 minutes ago, IronHunter said:

I made a typo when copy/pasting my similar code, instead of disappears it should be workable, as for why they are indestructable

I just tested this it works fine for me, object updated properly and hammers correctly

I can, don't change the default value, but just multiply it by a certain value?

if inst.components.workable then inst.components.workable:SetWorkLeft(*2) end

 

Edited by Tezumoto
1 minute ago, Tezumoto said:

I can, don't change the default value, but just multiply it by a certain value?


if inst.components.workable then inst.components.workable:SetWorkLeft(*2) end

 

A strange request but I guess you could do

inst.components.workable.workleft = inst.components.workable.workleft * 2

6 hours ago, IronHunter said:

A strange request but I guess you could do

inst.components.workable.workleft = inst.components.workable.workleft * 2

Thank you, you helped me a lot.
But still I have some problems.
I need to create two separate functions to forbid: 1) "repairable" and 2) "workable" for prefabs.

Edited by Tezumoto

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