Jump to content

[Character Creation] I require the help of a more advanced brain.


Recommended Posts

Let's face it, scripting has never been my thing. Perhaps I can study the language of the computers but until then I'm no better than nothing.

While creating my character, I have come to the conclusion that the art is finally complete. Everything is in order, except one or two things that have nothing to do with that anymore.

It is his pros and cons.

I have already received help to create a script that dictates he delivers weaker attacks during dusk and night, so that is one thing off the list.

But now, I need to do a few things:

- Remove the sanity loss from eating raw meat (excluding monster meat).
- Lose sanity every time he chops a tree. It would be .75 sanity loss per chop (I'm talking about actually doing the process of chopping, not bringing it down).

- Recover 5 sanity every time he plants a sapling of any kind.

- Negate sanity gain when picking up flowers.

- Make a Garland offer no sanity gain to this character.

 

If anyone can help me with these little things, I would appreciate it a lot. Or if someone can give me a few ideas I'd love to hear them. Thanks a lot for your patience! It's the only thing I have left before finally finishing my character :3

Link to comment
Share on other sites

I haven't tested these (just writing them based on looking at the game's code), so I can't guarantee they'll work, but they probably will.
 
 
 

Remove the sanity loss from eating raw meat (excluding monster meat).

 In your character's master_postinit:

local function CheckMeat(food)    if not food:HasTag("meat") then return false end    return not food.prefab:find("monster")endlocal OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and CheckMeat(food) then        food.components.edible.sanityvalue = 0    end    return OldEat(self, food)end

 
 

Lose sanity every time he chops a tree. It would be .75 sanity loss per chop (I'm talking about actually doing the process of chopping, not bringing it down).

In the modmain:

AddPrefabPostInitAny(function(inst)    if inst:HasTag("tree") and inst.components.workable then        local oldonwork = inst.components.workable.onwork        inst.components.workable.onwork = function(inst, worker, ...)            if oldonwork then oldonwork(inst, worker, ...) end            if worker.prefab == "mycharacterprefabname" then                worker.components.sanity:DoDelta(-0.75)            end        end    endend)

 
 

Recover 5 sanity every time he plants a sapling of any kind.

Also in the modmain:

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 == "mycharacterprefabname" then                deployer.components.sanity:DoDelta(5)            end        end    endendAddPrefabPostInit("dug_sapling", SanityOnDeploy)AddPrefabPostInit("pinecone", SanityOnDeploy)-- when RoG comes around: AddPrefabPostInit("acorn", SanityOnDeploy) 

 
 

Negate sanity gain when picking up flowers.

Also in the modmain:

AddPrefabPostInit("flower", function(inst)    local oldonpickedfn = inst.components.pickable.onpickedfn    inst.components.pickable.onpickedfn = function(inst, picker)        if picker and picker.prefab == "mycharacterprefabname" then            inst:Remove()        else            oldonpickedfn(inst, picker)        end    endend) 

 
 

Make a Garland offer no sanity gain to this character.

Also modmain:

AddPrefabPostInit("flowerhat", function(inst)    local olddapperfn = inst.components.dapperness.dapperfn    inst.components.dapperness.dapperfn = function(inst, owner)        if owner.prefab == "mycharacterprefabname" then            return 0        elseif olddapperfn then            return olddapperfn(inst, owner)        else            return inst.components.dapperness.dapperness        end    endend) 

 Note that everything I wrote for the modmain should be only run on the server, so encase it in a block like this:

if GLOBAL.TheNet:GetIsServer() then    --put code hereend

Edit: Fixed single equals that should've been double equals

Edited by rezecib
Link to comment
Share on other sites

 

I haven't tested these (just writing them based on looking at the game's code), so I can't guarantee they'll work, but they probably will.

 

 

 

 In your character's master_postinit:
local function CheckMeat(food)    if not food:HasTag("meat") then return false end    return not food.prefab:find("monster")endlocal OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and CheckMeat(food) then        food.components.edible.sanityvalue = 0    end    return OldEat(self, food)end
In the modmain:
AddPrefabPostInitAny(function(inst)    if inst:HasTag("tree") and inst.components.workable then        local oldonwork = inst.components.workable.onwork        inst.components.workable.onwork = function(inst, worker, ...)            if oldonwork then oldonwork(inst, worker, ...) end            if worker.prefab == "mycharacterprefabname" then                worker.components.sanity:DoDelta(-0.75)            end        end    endend)
Also in the modmain:
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 == "mycharacterprefabname" then                deployer.components.sanity:DoDelta(5)            end        end    endendAddPrefabPostInit("dug_sapling", SanityOnDeploy)AddPrefabPostInit("pinecone", SanityOnDeploy)-- when RoG comes around: AddPrefabPostInit("acorn", SanityOnDeploy) 
Also in the modmain:
AddPrefabPostInit("flower", function(inst)    local oldonpickedfn = inst.components.pickable.onpickedfn    inst.components.pickable.onpickedfn = function(inst, picker)        if picker and picker.prefab == "mycharacterprefabname" then            inst:Remove()        else            oldonpickedfn(inst, picker)        end    endend) 
Also modmain:
AddPrefabPostInit("flowerhat", function(inst)    local olddapperfn = inst.components.dapperness.dapperfn    inst.components.dapperness.dapperfn = function(inst, owner)        if owner.prefab = "mycharacterprefabname" then            return 0        elseif olddapperfn then            return olddapperfn(inst, owner)        else            return inst.components.dapperness.dapperness        end    endend) 

 Note that everything I wrote for the modmain should be only run on the server, so encase it in a block like this:

if GLOBAL.TheNet:GetIsServer() then    --put code hereend

 

 

Wow, thanks rezecib for taking your time in doing all of this for me. I have tested this ingame, but the mod won't load, the game crashes every time I load it. Here's the log.

 

...ps/common/dont_starve/data/scripts/mainfunctions.lua:71: Error loading file prefabs/ysu...apps/common/dont_starve/data/../mods/Ysulyan mod/scripts/prefabs/ysu.lua:112: 'then' expected near '='

I tried to see if there was a mistake but there is indeed a 'then' near the '=' so, I don't know what to make out of this. What could be the problem?

Link to comment
Share on other sites

@Ysulyan, Derp! That should be a double-equals on that line. So:


        if picker and picker.prefab == "ysu" then

Edit: double-equals is used for comparing things ("is this equal to?") while single-equals is used for setting things ("assign the following value to this")

Edited by rezecib
Link to comment
Share on other sites

 

@Ysulyan, Derp! That should be a double-equals on that line. So:

        if picker and picker.prefab == "ysu" then

Hm? A double-equals? May I ask why? Unless it's too hard to explain.

Well, it seems the log does not show me that error anymore! Now another one pops. :( Sorry about this, I seem to be taking too much of your time.

...rve/data/../mods/Ysulyan mod/scripts/prefabs/ysu.lua:50: variable 'inst' is not declared

EDIT: The same happens on other things, like shown in this error:

variable 'AddPrefabPostInitAny' is not declared

It seems the game does not recognize these variables? :c

EDIT2: By the way, I think I have not made this clear, but this mod is NOT going to be compatible with DST... yet

EDIT3: *facepalm* I posted this in the wrong section of the forums.

Edited by Ysulyan
Link to comment
Share on other sites

...rve/data/../mods/Ysulyan mod/scripts/prefabs/ysu.lua:50: variable 'inst' is not declared
 Looking at your ysu,lua, you didn't follow my instructions on where to put the various things.

 

But.... I think this code should still work in DS? I'm not seeing anything that's obviously DST-specific, anyway.

Link to comment
Share on other sites

 Looking at your ysu,lua, you didn't follow my instructions on where to put the various things.

 

But.... I think this code should still work in DS? I'm not seeing anything that's obviously DST-specific, anyway.

 

Oh, I apologize so deeply... I thought all of these codes went into ysu.lua...  I must have... Derped greatly there... Well, yesterday was a long day and I was tired when I started tweaking the files... Sorry, I will put the codes that should go into the modmain.lua to the modmain.lua... I will let you know when I'm done

Edit: The tweak has been made and the mod works wonderfully! I have tested all new perks and finally decided to remove the perk that negates sanity drain when eating raw food. But for your efforts, I appreciate it so much! You have my most sincere thanks! ^^

Edited by Ysulyan
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...