Jump to content

How do I assign a unique nature naughtiness which eventually summons treeguards


Recommended Posts

Hi guys,


I want to assign my Wanda character her own unique value, sort of like naughtiness but not for killing innocents, rather for harming nature.


* Gains #Shenaniganism from cutting down any trees of differing sizes, digging saplings or grass tufts


* Loses #Shenaniganism from planting butterflies, pinecones, birchnuts, saplings or grass tufts

* When #Shenaniganism is high enough, a poison birch tree will spawn (alternatively, I might have a tree guard appropriate to the biome the player is in at the time spawn).  NOTE: this is in addition to the usual 1.33% chance of treeguards spawning while cutting down trees, so it is possible if the Shenaniganism is maxed while cutting trees with that 1.33% chance coming up at the same time, that both events will trigger simultaneously.

# Originally I thought of just hijacking naughtiness (it might work in solo DS), but more likely I will have to invent this different Shenaniganism personal value,  bit like Woodie's Log Meter for DST.  Worse comes to worst, I suppose I could just have gaining / losing sanity (but I think this has been done already by other developers, and I don't want to have players micro-managing sanity all the time)


I also want Sleeping treeguards to always awaken when Wanda passes by, and to be aggressive towards her when awakened this way or if summoned by other players (bushhat enables her to hide from them).  Also, she cannot pacify Treeguards by planting pine cones near them.


Cheers,

Rusty

Edited by RustyNayle
Link to comment
Share on other sites

Okay, I was reading through Woodie's Beaverness ("Log Meter") code from DST, and these are some of the stuff I extracted from his prefab.lua

 

local function GetBeaverness(inst)
    if inst.components.beaverness ~= nil then
        return inst.components.beaverness:GetPercent()
    elseif inst.player_classified ~= nil then
        return inst.player_classified.currentbeaverness:value() * .01
    else
        return 1
    end
end
 
local function IsBeaverStarving(inst)
    if inst.components.beaverness ~= nil then
        return inst.components.beaverness:IsStarving()
    elseif inst.player_classified ~= nil then
        return inst.player_classified.currentbeaverness:value() <= 0
    else
        return false
    end
end
 
local function onbeavernesschange(inst)
    if inst.sg:HasStateTag("nomorph") or
        inst.sg:HasStateTag("silentmorph") or
        inst:HasTag("playerghost") or
        inst.components.health:IsDead() or
        not inst.entity:IsVisible() then
        return
    end
 
    if inst.isbeavermode:value() then
        if inst.components.beaverness:GetPercent() > TUNING.WOODIE_TRANSFORM_TO_HUMAN then
            inst:PushEvent("transform_person")
 
 
 
local function common_postinit(inst)
    --beaverness (from beaverness component) added to pristine state for optimization
    inst:AddTag("beaverness")
 
        inst.GetBeaverness = GetBeaverness -- Didn't want to make beaverness a networked component
    inst.IsBeaverStarving = IsBeaverStarving -- Didn't want to make beaverness a networked component
 
local function master_postinit(inst)
    
    inst:AddComponent("beaverness")
 
inst.TransformBeaver = TransformBeaver
 
 
 
I'm guessing some of this stuff is inherent in the actual game, like what causes the beaverness to rise or fall, so so we're going to have to code all that stuff separately.  This is just very rough and I'm a total novice, but I'm guessing my end code might look a little like this:
 
local function GetShenanigan(inst)
    if inst.components.shenanigan ~= nil then
        return inst.components.shenanigan:GetPercent()
    elseif inst.player_classified ~= nil then
        return inst.player_classified.currentshenanigan:value() * .01
    else
        return 1
    end
end
 
local function IsShenaniganSoaring(inst)
    if inst.components.shenanigan ~= nil then
        return inst.components.shenanigan:IsSoaring()
    elseif inst.player_classified ~= nil then
        return inst.player_classified.currentshenanigan:value() <= 0
    else
        return false
    end
end
 
local function onshenaniganchange(inst)
    if  inst:HasTag("playerghost") or
        inst.components.health:IsDead() or
        not inst.entity:IsVisible() then
        return
    end
 
    if inst.isshenaniganmode:value() then
        if inst.components.shenanigan:GetPercent() > TUNING.SUMMON_TREEGUARD then
            inst:PushEvent("summon_treeguard")
 
local function common_postinit(inst)
--shenanigan (from shenanigan component) added to pristine state for optimization
    inst:AddTag("shenanigan")
 
        inst.GetShenanigan = GetShenanigan -- Didn't want to make shenanigan a networked component
    inst.IsShenaniganStarving = IsShenaniganSoaring -- Didn't want to make shenanigan a networked component
 
 
local function master_postinit(inst)
    inst:AddComponent("Shenanigan")
 
inst.SummonTreeguard = SummonTreeguard
 

 

So...  I'll have to define somewhere what increases / decreases this nature Shenanigan value, at what point the treeguard will be summoned.  I'll also have to come up with a widget so the value can be seen in game (until I can fine tune it so it's balanced, then I might remove it later, just like "naughtiness" doesn't have its own widget by default).  Of course, I'll have to code how the Treeguard is summoned (I think if we start with Poison Birch Trees, that will be easiest to manage, seeing whether it's fair or not).  I might even need to come up with some sort of animation for how a birch sapling appears, grows through the 3 stages, then transforms into a Poison Birchtree.

Link to comment
Share on other sites

@DarkXero , that's great, what would I add to the code so killing eyeplants raises it by 1, and killing a lureplant raises it by 5?  I was thinking about Totally normal Trees, but I guess they take a lot of hits to kill anyway, so there's no need to penalise doing so even further

Link to comment
Share on other sites

what would I add to the code so killing eyeplants raises it by 1, and killing a lureplant raises it by 5?
local function onkilled(inst, data)    local victim = data.victim    if victim.prefab == "eyeplant" then		inst.components.shenaniganism:AddValue(1)	elseif victim.prefab == "lureplant" then		inst.components.shenaniganism:AddValue(5)    endendself.inst:ListenForEvent("killed", onkilled)

In the component. The local function with the others. The event listening inside the class function.

 

You can transform that 1 and 5 into TUNING values just like the others so you can get them from modmain.

 

Wow, some trees take 15 hits to down, so that really raises the shenaniganism quite a lot. Does it slowly go down over time, like naughtiness?

 

No, it doesn't go down.

I put TUNING values in the modmain so you can touch them, probably should raise the max to 100.

 

If you make shenaniganism as naughtiness thinking it will punish you, it won't.

Getting Krampus is a challenge, not a punishment. Unless you are aiming your hits at Glommer.

Or you are using the game mechanics intelligently to murder a lot at get points.

 

If the values drop slow, then the drop is pointless, people won't wait for it.

If the values drop fast, then the component might as well not be there because it won't punish you.

Link to comment
Share on other sites

I might just make each hit against a tree to add only 0.4 shen points, so felling 3 large trees will only bring you to 18, which is not far off a treeguard event.  Will it cause a problem when you have say 19.6 shenaniganism, that adding a whole point would raise you above 20 so it wouldn't register the add?  Or, are you suggesting we just scale all of the events that add to shen value (as well as the max) by 5, meaning I can have each cut on a tree worth 2 out of 100 (0.4 x 5)?

Edited by RustyNayle
Link to comment
Share on other sites

I might just make each hit against a tree to add only 0.4 shen points, so felling 3 large trees will only bring you to 18, which is not far off a treeguard event. Will it cause a problem when you have say 19.6 shenaniganism, that adding a whole point would raise you above 20 so it wouldn't register the add? Or, are you suggesting we just scale all of the events that add to shen value (as well as the max) by 5, meaning I can have each cut on a tree worth 2 out of 100 (0.4 x 5)?

 

Yeah, scale it. Up the max so you don't have to use values lesser than 1.

You can like it as 50. 15*3 = 45 chops.

 

And no, it doesn't matter by how much you exceed the max, 19+1 is like 19+20000000, the threshold is met and the punishment comes.

Link to comment
Share on other sites

but the widget is clashing with those from other mods

 

Modify the SetPosition line in the widget in modmain. Modify the numbers, look at how the widget moves, then put the widget in a place where you can see it with both no mods and Always Status On.

Link to comment
Share on other sites

Okay, a couple of issues I'm having:

 

When the shen goes up to 100, it sets a treeguard to appear when Wanda is next near a tree.  This is fine, but if the player earns another 100 shen points before said treeguard is encountered, then two treeguards are queued to appear (this is the bug I don't want to occur, it should only ever be 1 treeguard queued to appear, and then the shen value should only reset AFTER Wanda encounters it).

 

For some reason, when Wanda fights a treeguard, each hit against it causes her to gain 25 shen points.  This is definitely way too much, as if the player decides to kite and kill the first treeguard that appears (74 hits * 25 = 1850 shen points in total), then 74 treeguards are queued to appear, which pretty much means any tree Wanda encounters for the rest of the game will turn into a treeguard.

 

Yeah, this sort of thing:

 

http://steamcommunity.com/sharedfiles/filedetails/?id=568942896

log.txt

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