Sign in to follow this  
sanok15

How to add a custom item?

Recommended Posts

sanok15    1

Hello again, I tried to add a custom item, which can only be used and crafted by my custom character, but I don't get it...
The item should be a throwing star/shuriken. It should do damage like a spear (maybe less, not sure about that) and the item should be stackable up to 15 times. After throwing and doing damage the item should disappear like a blow dart. The item should be craftable without a science machine or alchemie machine in an extra tab. 

Thank you for your help :) 

Share this post


Link to post
Share on other sites
sanok15    1
11 minutes ago, Ultroman said:

Which part don't you get? How much have you already done?

I copied the .lua of an item and tried to changed the code. If I start the game, I don't get an error, but I also can't find or use the Item ingame. I don't know what I have to do, that the item is really implemented.

Share this post


Link to post
Share on other sites
Ultroman    537

Well, your item need animations. Otherwise it won't load it. Other than that, it's difficult to help without seeing your mod. Can you zip it up and attach it to a reply here?

Share this post


Link to post
Share on other sites
sanok15    1
16 minutes ago, Ultroman said:

Well, your item need animations. Otherwise it won't load it. Other than that, it's difficult to help without seeing your mod. Can you zip it up and attach it to a reply here?

Ok, this is my current mod. The item i've copied was in scripts/prefabs. Sadly i've deleted it after it didn't work, but I just tried to change the name etc.

WalburgaMod.rar

Share this post


Link to post
Share on other sites
Ultroman    537

There are plenty of mod characters who have custom weapons. Check out the code for those. It might even be easier to start by making the item as a stand-alone mod, and then when it works you can move it into your character mod.

Once you've created your weapon, if you want to make a character-specific recipe for it or make other characters unable to pick it up, this post shows how to do that. That post also has a small paragraph at the beginning, which tells you how to move a stand-alone item mod into a character mod.

Share this post


Link to post
Share on other sites
sanok15    1
4 minutes ago, Ultroman said:

There are plenty of mod characters who have custom weapons. Check out the code for those. It might even be easier to start by making the item as a stand-alone mod, and then when it works you can move it into your character mod.

Once you've created your weapon, if you want to make a character-specific recipe for it or make other characters unable to pick it up, this post shows how to do that. That post also has a small paragraph at the beginning, which tells you how to move a stand-alone item mod into a character mod.

ok thank you :) 

Share this post


Link to post
Share on other sites
Ultroman    537

You're welcome! :) Godspeed with it. When you've tried some things out and run into a problem, just post here. I'll try to help. But you can't beat what you can learn by just reading what other people have done, looking at their files and the folder structure. Perhaps start by looking at mods which add a few simple items, like this mod. Just know that the animations in these mods are compiled from animations created in a program called Spriter, which comes with the Don't Starve Mod Tools. I've never made animations, so I can't help with that part. It's not easy, but it's something you'll have to learn if you want to make characters and items.

This is a good template and thread for creating character animations.

Share this post


Link to post
Share on other sites
sanok15    1
11 hours ago, Ultroman said:

You're welcome! :) Godspeed with it. When you've tried some things out and run into a problem, just post here. I'll try to help. But you can't beat what you can learn by just reading what other people have done, looking at their files and the folder structure. Perhaps start by looking at mods which add a few simple items, like this mod. Just know that the animations in these mods are compiled from animations created in a program called Spriter, which comes with the Don't Starve Mod Tools. I've never made animations, so I can't help with that part. It's not easy, but it's something you'll have to learn if you want to make characters and items.

This is a good template and thread for creating character animations.

So, I did it :) thanks ^^.
Another question, I want to increase the fire and ice staff's damage while wearing a top hat. Any idea how to do this?
How to ask for an item that is equipped in "equipslot head" and how to increase the damage of the staffs.


 

Share this post


Link to post
Share on other sites
Ultroman    537

Forgive my ignorance, as I don't actively play the game, but looking at the code, it doesn't look like any of the staves or their projectiles do any damage, but only apply coldness or ignite the target, respectively. Anywhere it applies damage in their code the damage number is 0.

If you would like to add that they do a certain amount of damage, but only if the attacker is your character and the character is wearing a top hat, we can do that. Is that what you're asking?

Share this post


Link to post
Share on other sites
sanok15    1
58 minutes ago, Ultroman said:

Forgive my ignorance, as I don't actively play the game, but looking at the code, it doesn't look like any of the staves or their projectiles do any damage, but only apply coldness or ignite the target, respectively. Anywhere it applies damage in their code the damage number is 0.

If you would like to add that they do a certain amount of damage, but only if the attacker is your character and the character is wearing a top hat, we can do that. Is that what you're asking?

yeah that is what i meant :) 

Share this post


Link to post
Share on other sites
Ultroman    537

These should go in your modmain.lua.

This is the code for the ice projectile:

AddPrefabPostInit("ice_projectile", function(inst)
	local oldOnHit = inst.components.projectile.onhit
	local newOnHit = function(inst, owner, target)
		if oldOnHit then
			oldOnHit(inst, owner, target)
		end
		
		if owner == nil or not owner:IsValid() or target == nil or not target:IsValid() then
			return
		end

		local headItem = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
		
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" and headItem ~= nil and headItem:IsValid() and headItem.prefab == "tophat" then
			if target.components.combat then
				-- This is the line that does damage to targets with a combat component. Change the amount (5) to whatever you'd like.
				target.components.combat:GetAttacked(owner, 5, nil)
			elseif target.components.health then
				-- This is the line that does damage to non-combatants with a health component. Change the amount (5) to whatever you'd like.
				target.components.health:DoDelta(5, false, "ice_projectile", false, owner, false)
			end
		end
	end
	inst.components.projectile:SetOnHitFn(newOnHit)
end

This is the code for the fire projectile:

AddPrefabPostInit("fire_projectile", function(inst)
	local oldOnHit = inst.components.projectile.onhit
	local newOnHit = function(inst, owner, target)
		if oldOnHit then
			oldOnHit(inst, owner, target)
		end
		
		if owner == nil or not owner:IsValid() or target == nil or not target:IsValid() then
			return
		end

		local headItem = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
		
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" and headItem ~= nil and headItem:IsValid() and headItem.prefab == "tophat" then
			if target.components.combat then
				-- This is the line that does damage to targets with a combat component. Change the amount (5) to whatever you'd like.
				target.components.combat:GetAttacked(owner, 5, nil)
			elseif target.components.health then
				-- This is the line that does damage to non-combatants with a health component. Change the amount (5) to whatever you'd like.
				target.components.health:DoDelta(5, false, "fire_projectile", false, owner, false)
			end
		end
	end
	inst.components.projectile:SetOnHitFn(newOnHit)
end

 

If it complains about EQUIPSLOTS being a GLOBAL, then put in GLOBAL.EQUIPSLOTS where it says EQUIPSLOTS.

Also, remember to substitute YOUR_CHARACTER_PREFAB_NAME with your character's prefab name.

  • Like 1

Share this post


Link to post
Share on other sites
sanok15    1
On 7.9.2019 at 1:34 AM, Ultroman said:

These should go in your modmain.lua.

This is the code for the ice projectile:


AddPrefabPostInit("ice_projectile", function(inst)
	local oldOnHit = inst.components.projectile.onhit
	local newOnHit = function(inst, owner, target)
		if oldOnHit then
			oldOnHit(inst, owner, target)
		end
		
		if owner == nil or not owner:IsValid() or target == nil or not target:IsValid() then
			return
		end

		local headItem = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
		
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" and headItem ~= nil and headItem:IsValid() and headItem.prefab == "tophat" then
			if target.components.combat then
				-- This is the line that does damage to targets with a combat component. Change the amount (5) to whatever you'd like.
				target.components.combat:GetAttacked(owner, 5, nil)
			elseif target.components.health then
				-- This is the line that does damage to non-combatants with a health component. Change the amount (5) to whatever you'd like.
				target.components.health:DoDelta(5, false, "ice_projectile", false, owner, false)
			end
		end
	end
	inst.components.projectile:SetOnHitFn(newOnHit)
end

This is the code for the fire projectile:


AddPrefabPostInit("fire_projectile", function(inst)
	local oldOnHit = inst.components.projectile.onhit
	local newOnHit = function(inst, owner, target)
		if oldOnHit then
			oldOnHit(inst, owner, target)
		end
		
		if owner == nil or not owner:IsValid() or target == nil or not target:IsValid() then
			return
		end

		local headItem = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
		
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" and headItem ~= nil and headItem:IsValid() and headItem.prefab == "tophat" then
			if target.components.combat then
				-- This is the line that does damage to targets with a combat component. Change the amount (5) to whatever you'd like.
				target.components.combat:GetAttacked(owner, 5, nil)
			elseif target.components.health then
				-- This is the line that does damage to non-combatants with a health component. Change the amount (5) to whatever you'd like.
				target.components.health:DoDelta(5, false, "fire_projectile", false, owner, false)
			end
		end
	end
	inst.components.projectile:SetOnHitFn(newOnHit)
end

 

If it complains about EQUIPSLOTS being a GLOBAL, then put in GLOBAL.EQUIPSLOTS where it says EQUIPSLOTS.

Also, remember to substitute YOUR_CHARACTER_PREFAB_NAME with your character's prefab name.

Thank you again ^^

  • Like 1

Share this post


Link to post
Share on other sites

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

Sign in to follow this