Sign in to follow this  
Scrumch

Character only item help

Recommended Posts

Scrumch    7

Hey, so my mod is nearly done, but I've just got one more thing to add, a character-exclusive item. The item itself is a hood that's supposed to give insulation, sanity regain and a bit of armor. The only problem is that I don't know how to make an item only craft-able by a mod character. I used the hat template and made it  a standalone mod, but I have no idea how to combine it with my character's main mod file.

Any help would be appreciated, thanks. 

20190509004821_1.jpg

Share this post


Link to post
Share on other sites
Ultroman    340
Posted (edited)

First of all, I have to make sure that we're talking about a DST mod here. You've posted in the Don't Starve Mods and Tools forum instead of the Don't Starve Together Mods and Tools forum, but it looks from your screenshot like you are playing Don't Starve Together. Also, you want to make the recipe only usable by your character, which is something that makes no sense in Don't Starve, since it's singleplayer. I'm going ahead assuming you are talking about a DST mod here.
EDIT: I'm an idiot. This is DS.

In order to "merge" the character mod and the item mod, you simply merge the file structures. Obviously you should discard the modinfo.lua of the item mod and take the code from the item mod's modmain.lua and merge it with the character's modmain.lua. Most of the code will be copy/paste, but you'll need to merge the "prefabs" and "assets" lists (and any other similar things I'm forgetting) in the modmain.lua files.

How to make a character-specific recipe?
EDIT:
For DS, simply put the Recipe() function call in the character's master_postinit() or fn() (see K1NGT1GER609's post below for more details).

For DST, use the following instructions!

In order to make the recipe character-specific in DST, you just have to employ the builder_tag parameter of the AddRecipe function. AddRecipe has the following parameters:
AddRecipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive, builder_tag, atlas, image, testfn, product)

All you have to do, is use a tag unique to your character (if you don't have one, just add one), and put that in the builder_tag parameter. Presto! You can leave all but the first four parameters as nil.

How to make it so no one else can pick up a custom item, like Thor's hammer?
EDIT:
The following works for both DS and DST (at the time of writing).
You can do that by adding this code at the bottom of your item prefab LUA's fn() or postinit() function:

local oldOnPickup = inst.components.inventoryitem.OnPickup
inst.components.inventoryitem.OnPickup = function(self, pickupguy)
	if pickupguy.prefab == "YOUR_CHARACTER_PREFAB_NAME" then
		if not self.inst.itemowner then
			self.inst.itemowner = pickupguy
		end
		if pickupguy == self.inst.itemowner then
			oldOnPickup(self, pickupguy)
		elseif pickupguy.components.talker then
			pickupguy.components.talker:Say("That item is not mine.")
		end
	elseif pickupguy.components.talker then
		pickupguy.components.talker:Say("I cannot wield that.")
	end
end

 

Edited by Ultroman
Clarified some things, and included both the DS and DST ways of doing things.

Share this post


Link to post
Share on other sites
Ultroman    340

This will not prevent anyone from picking up your backpack, and thus carry around the item, but as soon as they try to pick it up, it should prevent them from doing so. Test it, because I'm not sure.

Share this post


Link to post
Share on other sites
K1NGT1GER609    120
Posted (edited)

@Ultroman Erm he is actually playing don't starve because the combined status mod on dst doesn't have a krampus meter and if you look at his inventory it doesn't have the self inspect button near his equip-ables (I could also say that the chest resolution is lower than the dst one, as dst did update the pictures of most items). The final note on why you want to make a recipe only craftable by the said character is because when you play as another character and have the mod enabled, that other character has access to the modded character's items (I know I get lazy on disabling mods in single player).

Anyways to make a recipe only accessable to the modded character is simple as putting the recipe code in the character lua, under the main function where all his stats are like so:

local fn = function(inst) --main character function

local armor_device = Recipe("customhatimade", { Ingredient("purplegem", 1),  Ingredient("goldnugget",10) }, RECIPETABS.SCIENCE, {SCIENCE=2})
    armor_device.atlas = "images/inventoryimages/customhatimade.xml"

inst.components.health:SetMaxHealth(200) --reference on where the code goes
    inst.components.hunger:SetMax(200)
    inst.components.sanity:SetMax(200)

end

If the mod crashes when you do this you might need this in the modmain:

local TECH = GLOBAL.TECH
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local resolvefilepath = GLOBAL.resolvefilepath
local ACTIONS = GLOBAL.ACTIONS
local Action = GLOBAL.Action

As for making an item character specific I'd go try ultroman's code, seems right. (Also nice job on the art for the character)

Edited by K1NGT1GER609
  • Like 1

Share this post


Link to post
Share on other sites
Ultroman    340
3 minutes ago, K1NGT1GER609 said:

snip

Thanks for clearing all that up. I wasn't too sure about the DST-thing, which is why I wrote that paragraph xD

And yes, that would also be how I'd create a character-only recipe for DS.

I have edited my previous post to clarify things, so it is better suited for when people stumble upon it in the future.

Share this post


Link to post
Share on other sites
Scrumch    7
Posted (edited)

Thanks for the compliment, K1NGT1GER609. There's just one problem. I can't get the item doesn't appear when I drop it on the floor. Any help? 

Here's the code for the item

Quote

local assets=

    Asset("ANIM", "anim/wakes_hood.zip"),
    Asset("ANIM", "anim/wakes_hood_swap.zip"), 

    Asset("ATLAS", "images/inventoryimages/wakes_hood.xml"),
    Asset("IMAGE", "images/inventoryimages/wakes_hood.tex"),
}

local prefabs = 
{
}

local function fn()

    local function OnEquip(inst, owner) 
        owner.AnimState:OverrideSymbol("swap_hat", "wakes_hood_swap", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Show("HAT_HAIR")
        owner.AnimState:Hide("HAIR_NOHAT")
        owner.AnimState:Hide("HAIR")
        print('A')
        if owner:HasTag("player") then
            print('B')
            owner.AnimState:Hide("HEAD")
            owner.AnimState:Show("HEAD_HAIR")
        end
    end

    local function OnUnequip(inst, owner) 
        owner.AnimState:Hide("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Show("HAIR_NOHAT")
        owner.AnimState:Show("HAIR")

        if owner:HasTag("player") then
            owner.AnimState:Show("HEAD")
            owner.AnimState:Hide("HEAD_HAIR")
        end
    end

    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("wakes_hood")
    anim:SetBuild("wakes_hood")
    anim:PlayAnimation("idle")
    
    inst:AddComponent("insulator")
    inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wakes_hood"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wakes_hood.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)
    
    inst:AddComponent("armor")
    inst.components.armor:InitCondition(TUNING.ARMORGRASS * 2, TUNING.ARMORGRASS_ABSORPTION*0.5)

    return inst
end

return  Prefab("common/inventory/wakes_hood", fn, assets, prefabs)

And here's where I've put the item's recipe description in modmain

Quote

STRINGS.NAMES.WAKES_HOOD = "Takes' Hood"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WAKES_HOOD = "I made the horn holes myself!"
STRINGS.RECIPE_DESC.WAKES_HOOD = "Soft, yet durable."

 

20190510002102_1.jpg

Edited by Scrumch

Share this post


Link to post
Share on other sites
Ultroman    340

Weird. If you have this in your modmain, the inspect description should work.

-- NOTE: Make sure this first line is above the three below.
local STRINGS = GLOBAL.STRINGS

STRINGS.NAMES.WAKES_HOOD = "Takes' Hood"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WAKES_HOOD = "I made the horn holes myself!"
STRINGS.RECIPE_DESC.WAKES_HOOD = "Soft, yet durable.

Do you also have something like this in your modmain.lua?

PrefabFiles = {
    "wakes_hood",
}

Assets = 
{
    Asset("ATLAS", "images/inventoryimages/wakes_hood.xml"),
    Asset("IMAGE", "images/inventoryimages/wakes_hood.tex"),
}

In the mods I've worked with, I did not reference the inventory images in the prefab LUA, but instead in the modmain.lua. So try removing these lines from your prefab LUA, and put them in modmain.lua like the code I posted above.

Asset("ATLAS", "images/inventoryimages/wakes_hood.xml"),
Asset("IMAGE", "images/inventoryimages/wakes_hood.tex"),

I do not know if there is a difference to doing it this way or the other. I only know how I've made it work in the past.

An item being invisible on the ground and in the hand (mouse), is usually due to an anim file reference error.

Share this post


Link to post
Share on other sites
Scrumch    7

I figured out why the hood wasn't inspect-able, I just forgot to add that component to the hood's prefab. As for the invisible item thing, what kind of anim error? I have both wakes_hood_swap and wakes_hood anim files with all three files inside. What else am I missing?

 

Share this post


Link to post
Share on other sites
Ultroman    340

From what I can understand, usually it's a problem with naming of the animations and referencing them properly. Try repacking your anim file and make sure the anim build references in the code are correct e.g. if your idle animation is called "idle_on" you need to inst.AnimState:PlayAnimation("idle_on")

Share this post


Link to post
Share on other sites
Scrumch    7
Posted (edited)

Okay, figured it out. SetBank wasn't referring to the base game item I was using the animation from. The both of you have been a big help, sorry I forgot to reply to you @Ultroman in that older post, but your advice on temperature eventually helped me out. (I went with the character's max body temperature dropping in Winter which had about the same effect).

Now I just need to figure out how to remove the sanity drain from wearing wet items...

20190510014613_1.jpg

Edited by Scrumch
  • Like 1

Share this post


Link to post
Share on other sites
Ultroman    340

You're welcome!

Removing the sanity drain from wetness is super easy in DS (compared to DST). It's just

inst.components.sanity.wetnessImmune = true

 

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