Jump to content

Recommended Posts

Need some help on coding for a vegetarian char's perk:

Gain sanity from:

+ Plant seeds and crop seeds into "slow_farmplot" & "fast_farmplot"

+ Havesting crops from "slow_farmplot" & "fast_farmplot"

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

Edited by SrNomercy

Ok ! Here somthing i luckily find out on the "Gain sanity from PICKING things" perk:

Spoiler

inst:ListenForEvent(
            "picksomething",
            function(inst, data)
                if(data and data.object and data.object.prefab=="sapling")
                then
                    if(inst and inst.components and inst.components.sanity)
                    then
                        inst.components.sanity:DoDelta(10)
                    end
                end
            end
        )

Put these line under the "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. you can customize 2 things:

+ The thing you want to gain sanity from pick it, here is sapling, there are 9 things in total you can change: berrybush, berrybush2, grass, sapling, reeds, cactus, red_mushroom, blue_mushroom, green_mushroom (these're prefab's name).

+ The amount of sanity gain by change the number in DoDelta(10), here is 10 sanity points per sapling picked.

P/s: if you want to gain sanity from pick all 9 things just copy the code 9 times and replace prefab's name in the prefab=="..".

And on the "Gain sanity from catching things with BUGNET" perk:

Spoiler

inst:ListenForEvent(
            "finishedwork",
            function(inst, data)
                if(data and data.target and data.target.prefab=="butterfly")
                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)
                        end
                    end
                end
            end
        )

Put these line under the "local fn = function(inst)" in your "character's name".lua file in prefabs folder of your character mod. you can customize 2 things:

+ The thing you want to gain sanity from catching it, here is butterfly, there are 5 bugs in total you can change: butterfly, fireflies, bee,killerbee, mosquito (these're prefab's name).

+ The amount of sanity gain by change the number in DoDelta(25), here is 25 sanity points per butterfly caught.

P/s: if you want to gain sanity from pick all 5 things just copy the code 5 times and replace prefab's name in the prefab=="..".

That's all. Hope this help !!!

P/s: STILL NEED HELP on gain sanity from:

+ Planting things like: pinecone, acorn, butterfly, dug_grass, dug_sapling, dug_berrybush, dug_berrybush2, lureplantbulb

+ Plant and Havest crop from "slow_farmplot" and "fast_farmplot"

Credit goes to every members in this thread below which is where i got those code from, many thanks !!!

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

Edited by SrNomercy

Ok! Here something funny, when i read this thread "Introduction to some Components" (link below), in the eater section, i got an idea why do i need pig to poop manure, we - human do it nearly every day, so thing is i want my char can do so, which mean the char will poop manure when eat veggie type food. so i follow the instruction from the thread, and take a look into the pigman.lua file pick some lines out for the perk (which is poop manure when eat veggie),

and here it is:

Step 1: 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

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

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

Spoiler

inst:AddComponent("eater")

inst.components.eater:SetOnEatFn(OnEat)

DONE !!!

and now your char will poop manure when eat veggie food :D!!!

Have fun !!!

all creadit go to Mobbstar the OP of the thread.

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

Edited by SrNomercy

OK! when i research on this forum i found the code for the perk: "gain health, sanity, hungger upon killing stuff"

I combine 2 code given by 2 member, credit goes to them, of course.

Finerlobster

This code is give u the benefit (here is 10 point add to health/Sanity/Hunger) from destroying a world entity, including structures.

Spoiler

inst:ListenForEvent("entity_death", function(wrld, data)     
    if data.cause == inst.prefab
    then        
        local delta = 10 -- amount        
        inst.components.health:DoDelta(delta)        
        inst.components.sanity:DoDelta(delta)        
        inst.components.hunger:DoDelta(delta)    
    end
    end, GetWorld())

rezecib

a part of the code set some rules on choosing which targets that you gonna get benefit from killing it. and of course i picked them out.

Spoiler

local function onentitydeath(world, data)
	if data.inst and not data.inst:HasTag("prey") and not data.inst:HasTag("veggie")
	and not data.inst:HasTag("structure") and not data.inst:HasTag("butterfly") then
		--"prey" will rule out bunnies, birds, etc; "veggie" rules out eyeplants from lureplants, "structure" rules out houndius shootius I think
		if data.afflicter and data.afflicter.components.sanity and data.cause and data.cause.prefab == "thisweaponsprefabname" then
			--afflicter should be the player that killed it; cause should be either the player (if punching) or the weapon
			data.afflicter.components.sanity:DoDelta(2) --you might want to scale this value by the mob? like maybe health
			--to scale by health instead, for example:
			data.afflicter.components.sanity:DoDelta(math.clamp(data.inst.components.health.maxhealth/100, 2, 4))
			--arguments for math.clamp are (suggested_amount, min_amount, max_amount)
		end
	end
end

local function onequip(inst, owner)
	--the code you already have
	inst:ListenForEvent("entity_death", onentitydeath, TheWorld)
end

local function onunequip(inst, owner)
	--the code you already have
	inst:RemoveEventCallback("entity_death", onentitydeath, TheWorld)
end

Here is the result:

Spoiler

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

This code give your character a perk: "Gain health, sanity, hunger everytime you kill, destroy a world entity (exclude those "and not" tag), must last hit target to execute it.

You can customize the amount gain (here is 25 points) by changing the number after local delta = amount

P/s: STILL NEED HELP on gain sanity from:

+ Planting things like: pinecone, acorn, butterfly, dug_grass, dug_sapling, dug_berrybush, dug_berrybush2, lureplantbulb

+ Plant and Havest crop from "slow_farmplot" and "fast_farmplot"

btw I don't know anything about coding, just copy and paste. So all things i post here is supposed to help those like me to customize there favorite char, not to show off or something, just in case if anyone ever wonder what i am doing here :D.

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

 

Edited by SrNomercy

Gain sanity from planting stuff!!! Man this one perk nearly got me, i almost give up on this one. i told myself one last try and that's it.

I go to Steam's Workshop for Don't Starve and search for "PLANT" which no hope for finding anything, just 1 last try, 77 mods came up, i glanced through them, open every character mod that came up in new window, check for there description. And then i found this line: "he will recover sanity every time he plants any seed related to trees". can't say how happy i am, and i also wonder why i miss this mod on the first place.

Ok! Time up!!! Here come the mod i got the code from:

Oh man ! the author is Mobbstar, thank you so much, your legacy here realy help me alot.

The mod's name is: Ysulyan, the Nature Dragon

https://steamcommunity.com/sharedfiles/filedetails/?id=743600424&searchtext=plant

So credit go to Mobbstar, AGAIN!!! THANK YOU SO MUCH.

OK, time for the code:

This code below give you the perk: "gain sanity for planting thingsf"

Spoiler

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 == "Your Character's name here" then
                deployer.components.sanity:DoDelta(10)
            end
        end
    end
end
AddPrefabPostInit("pinecone", SanityOnDeploy)
AddPrefabPostInit("acorn", SanityOnDeploy)
AddPrefabPostInit("dug_grass", SanityOnDeploy)
AddPrefabPostInit("dug_sapling", SanityOnDeploy)
AddPrefabPostInit("dug_berrybush", SanityOnDeploy)
AddPrefabPostInit("dug_berrybush2", SanityOnDeploy)
AddPrefabPostInit("lureplantbulb", SanityOnDeploy)
AddPrefabPostInit("butterfly", SanityOnDeploy)

Put these line in your modmain.lua file of your character, replace the - Your Character's name here - in the code with your character's name.

If you want to plant more stuff, copy the last line and replace the prefabs name with the prefab name of the stuff you want to gain sanity from planting it. You can customize the amount gain (here is 10 points) by changing the number DoDelta(amount).

Ok! pretty much done, only one Perk left: Gain sanity from Planting and Havesting crops from "slow_farmplot" and "fast_farmplot" STILL NEED HELP on this one, i'm pretty sure didn't see any mod cover this perk so may be that's all, time to play some don't starve.

P/s: Thank all the author for your codes that made my character the man he is today.

One again all Credit go to :

Mobbstar

Finerlobster

rezecib

CarlZalph

Thank you so much !!!

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

Edited by SrNomercy

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