Jump to content

Recommended Posts

NOTE: I'm not very good at talking about codes, so this might sound like gibberish.

 

 So I'm working on a mod to add more abilities/buffs for a certain creature, and I'm wondering how some buffs can be added appropriately to a creature's prefab/stategraph/brain file. One aspect I'm trying to add is the disarming ability, which is something the Goose has. To do this, I'm copying the disarm codes within the Goose files and bringing them to the creature I'm trying to modify, while editing some code strings (changing the "honk" animation to the "taunt" animation, changing the sounds into the ones the creature has, etc.). One code string that's getting in my way is the Disarm Timer, which is what makes the Goose decide when it should honk or not. No matter how many ways I try to edit the code strings, Don't Starve will either result in a crash, or with the modified creature not disarming at all. This is the code from the Goose's stategraph I'm trying to copy for the timer(minus the animation strings):

Code.png   I'd like to know how Don't Starve's timer codes work in general, please. Does anyone know what the problem would be? Would my problem be that I'm trying to make two different actions share the same animation (taunt)? 

Edited by DangWoodchuck
9 hours ago, Mobbstar said:

This is, suprisingly, a rarely used component. It is really just a cooldown, the GooseMoose uses it in her brain and prefab. So if you have copied those as well, you shouldn't edit these lines at all.

 Looking through the Goose's brain file, there's nothing that involves the timer for the disarming cool-down. I didn't edit the disarming cool-down code strings, I only edited other disarming code strings so that the creature can play its own animations and sounds while disarming. I got that part down, but all that's left is the timer between disarming attacks. Since I'm only copying those code strings, where do I place them in the other creature's Stategraph file?

inst:AddComponent("timer")
inst:ListenForEvent("timerdone", ontimerdone)

==>

local function ontimerdone(inst, data)
    if data.name == "WantsToLayEgg" then
        inst.WantsToLayEgg = true
    end

    if data.name == "DisarmCooldown" then
        inst.CanDisarm = true
    end
end

Any more questions?

11 hours ago, Mobbstar said:

inst:AddComponent("timer")
inst:ListenForEvent("timerdone", ontimerdone)

==>

local function ontimerdone(inst, data)
    if data.name == "WantsToLayEgg" then
        inst.WantsToLayEgg = true
    end

    if data.name == "DisarmCooldown" then
        inst.CanDisarm = true
    end
end

Any more questions?

 I've already copied all of those copy strings, but I removed the egg-laying code strings, for I don't want the creature to lay any eggs.

I've also copied this:     inst.CanDisarm = false

When it's in the files, the creature won't do anything, but when it is not, spawning the creature will result in crashing the game. This is the stategraph I made for the creature's disarming ability:

 State{
        name = "disarm",
        tags = {"busy"},

        onenter = function(inst)
            inst.AnimState:PlayAnimation("taunt")
        end,

        timeline =
        {
        TimeEvent(20*FRAMES, function(inst) inst.SoundEmitter:PlaySound("*****************/creatures/*******/taunt")
        GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.75, 0.01, 2, SHAKE_DIST)
        inst.DisarmTarget(inst, inst.components.combat.target) end), 
        },
         
        events=
        {
            EventHandler("animover", function(inst) inst.sg:GoToState("idle")
            end ),
        },
    },

Does anything look wrong?

Alright, got the whole "model not appearing" problem fixed, the timer now exists, but the creature still refuses to disarm. Is the stategraph string not appropriate?

Edited by DangWoodchuck

Are you sure you copied this part of the stategraph?

local function onattackfn(inst)
    if inst.components.health and not inst.components.health:IsDead()
       and (inst.sg:HasStateTag("hit") or not inst.sg:HasStateTag("busy")) then
        if inst.CanDisarm then
            inst.sg:GoToState("disarm")

        else
            inst.sg:GoToState("attack")
        end
    end
end

local events=
{
    EventHandler("doattack", onattackfn),
    ....

6 hours ago, Mobbstar said:

Are you sure you copied this part of the stategraph?

local function onattackfn(inst)
    if inst.components.health and not inst.components.health:IsDead()
       and (inst.sg:HasStateTag("hit") or not inst.sg:HasStateTag("busy")) then
        if inst.CanDisarm then
            inst.sg:GoToState("disarm")

        else
            inst.sg:GoToState("attack")
        end
    end
end

local events=
{
    EventHandler("doattack", onattackfn),
    ....

I copied all but the "fn" in both "onattack"s. Do I need the "fn"?

5 hours ago, DangWoodchuck said:

I copied all but the "fn" in both "onattack"s. Do I need the "fn"?

No you don't.

You should try placing "print()" in the attack timeline, the event callback and the event handler to trace the steps. e.g.

print("SETTING TIMER")
if not inst.components.timer:TimerExists("DisarmCooldown") then
    inst.components.timer:StartTimer("DisarmCooldown", 10)
    print("TIMER SET to 10 seconds")
end

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