Jump to content

Recommended Posts

I'm trying to create a new character for Don't Starve Together; it's the first time i try to mod the game but i know a bit of LUA.

The problem is that i wanted to create a character with innate electric damage, but i can't find any tutorial or pieces of code even from Volt Goat so i wanted to ask for help with the creation of the character.

I had other kinds of Pros and Cons to add but i don't know how to write the specific code

 

Add this code to your character, under the "master_postinit" function:

inst:AddComponent("electricattacks")
inst.components.electricattacks:AddSource(inst)

The source could be named whatever you want, but keep it "inst" so it is less likely that other source takes its place.

If you ever want to remove the electric attack, you can make a function that includes:

inst.components.electricattacks:RemoveSource(inst)

Remember, if you change the source name, you should write it with quotation marks. And when removing an electric attack source make sure the text inside RemoveSource matches the text inside AddSource.

Hope I helped!

Edited by HarryPPP
  • Like 2
On 3/14/2021 at 9:04 PM, HarryPPP said:

inst:AddComponent("electricattacks") inst.components.electricattacks:AddSource(inst)

Hello, I was looking for a code to make my character do electrical damage, and yours worked perfectly, but I would like to know if you can help me to make the sparks of the morning star and the voat goat chaud froid come out when hitting , and if you could help me know where to put them, I add my code:

 

local MakePlayerCharacter = require "prefabs/player_common"

local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}

-- Your character's stats
TUNING.JINRO_HEALTH = 100
TUNING.JINRO_HUNGER = 125
TUNING.JINRO_SANITY = 200

-- Custom starting inventory
TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.JINRO = {
    "blowdart_sleep",
}

local start_inv = {}
for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do
    start_inv[string.lower(k)] = v.JINRO
end
local prefabs = FlattenTree(start_inv, true)

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when not a ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "jinro_speed_mod", 1.35)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "jinro_speed_mod")
end


-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end


-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst)
inst:AddTag("insomniac")
inst:AddTag("fastbuilder")
inst:AddTag("masterchef")
inst:AddTag("houndfriend")
inst:AddTag("monster")
inst:AddTag("quagmire_fasthands")

inst:RemoveTag("scarytoprey")


    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "jinro.tex" )
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)

inst:AddComponent("electricattacks")
inst.components.electricattacks:AddSource(inst)

    -- Set starting inventory
    inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default
    
    -- choose which sounds this character will play
    inst.soundsname = "woodie"
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
inst:ListenForEvent("killed",function(inst,data)
    inst.components.sanity:DoDelta(5) --Restores 5 sanity on kill
end)
    

    -- Stats    
    inst.components.health:SetMaxHealth(TUNING.JINRO_HEALTH)
    inst.components.hunger:SetMax(TUNING.JINRO_HUNGER)
    inst.components.sanity:SetMax(TUNING.JINRO_SANITY)
    
inst.components.foodaffinity:AddPrefabAffinity("californiaroll", TUNING.AFFINITY_15_CALORIES_HUGE )

inst.components.sanity.neg_aura_mult = 0.25

inst.components.sanity.night_drain_mult = 0


    inst.components.temperature.inherentinsulation = 60    
    inst.components.temperature.inherentsummerinsulation = 60

inst.components.health:StartRegen(0.1, 0.5)

    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1.50
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 0.80 * TUNING.WILSON_HUNGER_RATE
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    
end

return MakePlayerCharacter("jinro", prefabs, assets, common_postinit, master_postinit, prefabs)
 

Quote

Hello, I was looking for a code to make my character do electrical damage, and yours worked perfectly, but I would like to know if you can help me to make the sparks of the morning star and the voat goat chaud froid come out when hitting , and if you could help me know where to put them, I add my code:

Sorry for the somewhat late response, @Kirigio.

All you need to do is put the following under master_postinit:

    if inst._onattackother == nil then
        inst._onattackother = function(attacker, data)
            if data.weapon ~= nil then
                if data.projectile == nil then
                    --in combat, this is when we're just launching a projectile, so don't do FX yet
                    if data.weapon.components.projectile ~= nil then
                        return
                    elseif data.weapon.components.complexprojectile ~= nil then
                        return
                    elseif data.weapon.components.weapon:CanRangedAttack() then
                        return
                    end
                end
                if data.weapon.components.weapon ~= nil and data.weapon.components.weapon.stimuli == "electric" then
                    --weapon already has electric stimuli, so probably does its own FX
                    return
                end
            end
            if data.target ~= nil and data.target:IsValid() and attacker:IsValid() then
                SpawnPrefab("electrichitsparks"):AlignToTarget(data.target, data.projectile ~= nil and data.projectile:IsValid() and data.projectile or attacker, true)
            end
        end
        inst:ListenForEvent("onattackother", inst._onattackother, inst)
    end

This will create the same effect as Warly's Volt Goat Chaud-Froid.

Tell me if you find any problem!

  • Like 2

@HarryPP 

It helped me a lot, thank you very much!!!, if it is not too much trouble taking advantage of your kindness, won't you have a backpack mod that contains the exported folder to know how to create my own backpack mod?

I would appreciate it a lot since I've been looking for days and I have no idea how to create it

On 3/15/2021 at 3:04 AM, HarryPPP said:

Add this code to your character, under the "master_postinit" function:


inst:AddComponent("electricattacks")
inst.components.electricattacks:AddSource(inst)

The source could be named whatever you want, but keep it "inst" so it is less likely that other source takes its place.

If you ever want to remove the electric attack, you can make a function that includes:


inst.components.electricattacks:RemoveSource(inst)

Remember, if you change the source name, you should write it with quotation marks. And when removing an electric attack source make sure the text inside RemoveSource matches the text inside AddSource.

Hope I helped!

Man sorry for the late response but i F*CKING LOVE YOU, i wish you the best for this new year, you don't know how happy i am that you gave me all this pieces of code. I forgot to check this website so i saw your comment now, but you really did opened my eyes since i didn't know that the electric damage is separated from the actual visible effect, thanks again and i'll never forget you (sorry for being this emotinal but i've been struggling for months :')

  • Like 1

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