Eusong Posted May 13, 2019 Share Posted May 13, 2019 I'm having an issue with making the player do a different animation when using a weapon other than the normal attack animation. He plays the animation and uses the weapon just fine, until it's over. Then about 75% of the time he repeats the animation and attack a second time, sometimes even a third. This is if I just tap control F and then let go during the first attack. Here's my code Modmain AddStategraphPostInit("wilson", function(sg) local old_doattack = sg.events.doattack.fn sg.events.doattack.fn = function(inst) local weapon = inst.components.combat and inst.components.combat:GetWeapon() if weapon and weapon:HasTag("spellbook") then if not inst.components.health:IsDead() and not inst.sg:HasStateTag("doing") and not inst.sg:HasStateTag("attack") then inst.sg:GoToState("book") weapon.components.weapon:OnAttack(inst, inst.components.combat.target) inst.sg:AddStateTag("attack") end else return old_doattack(inst) end end end) Weapon prefab local function onattack(inst, attacker, target) attacker:DoTaskInTime(2, function() if attacker.sg:HasStateTag("doing") then finishspell(inst,attacker,target) end end) end local function finishspell(inst, attacker, target) attacker.components.sanity:DoDelta(-TUNING.SANITY_SMALL) local pos = Vector3(target.Transform:GetWorldPosition()) local hit = SpawnPrefab("statue_transition_2") hit.Transform:SetPosition(pos.x, pos.y, pos.z) attacker.SoundEmitter:PlaySound("dontstarve/wilson/hit") if target.components.sleeper and target.components.sleeper:IsAsleep() then target.components.sleeper:WakeUp() end if target.components.health and not target.components.health:IsDead() then if target.components.combat then target.components.combat:SuggestTarget(attacker) if target.sg and not target.sg:HasStateTag("frozen") and target.sg.sg.states.hit then target.sg:GoToState("hit") end end target.components.health:DoDelta(-20) local crit = math.random() if crit > 0.7 then local critical = SpawnPrefab("explode_small") critical.Transform:SetPosition(pos.x, pos.y, pos.z) attacker.SoundEmitter:PlaySound("dontstarve/creatures/bishop/shotexplo") target.components.health:DoDelta(-40) end end attacker.sg:RemoveStateTag("attack") end Obviously finishspell is before onattack in the file, but I'm listing it below it because that's the order it's called in. Link to comment https://forums.kleientertainment.com/forums/topic/106046-unwanted-repeats-of-attacks/ Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now