Jump to content

[CODE COLLECTION] Some special function (Character's Perks, item's perks...) and the code lines for it ! Update 17/02/2017


SrNomercy

Recommended Posts

Hi, first thing i want to say is all the code down here is mostly from this forum's thread, from mod that posted on this forum and on steam workshop (DS+DST). I'm just the collector, So all Credit go to the original author of the code :

Mobbstar

Finerlobster

rezecib

CarlZalph

NyctoDarkMatter

Squids

DarkXero

Mr. Tiddles

Sukoushi

 

When i'm customize my favorite character (actually that not my own character, i download it from steam and love it so much that i decide to customize it to fit my taste), try adding some new perks i already got in mind, i had a realy hard time finding those codes for all the perks i want on this forum, so i creates this thread to make it easy to find for those who want to have the same perk on their character.

One more thing: i don't know anything about coding so i cant give any more help than this and cant explain why or whatever you wonder cause i don't know too, sorry :D !!! One thing i'm sure of is these codes work for me, hope it work for you too. Have Fun !!!

1/ DEALS POISON DAMAGE

Spoiler

local function DoPoisonDamage(inst)
    -- Poison DPS: -10
    inst.components.health:DoDelta(-10, true, "poison") -- customize damage amount here
    -- Blip Green for 1/9 of a second upon poison
    -- The first three numbers are standing for "RGB" -> Red Green Blue. If the value is 1, it is a RGB value of 255.
    inst.AnimState:SetMultColour(0,1,0,1)
    inst:DoTaskInTime(.9, function(inst) inst.AnimState:SetMultColour(1,1,1,1) end)
end
-- OnAttackOther, deal poison damage every .33 seconds. Remember to call this function in local fn = function(inst)
local function onattackother(inst, data)
if data.target and data.target.components.health and not data.target.components.health:IsDead() then

-- No target players.
if not data.target:HasTag("player") then

-- Can't already be poisoned.
if data.target.poisontask == nil then

-- If conditions met; deal DoPoisonDamage value 3 times per second.
data.target.poisontask = data.target:DoPeriodicTask(1/3, DoPoisonDamage)

-- End poison damage @ 30 seconds. Deals damage total = (30 seconds * Poison DPS * 3 times per second).
data.target.poisonwearofftask = data.target:DoTaskInTime(30, function(inst) inst.poisontask:Cancel() inst.poisontask = nil end)
            end
        end
    end
end

Put these line above the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod

Spoiler

-- Deals poison damage function being called
    inst:ListenForEvent("onattackother", onattackother)
-- add Poison Bubbles effect on poisoned target.
    inst:AddTag("poisonous")
    inst.components.combat.poisonous = true

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. Save & DONE !!!

2/ POOP MANURE WHEN EAT VEGGIE FOOD (like pigman does)

Spoiler

-- Poop **** when eat veggies food function. Remember to call this function in local fn = function(inst)

local function OnEat(inst, food)
    if food.components.edible and food.components.edible.foodtype == "VEGGIE" then
        local poo = SpawnPrefab("poop")
        poo.Transform:SetPosition(inst.Transform:GetWorldPosition())        
    end
    
end

Put these line above the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod

Spoiler

-- Poop **** when eat veggies food
    inst:AddComponent("eater")
    inst.components.eater:SetOnEatFn(OnEat)   

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. Save & DONE !!!

3/ QUICK PICKING

Spoiler

-- Quick pickin'!
    local handle = inst.sg.sg.actionhandlers[ACTIONS.HARVEST]
handle.deststate = function(inst) return "doshortaction" end
    local handle = inst.sg.sg.actionhandlers[ACTIONS.PICK]
handle.deststate = function(inst) return "doshortaction" end

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. Save & DONE !!!

4/ GAIN SANITY FROM PICKING THINGS

Spoiler

-- Gain Sanity from picking   
        inst:ListenForEvent(
            "picksomething",
            function(inst, data)
                if(data and data.object and data.object.prefab=="sapling") -- thing you want to gain sanity from picking it
                then
                    if(inst and inst.components and inst.components.sanity)
                    then
                        inst.components.sanity:DoDelta(10) -- customize the amount of sanity gain here
                    end
                end
            end
        )

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. want to add more things just copy the code and replace the prefabs name of the thing you want to add. Save & DONE !!!

5/ GAIN SANITY FROM CATCHING BUG WITH BUGNET

Spoiler

-- Gain Sanity from catching bugs with bugnet
        inst:ListenForEvent(
            "finishedwork",
            function(inst, data)
                if(data and data.target and data.target.prefab=="butterfly") -- Bug's prefabs name here
                then
                    if(data.action and data.action.id=="NET")
                    then
                        if(inst and inst.components and inst.components.sanity)
                        then
                            inst.components.sanity:DoDelta(25) -- amount of sanity gain here
                        end
                    end
                end
            end
        )

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. want to add more bugs just copy the code and replace the prefabs name of the bug you want to add. Save & DONE !!!

6/ GAIN SANITY FROM PICK THINGS ON THE GROUND

Spoiler

-- Gain sanity on pickup something ON THE GROUND
    inst:ListenForEvent("onpickup", function(inst, data)        
        if data.item.prefab == "poop" -- Thing's prefab name here
        then            
            inst.components.sanity:DoDelta(5)   -- The amount of sanity gain here    
        end    
    end
    )

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. want to add more things just copy the code and replace the prefabs name of the thing you want to add. Save & DONE !!!

7/ GAIN HEALTH, SANITY, HUNGER ON KILLING

Spoiler

-- Gain health, sanity, hunger everytime you kill, destroy a world entity (exclude those "and not" tag), must last hit target to execute it
    inst:ListenForEvent("entity_death", function(wrld, data)
        if data.inst
        and not data.inst:HasTag("prey") --"prey" will rule out bunnies, birds, etc
        and not data.inst:HasTag("veggie") --"veggie" rules out eyeplants from lureplants
        and not data.inst:HasTag("structure") --"structure" rules out structure I think :D
        and not data.inst:HasTag("butterfly") --rules out butterflies
        then
            if data.cause == inst.prefab
            then        
                local delta = 25 -- the amount of sanity gain here
            inst.components.health:DoDelta(delta)        
            inst.components.sanity:DoDelta(delta)        
            inst.components.hunger:DoDelta(delta)    
            end
        end
    end, GetWorld())

Put these line under the line "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. Save & DONE !!!

8/ GAIN SANITY FROM PLANTING STUFF

(Best for last, this one perk nearly got me, i almost give up on this perk)

Spoiler

-- Gain sanity from planting stuff.
local function SanityOnDeploy(inst)
    if inst.components.deployable then
        local oldondeploy = inst.components.deployable.ondeploy
        inst.components.deployable.ondeploy = function(inst, pt, deployer)
        if oldondeploy then oldondeploy(inst, pt, deployer) end
            if deployer.prefab == "abc" then -- Your character's name here
                deployer.components.sanity:DoDelta(10)
            end
        end
    end
end
AddPrefabPostInit("pinecone", SanityOnDeploy) -- Thing you gain sanity from planting it

Put these line in your modmain.lua file of your character, replace the abc in the code with your character's name. want to add more things just copy the last line (only) and replace the prefabs name of the thing you want to add. Save & DONE!!!

Voila! All done!!!

Hope this help !!!

Sorry for any mistakes. English is not my native language.

Link to comment
Share on other sites

New Tut comming!!!

Today i'll explain to you step-by-step how i add a special item from other mod to your character.

Here is the scenario – let's say you found an item mod on steam, this mod brought you so many new item, but in the end you only need one, you dont want to enable too many mod or just want your character to have a special item....v.v..

I'm not sure if this work 100% time but it worked for the one time i need it to, just hope this work for you too.

P/s: dont try to add a too complicated item (item with many function that need the original mod to work), simple is love, simple is life !!!

Add Item from another mod to your character

Credit to author of the original mod:

Author: Sage - Whandler, the Digital Artist (RoG) https://steamcommunity.com/sharedfiles/filedetails/?id=436326795&searchtext=Whandler

Author Mobbstar & <default>  - <default>'s item pack [DS/RoG/SW] https://steamcommunity.com/sharedfiles/filedetails/?id=575092269&searchtext=16+item

1/ Preparation:

Notepad++

mod:

Whandler, the Digital Artist (RoG)

<default>'s item pack [DS/RoG/SW]

and your main character mod of course.

2/ Explanation:

ok! why do we need a character mod that not your main ?! because you need to know what a chacracter that have a special item look like.

Whandler here is a simple character and have a special hat. <<< I likes simple things, life is too complicated

+ Unzip Whandler mod, go to Whandler\scripts\prefabs, you will see 2 files:

whandler.lua <<< this is character lua file

whandlerhat.lua <<< this is the speacial hat lua file, hah found you :D !!!

+ Back to the Whandler folder search for the word " whandlerhat", result in 4 files:

whandlerhat.lua

whandlerhat.tex

whandlerhat.xml

whandlerhat..zip

This mean that special hat need to have all this 4 kind of files in the character mod to work. <<< get the idea "the 4 kind of files & their located folder" <<< this is important

+ Unzip <default>'s item pack mod, this mod have an item that i love so much, it's the Staff of Growth

so go to the ...\scripts\prefabs try to find something related to grow or staff and here it is: growthstaff.lua so growthstaff is the prebab name of your item <<< this is important

+ Back to the main folder search for the word " growthstaff", result in 5 files: (it's ok, don't panic)

    growthstaff.lua
    growthstaff.tex
    growthstaff.xml
    growthstaff.zip
    swap_growthstaff.zip << This one may be expendable but copy it just to make sure.

Step 1: Copy-paste

-- copy all this file from the mod to the SAME location list below in your character' folder
    -- Copy growthstaff.zip and swap_growthstaff.zip to character's anim folder
    -- Create new folder "inventoryimages" in character's folder\images <<< if your character dont' have this folder already just like my character.
        -- Copy growthstaff.tex and growthstaff.xml to inventoryimages folder
    -- Copy growthstaff.lua to character' folder\scripts\prefabs folder

Step 2: Coding <<< love to use this word although i dont know anything about coding :D and REMEMBER to REPLACE every growthstaff word that showed up with your item prefab name

-- modinfo.lua: <<< nothing to do here, compare with Whandler's modinfo.lua which is not mentioned about whandlerhat

-- modmain.lua: <<< compare with Whandler's modmain.lua there something you need to do here

   added "growthstaff" in PrefabFiles = {...} -- Replace with the prebab name of your desire item
   added 2 line under "-- Custom speech strings" line
            GLOBAL.STRINGS.NAMES.GROWTHSTAFF = "character''s Staff" << item's name display in game when you hover your mouse on them
            GLOBAL.STRINGS.CHARACTERS.WALTER.DESCRIBE.GROWTHSTAFF = "It's my magical staff!" << what your character say when exemize the item

Save & done.

-- "your Character".lua: compare with Whandler.lua file
        -- added this line in local assets = {...}
            Asset( "ANIM", "anim/growthstaff.zip"), --Replace growthstaff with your item prefab name
        -- added "growthstaff" in local prefabs = {...}, local start_inv = {...} --Replace growthstaff with your item prefab name

Important: remember to check the last line of "your character".lua file, must be something like below:

Spoiler

return MakePlayerCharacter("your character'name", prefabs, assets, fn, start_inv)

If the "start_inv" is not called in that line then add it or your character will not have start item.

Save & DONE <<< This time you realy DONE, cause if you not i don't know what to do next.

Now get your character to the Don't Starve world and see if they have that special item like i have my staff, and remember to disable the item mod.

P/s: next time i will explain how i customize the staff to fit my taste, so may be you can base on what i done to make your special item to fit yours.

P/s': I'm just a copy-paster , so i cant give any more help than this and cant explain why or whatever you wonder cause i don't know too, sorry :D!!!
I appreciate you taking the time to read my topic.
Sorry for any mistakes. English is not my native language.

 

 

 

Link to comment
Share on other sites

ok ! From here i assumed you already have a special handheld item (like my Staff of Growth - SoG ), and you want to make it more special :D, and i'll call your special item with a prefab name like abc.

Now i'm gonna describe how i'm customize my staff i got from up there (SoG).

1/ MAKE YOUR SPECIAL HANDHELD ITEM DEAL SOME DAMAGE (My original SoG didn't)

Spoiler

inst:AddComponent("weapon")
        inst.components.weapon:SetDamage(69) -- damage amount, 69 is love, 69 is life

Put these line under the line "local function init()" (my staff had 2 local function from the original: local function growstaff(staff) & local function init(), i just picked one and add these line) in your abc.lua file in prefabs folder of your character mod. You can customize the damage amount. Save & DONE !!!

2/ DEAL POISON DAMAGE (i loves poison)

Ok! why poison again, the poison function up there is not the original game's poison mechanic (like poison spear in SW), it just make your character deal damage over time regardless whatever your character hold in hand (mean that when you whacked a Moleworm with a hammer it didn't die at first, but the damage over time will kill it lately, that's inconvenience). So now, here come the real poison machenic (like poison spear in SW).

2a/ Deal poison damage to a single target (like poison spear in SW):

Spoiler

-- Deals poison damage on single target:
local function poisonattack(inst, attacker, target) -- Remember to call this in the local function
    if target.components.poisonable then
        target.components.poisonable:Poison()
    end
    if target.components.combat then
        target.components.combat:SuggestTarget(attacker)
    end
    target:PushEvent("attacked", {attacker = attacker, damage = 0})
end

Put these line above the line "local fn = function" in your "special handheld item".lua file in prefabs folder of your character mod

Spoiler

-- Deals poison damage on single target
            inst.components.weapon:SetOnAttack(poisonattack) -- Poison single target function being call

Put these line under the line "local function" in your abc.lua file in prefabs folder of your character mod. Save & DONE !!!

2b/ Deal poison damage to a multiple targets (AoE):

Credit goes to author Mr. Tiddles for the origianal code.

Spoiler

-- Deals AOE-poison damage:
local function Gasem(v)

    if v     and v.components.health
            and not v.components.health:IsDead()
            and v ~= GetPlayer()
            and v.components.combat
            and v.components.poisonable
            then
                v.components.combat:GetAttacked(GetPlayer(), 2.4)
                v.components.poisonable:Poison()
    end
end

-- Asplode upon the Stabbins

local function Mark(inst, attacker, target)

    local pt = attacker:GetPosition()
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 3)
    local ents2 = TheSim:FindEntities(pt.x, pt.y, pt.z, 6)
    local ents3 = TheSim:FindEntities(pt.x, pt.y, pt.z, 8)
    local ents4 = TheSim:FindEntities(pt.x, pt.y, pt.z, 9)
    for k,v in pairs(ents) do
            Gasem(v)
    end
attacker:DoTaskInTime(0.1, function()
    for k,v in pairs(ents2) do
                        Gasem(v)
    end
    end)
attacker:DoTaskInTime(0.2, function()
    for k,v in pairs(ents3) do
                        Gasem(v)
    end
    end)
attacker:DoTaskInTime(0.3, function()
    for k,v in pairs(ents4) do
                        Gasem(v)
    end
    end)
    inst.SoundEmitter:PlaySound("dontstarve_DLC002/creatures/Stinkray/attack")
    local cloud = SpawnPrefab("firering_fx").Transform:SetPosition(inst:GetPosition():Get())
    if cloud then
    cloud.AnimState:SetMultColour(0.4,0.8,0.9,1)
    end
end

Put these line above the line "local fn = function" in your "special handheld item".lua file in prefabs folder of your character mod

Spoiler

-- AOE Poison damage:
            inst.components.weapon:SetOnAttack(Mark)

Put these line under the line "local function" in your abc.lua file in prefabs folder of your character mod. Save & DONE !!!

Ok! you may think poison damage is a crap, wait for it :D

2c/ Tuning poison damage: (hah! i told you i loves poison)

Spoiler

-- Manipulate poison damage over time: here is 20 damage per second for 120s
local TUNING = GLOBAL.TUNING
TUNING.POISON_DURATION = 120 -- the time in seconds that poison normally endures
TUNING.POISON_DAMAGE_PER_INTERVAL = 20 -- the amount of health damage poison causes per interval
TUNING.POISON_INTERVAL = 1 -- how frequently damage is applied

Put these line in your modmain.lua file of your character mod, you can customize the amount. Save & DONE !!!

3/ MAKE YOUR ABC BECOME THE LAZY EXPLORER STAFF

Spoiler

inst:AddComponent("blinkstaff") -- Teleboof

Put these line under the line "local function" in your abc.lua file in prefabs folder of your character mod. Save & DONE !!!

4/ MOVEMENT SPEED (LIKE WALKING CANE)

Spoiler

    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT*2 -- Movement speed, this is 2 time the walking cane value

Put these line in your modmain.lua file of your character mod, you can customize the amount. Save & DONE !!!

Ok!, that's pretty much it (for me), hope this help. and of course you can add more function but too much is not fun any more :D (i one used a mod call "god's cane" that make cane can do everythings (axe, pickaxe, bugnet, shovel, light, high damage, hight speed, teleboof...) that make the game so easy, no point crafting stuff)

P/s: I'm just a copy-paster , so i cant give any more help than this and cant explain why or whatever you wonder cause i don't know too, sorry :D!!! One thing i'm sure of is these codes work for me, hope it work for you too. Have Fun !!!
I appreciate you taking the time to read my topic.
Sorry for any mistakes. English is not my native language.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...