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.

FancyBonnie

Beginner starting a character mod, any tips/help?

Recommended Posts

FancyBonnie    1

Hey, I'm currently making a character mod for Don't starve together using the Extended sample character mod from Dragon Wolf, I got everything set up to work, just need to do the statistical stuff and art. (Friend is doing the art bless her soul.)

So the character is based off the rabbits in game and I'm trying to make him sanity based kinda like how you see beardlings at low sanity
Things I'm attempting to do, but unsure how to really get to work.

>Turn into a beardling at lower sanity |Maybe another time|
>On hit, get a speed boost and lose 5 sanity. |COMPLETE!|
>Health drain on super low sanity |COMPLETE!|
>Sanity aura while a rabbit, insanity aura while a beardling |Maybe another time|
>Gains half the amount of hunger eating meat |COMPLETE!|
>Can do dig actions without a shovel (Removing stumps, digging graves, ETC)  |Currently working on!|

Everything else like movement speed and heat/cold resistance I kinda know myself. Help is appreciated!  

      

Share this post


Link to post
Share on other sites
Yakuzashi    49

Hi.
This: >Turn into a beardling at lower sanity (Might not even add though)
and this: >Sanity aura while a rabbit, insanity aura while a beardling
can be solved via Kzisor's tutorial

 

Share this post


Link to post
Share on other sites
thomas4846    603

    inst:ListenForEvent("healthdelta", sanitycheck)
    
    local function sanity check (inst)
    if inst.components.sanity.currentsanity <= 30 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
    end

 

this is trashy but should work

Share this post


Link to post
Share on other sites
FancyBonnie    1
3 hours ago, thomas4845 said:

    inst:ListenForEvent("healthdelta", sanitycheck)
    
    local function sanity check (inst)
    if inst.components.sanity.currentsanity <= 30 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
    end

 

this is trashy but should work

This code makes the game get a mod error, maybe something isn't written right? I editted the 30 to 18 it didn't work, and I kept it to 30 and it still didn't work.

Share this post


Link to post
Share on other sites
FancyBonnie    1
7 minutes ago, thomas4845 said:

i think it should be sanitydelta instead of healthdata

Still crashes the game. I'll show you what the code looks like on my end
end
  inst:ListenForEvent("sanitydelta", sanitycheck)
    
    local function sanity check (inst)
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
    end

That look fine?

Share this post


Link to post
Share on other sites
thomas4846    603

i think it's because i tried to mess with the health component to create a negative regen

you might want to add a timer to it  

such as:

inst.components.health:StartRegen(-1,10)

Share this post


Link to post
Share on other sites
FancyBonnie    1
3 minutes ago, thomas4845 said:

i think it's because i tried to mess with the health component to create a negative regen

you might want to add a timer to it  

such as:

inst.components.health:StartRegen(-1,10)

It still doesn't work. saying something about a inst not being detected when I remove the space from the sanitycheck portion, assuming I needed to remove that space because it shows up green when removed. Even when It's spaced though it still doesn't work.

Share this post


Link to post
Share on other sites
FancyBonnie    1
9 minutes ago, thomas4845 said:

i'm not sure then, i'm still green myself when it comes to coding some of the other more experienced coders can help

I'll try moving it around, maybe I put it in the wrong spot.

Share this post


Link to post
Share on other sites
Ultroman    603

Try posting the exact code you have right now. Perhaps just attach the Lua file to a reply here so we can check it out.

Share this post


Link to post
Share on other sites
bizziboi    1,929

Your local function sanitycheck misses a closing 'end', only the one for the 'if' is there.

(If you fix indentation this is much easier to spot)

Share this post


Link to post
Share on other sites
FancyBonnie    1
12 minutes ago, bizziboi said:

Your local function sanitycheck misses a closing 'end', only the one for the 'if' is there.

(If you fix indentation this is much easier to spot)

So it should be like this?     

inst:ListenForEvent("sanitydelta", function(inst, data)
          local function sanitycheck (inst)
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
end

 

EDIT: OH wait that's what you mean I'll try that out!

EDIT 2: Guess this is tougher than I thought. Thought this one would work but still seems wrong.
inst:ListenForEvent("sanitydelta", function(inst, data)
    local function sanitycheck (inst)
    end
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end

I keep getting this error now..unknown.thumb.png.8255816e06ce96a1f5bd86ba0363a877.png

Share this post


Link to post
Share on other sites
thomas4846    603

thnx senpie bizziboi

also i think it should be like this

    inst:ListenForEvent("sanitydelta", function(inst, data)
          local function sanitycheck (inst)
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
    end)

i think this one is fixed

Share this post


Link to post
Share on other sites
FancyBonnie    1
6 minutes ago, thomas4845 said:

thnx senpie bizziboi

also i think it should be like this

    inst:ListenForEvent("sanitydelta", function(inst, data)
          local function sanitycheck (inst)
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:StartRegen(-1)
    else
    inst.components.health:StartRegen(0)
    end
    end)

i think this one is fixed

You left a bracket at "end)" So it kinda messed it up.
unknown.thumb.png.6aa480d5a669ce1102142929bd535122.png
Fixed it and got left with this. Gonna try to fix it from here maybe.

Share this post


Link to post
Share on other sites
FancyBonnie    1

Still not working, I'm trying this out now. Dunno if I'm getting hotter or colder.

  function Health:DoDelta(amount,overtime,cause) 
    if inst.components.sanity.currentsanity <= 18 then
    inst.components.health:DoDelta(-1)
    else
    inst.components.health:DoDelta(0)
    end
   end

Share this post


Link to post
Share on other sites
bizziboi    1,929

I think it should be more like (dunno if it'll work but it hopefully shouldn't throw a Lua syntax error on load)

 

inst:ListenForEvent("sanitydelta",
    function(inst, data)
        if inst.components.sanity.currentsanity <= 18 then
            inst.components.health:StartRegen(-1)
        else
            inst.components.health:StartRegen(0)
        end
    end
)
                                                        

 

Share this post


Link to post
Share on other sites
FancyBonnie    1
28 minutes ago, bizziboi said:

I think it should be more like (dunno if it'll work but it hopefully shouldn't throw a Lua syntax error on load)

 


inst:ListenForEvent("sanitydelta",
    function(inst, data)
        if inst.components.sanity.currentsanity <= 18 then
            inst.components.health:StartRegen(-1)
        else
            inst.components.health:StartRegen(0)
        end
    end
)
                                                        

 

Well, It doesn't crash. But didn't really do anything either, seems to give me a error when I resume at low sanity though.

"65: attempted to compare nil with number"

Thanks to some helpful users on discord. Got that part done! This was the code that worked the best.

 

 inst:ListenForEvent("sanitydelta",
    function(inst, data)
        if inst.components.sanity.current <= 18 then
            inst.components.health:DoDelta(-0.02)
        end
    end
)

Share this post


Link to post
Share on other sites
Ultroman    603

That's because inst.components.sanity.currentsanity is not a thing. It's inst.components.sanity.current, as you found out in your latest code snippet.

Sadly, your regen gets messed up if you eat a food that provides health regen, because there can only be one active regen at one time when using the health component's regen system.

The only reason why your code seems to work right now, is because the game has almost constant sanity changes, but if it's day and it's not raining and you're not close to anything with a sanity aura, your sanity will not be changing constantly, so you can still be at less than 18 sanity and not lose health from it. Also, "sanitydelta" is pushed every time a change happens to your sanity, so even an increase in sanity and also eating something that gives or removes sanity, will trigger additional health loss. This is not a good way to implement health degeneration over time. You need a task for this.

Do this instead:

inst:ListenForEvent("sanitydelta",
    function(inst, data)
		-- If a degeneration task is not currently running, and the player is below or at 18 sanity...
		if not inst.sanityinducedhealthdegen and inst.components.sanity.current <= 18 and not inst.components.health:IsDead() then
			-- Start a task that calls our degeneration function every second.
			inst.sanityinducedhealthdegen = inst:DoPeriodicTask(1.0,
				function(inst)
					-- Stop the degeneration task if the player has regained their sanity or they have died.
					if inst.components.sanity.current > 18 or inst.components.health:IsDead() then
						inst.sanityinducedhealthdegen:Cancel()
						return
					end
					inst.components.health:DoDelta(-1.2)
				end
			)
		end
	end
)

We use a task to administer the health degeneration every second. This task is only started when the sanity gets below or equal to 18 (and the player is not dead), and it stops itself when the sanity has been raised above 18 again (or the player has died).

Share this post


Link to post
Share on other sites
FancyBonnie    1
9 minutes ago, Ultroman said:

That's because inst.components.sanity.currentsanity is not a thing. It's inst.components.sanity.current, as you found out in your latest code snippet.

Sadly, your regen gets messed up if you eat a food that provides health regen, because there can only be one active regen at one time when using the health component's regen system.

The only reason why your code seems to work right now, is because the game has almost constant sanity changes, but if it's day and it's not raining and you're not close to anything with a sanity aura, your sanity will not be changing constantly, so you can still be at less than 18 sanity and not lose health from it. Also, "sanitydelta" is pushed every time a change happens to your sanity, so even an increase in sanity and also eating something that gives or removes sanity, will trigger additional health loss. This is not a good way to implement health degeneration over time. You need a task for this.

Do this instead:


inst:ListenForEvent("sanitydelta",
    function(inst, data)
		-- If a degeneration task is not currently running, and the player is below or at 18 sanity...
		if not inst.sanityinducedhealthdegen and inst.components.sanity.current <= 18 and not inst.components.health:IsDead() then
			-- Start a task that calls our degeneration function every second.
			inst.sanityinducedhealthdegen = inst:DoPeriodicTask(1.0,
				function(inst)
					-- Stop the degeneration task if the player has regained their sanity or they have died.
					if inst.components.sanity.current > 18 or inst.components.health:IsDead() then
						inst.sanityinducedhealthdegen:Cancel()
						return
					end
					inst.components.health:DoDelta(-1.2)
				end
			)
		end
	end
)

We use a task to administer the health degeneration every second. This task is only started when the sanity gets below or equal to 18 (and the player is not dead), and it stops itself when the sanity has been raised above 18 again (or the player has died).

Wow! Thanks for the info! I would've never known about that! My mod's almost done, So I'm just going to ask for your help since it seems like you know what you're doing, is there a simple way to use a shovel, without having a shovel? Just going to use the crafting animation, nothing to special. And how exactly would I make the charatcher call out the fact he's eating meat? Thanks so much though! Could I have your steam ID so when I get the artwork and everything done I could credit your help along with everyone else that has?

Share this post


Link to post
Share on other sites
Ultroman    603
5 hours ago, thomas4845 said:

jeez senpie ultroman is better then the devs please don't ban me

Not even close, but I have worked A LOT with regen stuff :) (check out my Stat Regen and Degen mod. It'll blow your mind :))

12 hours ago, FancyBonnie said:

Could I have your steam ID so when I get the artwork and everything done I could credit your help along with everyone else that has?

This is me. But you don't have to credit me. Just make a good mod and try not to break other mods while doing it ;) Also, try not to abandon your mod, or at least leave a note when you do, so people know.

12 hours ago, FancyBonnie said:

is there a simple way to use a shovel, without having a shovel? Just going to use the crafting animation, nothing to special.

Sorry, I haven't worked a lot with animations and actions. There are other more experienced people on here than me for this sort of thing. I'd advise you to start a separate thread with a specific title for this problem, in order to attract the helpful people who know a lot about this part of the game.

12 hours ago, FancyBonnie said:

how exactly would I make the charatcher call out the fact he's eating meat?

That's an easy one.

inst:ListenForEvent("oneat", function(inst, data)
	if inst.components.talker ~= nil and data and data.food and data.food:HasTag("meat") then
		inst.components.talker:Say("Erhmagherd! I ate the meats!")
	end
end)

 

Make sure that this last code snippet is put above the ismastersim check in your character's master_postinit, since we want him to say it on both client and server (I think).

Share this post


Link to post
Share on other sites
FancyBonnie    1
On 8/30/2019 at 8:46 AM, Ultroman said:

Not even close, but I have worked A LOT with regen stuff :) (check out my Stat Regen and Degen mod. It'll blow your mind :))

This is me. But you don't have to credit me. Just make a good mod and try not to break other mods while doing it ;) Also, try not to abandon your mod, or at least leave a note when you do, so people know.

Sorry, I haven't worked a lot with animations and actions. There are other more experienced people on here than me for this sort of thing. I'd advise you to start a separate thread with a specific title for this problem, in order to attract the helpful people who know a lot about this part of the game.

That's an easy one.


inst:ListenForEvent("oneat", function(inst, data)
	if inst.components.talker ~= nil and data and data.food and data.food:HasTag("meat") then
		inst.components.talker:Say("Erhmagherd! I ate the meats!")
	end
end)

 

Make sure that this last code snippet is put above the ismastersim check in your character's master_postinit, since we want him to say it on both client and server (I think).

inst:ListenForEvent("oneat", function(inst, data)
    if inst.components.talker ~= nil and data and data.food and data.food:HasTag("meat") then
        inst.components.talker:Say("Ugh, my stomach will never get used to meat..")
    end
end)

-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "wybie.tex" )
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.soundsname = "wilson"

I assume I put it correct? It says the "inst isn't declared"  

EDIT: I put it under it and it worked. Weird.

Share this post


Link to post
Share on other sites