Jump to content

Recommended Posts

Hello there!

In advance: I'm super grateful for every information piece, even for the tiniest ones. I don't expect finished codings, pointing me to the right direction fully fills my needs (though, I don't mind some polished codings if it's on the tip of your tongue).  Thanks for every selfless, nameless hero :)

The questions:

1) [Solved] How can I make a custom tool into a multitool (alias function as an axe, pickaxe, hammer and as a weapon)?

Solution:

Spoiler

inst:AddTag("sharp")
    inst:AddTag("possessable_axe")
    inst:AddTag("tool")
    inst:AddTag("hammer")
    inst:AddTag("weapon")
    
    if not TheWorld.ismastersim then
        return inst
    end
    inst.entity:SetPristine()
    
    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.MINE, 20)
    inst.components.tool:SetAction(ACTIONS.HAMMER, 20)
    inst.components.tool:SetAction(ACTIONS.CHOP, 20)
    
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(125)
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(3)
    inst.components.finiteuses:SetUses(3)
    inst.components.finiteuses:SetConsumption(ACTIONS.CHOP, 1)
    inst.components.finiteuses:SetConsumption(ACTIONS.MINE, 1)
    inst.components.finiteuses:SetConsumption(ACTIONS.HAMMER, 1)

 

 

2) [Solved] How can I change how much swings does it takes to chop down a tree by a custom axe? I would like this earlier said multitool to be able to chop/mine/demolish things with only one swing.

Solution: 
 

Spoiler

 

inst:AddComponent("tool")

inst.components.tool:SetAction(ACTIONS.CHOP, 20) -- You can manipulate the swing power by changing the number here. The current number makes the tool chop any tree by one swing. 

 

 

 

3) [Solved] The custom tool only leaves your inventory on 0% durability if you add the following line, right? (I don't want my tool to leave my inventory) Solution: I was right.

Spoiler

inst.components.finiteuses:SetOnFinished(inst.Remove)

 

4) How can I add a durability-restore item to my custom tool? I would like to make gems restore said tool's durability to 100%.

5) I would like my tool to change it's texture when it's on 0%. How can I achieve this?

 

Thanks in advance! Have a wonderful day!

Edited by BillTheCipher
  • Like 1

1) Look in the pick-axe code. That's a multitool

2) The should be the efficiency attribute.

3) I think so

4) I think you can make it re-fuel able but I don't know how

5) I don't know. I haven't worked with textures, but look into how chester's eyebone works

 

Hoped this answers at least some of your questions.

  • Like 1

For 1) ~ 4), Take a look at this.

 

For 5), you could use this code

local function ChangeTexture(inst)
  if inst.components.finiteuses and inst.components.finiteuses:GetPercent() == 0 then
    inst.components.inventoryitem:ChangeImageName("blahblah_ded")
  else
    inst.components.inventoryitem:ChangeImageName("blahblah")
  end
end
  
local function onequip(inst, owner)
  ChangeTexture(inst)
  if inst.components.finiteuses and inst.components.finiteuses:GetPercent() == 0 then
    owner.AnimState:OverrideSymbol("swap_object", "swap_blahblah_empty", "swap_blahblah_empty")
  else
    owner.AnimState:OverrideSymbol("swap_object", "swap_blahblah", "swap_blahblah")
  end
  --oneqiup codes here
end
=========================
inst.components.finiteuses:SetOnFinished(ChangeTexture)
  • Like 1

I did something about the 4) How can I add a durability-restore item to my custom tool? I would like to make gems restore said tool's durability to 100%.
for a mod i'm working on right now where there is a gem that give it one more use, what i did was that the gems were an edible item, 

--this function adds durability to the item
local function PushMana(inst, eater)
	if eater.components.inventory then
    --this function looks for the item on your inventory or your equipslots (thaks to Combustiblemon he helped me with this part)
		local itemfound = function(func)
			for k,v in pairs(eater.components.inventory.itemslots) do
				if func(v) then
					return v
				end
			end
			for k,v in pairs(eater.components.inventory.equipslots) do
				if func(v) then
					return v
				end
			end
			if eater.components.inventory.activeitem and fn(eater.components.inventory.activeitem) then
        		return eater.components.inventory.activeitem
    		end

    		local overflow = eater.components.inventory:GetOverflowContainer()
    		return overflow ~= nil and overflow:FindItem(fn) or nil
		end
		--here you use the function we just created to look for the item(your sword)
		local item = itemfound(function(item) return item.prefab == "name of yor item prefab" end)
    
		if item ~= nil then
			local uses = item.components.finiteuses.current
				item.components.finiteuses:SetUses(uses+1)      -- here i add  one use, if you want to add more change the part  uses+1
		end
	end
end
-----------------------
-----------------------
inst:AddComponent("edible")
	inst.components.edible.oneaten = PushMana -- this is to make the function work

 

  • Like 1
5 hours ago, Hector1324 said:

		if item ~= nil then
			local uses = item.components.finiteuses.current
				item.components.finiteuses:SetUses(uses+1)      -- here i add  one use, if you want to add more change the part  uses+1
		end

 

@Hector1324

For your question, use this code.

if item ~= nil then
    local origper = item.components.finiteuses:GetPercent()
	item.components.finiteuses:SetPercent(1) --"1" for 100%, "origper+0.1" for 10% recharge, "origper+0.2" for 20%, and so on.
end

if you want just set to instant full durability not some recharge, then "local origper = ..." line is not needed, you could delete it.

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