DangWoodchuck Posted May 2, 2016 Share Posted May 2, 2016 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): 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)? Link to comment Share on other sites More sharing options...
Mobbstar Posted May 2, 2016 Share Posted May 2, 2016 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. Link to comment Share on other sites More sharing options...
DangWoodchuck Posted May 2, 2016 Author Share Posted May 2, 2016 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? Link to comment Share on other sites More sharing options...
Mobbstar Posted May 3, 2016 Share Posted May 3, 2016 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? Link to comment Share on other sites More sharing options...
DangWoodchuck Posted May 3, 2016 Author Share Posted May 3, 2016 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? Link to comment Share on other sites More sharing options...
Mobbstar Posted May 4, 2016 Share Posted May 4, 2016 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), .... Link to comment Share on other sites More sharing options...
DangWoodchuck Posted May 4, 2016 Author Share Posted May 4, 2016 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"? Link to comment Share on other sites More sharing options...
Mobbstar Posted May 5, 2016 Share Posted May 5, 2016 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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.