Jump to content

Questions about custom character creating for DST


Recommended Posts

I've been working on a character recently, and I have her art down, but I'm not good at coding. At all. I can load her in the game, I even made her start with a customized weapon, but now I'm completely stuck. 

There are quite a few things I'm trying to code and am failing so badly I can even tell you what I have, and help would be greatly appreciated. I might have been too ambitious for my first character.

First, I can't seem to add in a custom recipe for her sword. I've tried basing it off other mods, looking online, but to no avail. 

Second, I really want her sanity to drain when killing innocent animals and spiders. I would also like spiders to not attack her without being provoked, but for pigs to automatically attack her.

What I think is the last thing I want is for her to be worse off in the heat, but better off in the cold.

I would really appreciate the help! Not being able to do this has been really frustrating me.

  • Like 1
Link to comment
Share on other sites

Hey PlayPretend,

 

I might be able to help you out with some of these things. But it's some time since I did them myself so someone might be able to do it better.

If you want to add a custom recipe adding:

AddRecipe("axting", {Ingredient("twigs", 2), Ingredient("flint", 4), Ingredient("goldnugget", 1)}, RECIPETABS.NAME_OF_TAB_YOU_WANT, GLOBAL.TECH.NONE, nil, nil, nil, nil, "CUSTOM_NAME_OF_TAG",  "images/inventoryimages/axting.xml", "axting.tex" )

Paste this into your modmain.lua

- You should change all instances of "axting" with your items file name.

- You can change the recipe by changing ingredient. Ingredient("itemname", amount). You can also add more or less items by adding more or removing Ingredient, seperated by ,

- Change RECIPETABS. could be RECIPETABS.TOOLS for example. Now the item is under tools.

- Change GLOBAL.TECH.NONE if you want it to require prototype.

- Change the CUSTOM_NAME_OF_TAG. Remove it and replace with nil if you want all to be able to craft it, otherwise pick a name and add inst.AddTag("NAME_OF_YOUR_TAG") to your charactername.lua file.

 

All this is taken from my own mod "Meet the Pyro", feel free to check it out if you wanna see exactly how I have done it.

 

This should work, I think...

 

To make spider ignore your character, simply add inst:AddTag("monster") in your character.lua file. Although this makes your character work like webber, so bunnies will attack aswell.

 

  • Like 1
Link to comment
Share on other sites

to be better in the cold, you just need to add insulation. shouldn't be hard to find a mod with that line of code, it would be in the character's prefab. 

I have lines of code in my character mod, Wollawossiky, that drains sanity when either a entity with the tag "smallcreature" or "largecreature" is killed by the character. If you take those lines and change "smallcreature" and "largecreature" to "prey" and "spider", I think that would work!

For the spider neutral thing, it might be a bit more difficult. You might be able to have a task that checks if there is a spider in range of you, and then adds the tag of "spider" or whatever that makes you like Webber, so they won't attack you. And then when you get out of range, it removes the tag. Wollawossiky also has some code that is similar to this, that he is able to get closer to entities before they react to him. With some effort, you could probably change that code to make spiders docile to you.

Link to comment
Share on other sites

Thank you both a lot! I was able to do quite a few of the things I was having issues with. I'm not sure if the cold and heat work because I haven't tested it, but I'll get around to it. The monster tag worked, so thanks for that too. Also, I'll be sure to check out your thing for the sanity drain. I have it right now so whenever she hits anything it drains, but I'd rather have it set to on death instead of on attack.

I am still having troubles with the sword, though. It seems like only the person who created the server can see/interact with the weapon. The only time others can see it is if the person who started the server is holding it. If they are given it or if it is dropped they can't see it or interact with it at all. They also can't use the debug to spawn it in either. Even when playing as the character when I wasn't the server creator I crafted it and then it looked like I was holding it but as soon as I picked up another equipable item it disappeared, but I somehow dropped multiple on death even though it didn't appear in my inventory.

Link to comment
Share on other sites

17 hours ago, Nightfall said:

I had similiar issues. It may be because you have not added inst.entity:AddNetwork() to your weapon.lua file.

I added it and when my friend tried to join the game also playing as my custom character it crashed.

Link to comment
Share on other sites

Spoiler

local assets=

    Asset("ANIM", "anim/lefu.zip"),
    Asset("ANIM", "anim/swap_lefu.zip"), 

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

local prefabs = 
{
}

local function fn(colour)

    local function OnEquip(inst, owner) 
        owner.AnimState:OverrideSymbol("swap_object", "swap_lefu", "lefu")
        owner.AnimState:Show("ARM_carry") 
        owner.AnimState:Hide("ARM_normal") 
    end

    local function OnUnequip(inst, owner) 
        owner.AnimState:Hide("ARM_carry") 
        owner.AnimState:Show("ARM_normal") 
    end

    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("lefu")
    anim:SetBuild("lefu")
    anim:PlayAnimation("idle")
    
    inst:AddTag("pointy")
    inst:AddTag("sharp")

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.NIGHTSWORD_DAMAGE/1.50)
    inst.entity:AddNetwork() 
    -------

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.NIGHTSWORD_USES*1.50)
    inst.components.finiteuses:SetUses(TUNING.NIGHTSWORD_USES*1.50)
    inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "lefu"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/lefu.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )

    return inst
end

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

 

Lefu is the name of the sword. I took out the bit of code you gave me because I had to test out something else without it crashing.

Link to comment
Share on other sites

23 minutes ago, PlayPretend said:

local function fn(colour)

change to local function fn()

 

25 minutes ago, PlayPretend said:

    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

change to 

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
26 minutes ago, PlayPretend said:

anim:SetBank("lefu")
    anim:SetBuild("lefu")
    anim:PlayAnimation("idle")

change to 

inst.AnimState:SetBank("lefu")
inst.AnimState:SetBuild("swap_lefu")
inst.AnimState:PlayAnimation("idle")

 

  • Like 1
Link to comment
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
 Share

×
  • Create New...