Jump to content

How can I make my custom character have a higher attack speed?


Scottnov

Recommended Posts

Greetings.

 

On my other help thread which was about the crashes I was having with my new custom character (Which, thanks to Mobbstar, WitchDoctEr16 and StalkinU, were resolved), I mentioned that I had a problem with the attack speed of my character. One of my character's perks was planned to be 1.5x attack speed, but as of right now, I can't find a way to make this happen. First, I tried changing this line:

 

self.min_attack_period = 4

 

To this:

 

self.min_attack_period = 2

 

This only made my attack speed slower, so obviously, I had to try something else.

WitchDoctEr16 suggested that I change it to:

 

inst.components.combat.min_attack_period = 0.2

 

...Instead, but that didn't seem to have much effect. The animation appeared to be slightly faster, but not by much. So, does anyone have any idea on how to set attack speed on a custom character to 1.5x, constantly?

 

Thanks in advance.

 

Link to comment
Share on other sites

When you say "higher attack speed" you surely mean "quicker attack" and not "more frequent attack". I don't think the min_attack_period shortens the animation, but only the time inbetween.

 

I think you'd need to change the player stategraph for quicker/sooner attacks (or at least two attacks in the full animation), as the stategraph contains information about when to do the attack. Maybe there is some mad-hack way of speeding up the animation without custom anim.zip

 

Writhe, Maxwells only Friend has a custom stategraph and anim.zip to allow them rapid-fire attacks.

Link to comment
Share on other sites

When you say "higher attack speed" you surely mean "quicker attack" and not "more frequent attack". I don't think the min_attack_period shortens the animation, but only the time inbetween.

 

I think you'd need to change the player stategraph for quicker/sooner attacks (or at least two attacks in the full animation), as the stategraph contains information about when to do the attack. Maybe there is some mad-hack way of speeding up the animation without custom anim.zip

 

Writhe, Maxwells only Friend has a custom stategraph and anim.zip to allow them rapid-fire attacks.

 

Actually, I do mean more frequent attacks. An example would be instead of hitting a beefalo 5 times in 3 seconds, the character could hit the beefalo 7-8 times in 3 seconds. However, the animation does need to match, but I'm pretty sure that won't mess up.

Try this line in your custom character.

inst.components.combat:SetAttackPeriod(0.35)
Based on what I've found, this should increase attack speed.
Just tried it, sadly, it didn't work. Thanks anyway, though.
Link to comment
Share on other sites

Bump.

 

Still open, does anyone know how to do this?

 

Okay since the other didn't work try adjusting the stategraphs.

    State{        name = "attack",        tags = {"attack", "notalking", "abouttoattack", "busy"},                onenter = function(inst)			--print(debugstack())            inst.sg.statemem.target = inst.components.combat.target            inst.components.combat:StartAttack()            inst.components.locomotor:Stop()            local weapon = inst.components.combat:GetWeapon()            local otherequipped = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)            if (weapon and weapon:HasTag("gun")) or (otherequipped and otherequipped:HasTag("gun")) then                inst.sg:GoToState("shoot")                return            end            if weapon then                inst.AnimState:PlayAnimation("atk")				if weapon:HasTag("icestaff") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_icestaff")				elseif weapon:HasTag("shadow") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_nightsword")                elseif weapon:HasTag("firestaff") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_firestaff")                else                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")                end            elseif otherequipped and (otherequipped:HasTag("light") or otherequipped:HasTag("nopunch")) then                inst.AnimState:PlayAnimation("atk")                inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")            else				inst.sg.statemem.slow = true                inst.AnimState:PlayAnimation("punch")                inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh")            end                        if inst.components.combat.target then                inst.components.combat:BattleCry()                if inst.components.combat.target and inst.components.combat.target:IsValid() then                    inst:FacePoint(Point(inst.components.combat.target.Transform:GetWorldPosition()))                end            end                    end,                timeline=        {            TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),            TimeEvent(12*FRAMES, function(inst) 				inst.sg:RemoveStateTag("busy")			end),				            TimeEvent(13*FRAMES, function(inst)				if not inst.sg.statemem.slow then					inst.sg:RemoveStateTag("attack")				end            end),            TimeEvent(24*FRAMES, function(inst)				if inst.sg.statemem.slow then					inst.sg:RemoveStateTag("attack")				end            end),                                },                events=        {            EventHandler("animover", function(inst)                inst.sg:GoToState("idle")            end ),        },    },    

You'll have to do this for every weapon in the game, just make sure you check to see if it's your character which is using the item on the increased version. If this doesn't work, I'm honestly not sure what would allow that to happen.

Link to comment
Share on other sites

Okay since the other didn't work try adjusting the stategraphs.

    State{        name = "attack",        tags = {"attack", "notalking", "abouttoattack", "busy"},                onenter = function(inst)			--print(debugstack())            inst.sg.statemem.target = inst.components.combat.target            inst.components.combat:StartAttack()            inst.components.locomotor:Stop()            local weapon = inst.components.combat:GetWeapon()            local otherequipped = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)            if (weapon and weapon:HasTag("gun")) or (otherequipped and otherequipped:HasTag("gun")) then                inst.sg:GoToState("shoot")                return            end            if weapon then                inst.AnimState:PlayAnimation("atk")				if weapon:HasTag("icestaff") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_icestaff")				elseif weapon:HasTag("shadow") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_nightsword")                elseif weapon:HasTag("firestaff") then                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_firestaff")                else                    inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")                end            elseif otherequipped and (otherequipped:HasTag("light") or otherequipped:HasTag("nopunch")) then                inst.AnimState:PlayAnimation("atk")                inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")            else				inst.sg.statemem.slow = true                inst.AnimState:PlayAnimation("punch")                inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh")            end                        if inst.components.combat.target then                inst.components.combat:BattleCry()                if inst.components.combat.target and inst.components.combat.target:IsValid() then                    inst:FacePoint(Point(inst.components.combat.target.Transform:GetWorldPosition()))                end            end                    end,                timeline=        {            TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),            TimeEvent(12*FRAMES, function(inst) 				inst.sg:RemoveStateTag("busy")			end),				            TimeEvent(13*FRAMES, function(inst)				if not inst.sg.statemem.slow then					inst.sg:RemoveStateTag("attack")				end            end),            TimeEvent(24*FRAMES, function(inst)				if inst.sg.statemem.slow then					inst.sg:RemoveStateTag("attack")				end            end),                                },                events=        {            EventHandler("animover", function(inst)                inst.sg:GoToState("idle")            end ),        },    },    

You'll have to do this for every weapon in the game, just make sure you check to see if it's your character which is using the item on the increased version. If this doesn't work, I'm honestly not sure what would allow that to happen.

 

Alright, but I do have some questions, though, to be honest, I have almost no programming knowledge, so please forgive the fact that I'm a filthy casual in this subject right now:

1: So, do I just put this into every weapon in the game's lua file, or the character's lua file? And what do I do with it? Replace something with it, add it to the bottom?

2: Wouldn't this cause every character in the game to have a faster attack speed? You did say to "check if it's your character which is using the item on the increased version", but I'm not quite sure what that means.

 

Again, I know it must be irritating to deal with someone with as little knowledge in scripting as I, but everyone has to start somewhere, right?

Link to comment
Share on other sites

Alright, but I do have some questions, though, to be honest, I have almost no programming knowledge, so please forgive the fact that I'm a filthy casual in this subject right now:

1: So, do I just put this into every weapon in the game's lua file, or the character's lua file? And what do I do with it? Replace something with it, add it to the bottom?

2: Wouldn't this cause every character in the game to have a faster attack speed? You did say to "check if it's your character which is using the item on the increased version", but I'm not quite sure what that means.

 

Again, I know it must be irritating to deal with someone with as little knowledge in scripting as I, but everyone has to start somewhere, right?

 

Don't sweat it, we've all been in the same boat. First I'd recommend downloading this mod: http://forums.kleientertainment.com/files/file/203-api-examples/

 

It has API examples of certain things which you are going to have to modify.

 

To answer your questions:

 

1: No you need to adjust the Stategraphs, not the actual weapon files. In the example I gave you, if you notive the 8*FRAMES, etc. those numbers is what you will need to adjust or simply add (* 0.5) to the end or the equation given.

 

2: Yes this is why you must add an if-then statement to determine if your character is the one using the weapon.

 

Example:

timeline=    {        TimeEvent(8*FRAMES*0.5, function(inst) if EXAMPLE_CHARACTER then inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end end),        TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),        TimeEvent(12*FRAMES*0.5, function(inst)             if EXAMPLE_CHARACTER then inst.sg:RemoveStateTag("busy") end        end),        TimeEvent(12*FRAMES, function(inst)             inst.sg:RemoveStateTag("busy")        end),                        TimeEvent(13*FRAMES, function(inst)            if not inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES*0.5, function(inst)            if inst.sg.statemem.slow and EXAMPLE_CHARACTER then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES, function(inst)            if inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),                  

Of course you will have to test if this would actually work, but I think what you are trying to do needs to be done by altering the actual amount of frames per action in the attack sequence.

Link to comment
Share on other sites

Don't sweat it, we've all been in the same boat. First I'd recommend downloading this mod: http://forums.kleientertainment.com/files/file/203-api-examples/

 

It has API examples of certain things which you are going to have to modify.

 

To answer your questions:

 

1: No you need to adjust the Stategraphs, not the actual weapon files. In the example I gave you, if you notive the 8*FRAMES, etc. those numbers is what you will need to adjust or simply add (* 0.5) to the end or the equation given.

 

2: Yes this is why you must add an if-then statement to determine if your character is the one using the weapon.

 

Example:

timeline=    {        TimeEvent(8*FRAMES*0.5, function(inst) if EXAMPLE_CHARACTER then inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end end),        TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),        TimeEvent(12*FRAMES*0.5, function(inst)             if EXAMPLE_CHARACTER then inst.sg:RemoveStateTag("busy") end        end),        TimeEvent(12*FRAMES, function(inst)             inst.sg:RemoveStateTag("busy")        end),                        TimeEvent(13*FRAMES, function(inst)            if not inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES*0.5, function(inst)            if inst.sg.statemem.slow and EXAMPLE_CHARACTER then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES, function(inst)            if inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),                  

Of course you will have to test if this would actually work, but I think what you are trying to do needs to be done by altering the actual amount of frames per action in the attack sequence.

Thanks for all this, but what file am I supposed to be editing? Where do I put the edited example?

Also, as a side note, I just tried putting a slightly edited version of the example you gave me into my character's prefab as a test (I didn't expect it to work), but it says the mod is "outdated" when I do.

 

Link to comment
Share on other sites

Thanks for all this, but what file am I supposed to be editing? Where do I put the edited example?

Also, as a side note, I just tried putting a slightly edited version of the example you gave me into my character's prefab as a test (I didn't expect it to work), but it says the mod is "outdated" when I do.

 

 

The file I gave you was for you to use outside of the game, not inside the game. Open the zip file and extract it to a work space. Open modmain.lua and look for StateGraph. That is the example you will need to use in order to get yours to work.

Link to comment
Share on other sites

The file I gave you was for you to use outside of the game, not inside the game. Open the zip file and extract it to a work space. Open modmain.lua and look for StateGraph. That is the example you will need to use in order to get yours to work.

 

Actually, I was talking about:

Example:

timeline=    {        TimeEvent(8*FRAMES*0.5, function(inst) if EXAMPLE_CHARACTER then inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end end),        TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),        TimeEvent(12*FRAMES*0.5, function(inst)             if EXAMPLE_CHARACTER then inst.sg:RemoveStateTag("busy") end        end),        TimeEvent(12*FRAMES, function(inst)             inst.sg:RemoveStateTag("busy")        end),                        TimeEvent(13*FRAMES, function(inst)            if not inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES*0.5, function(inst)            if inst.sg.statemem.slow and EXAMPLE_CHARACTER then                inst.sg:RemoveStateTag("attack")            end        end),        TimeEvent(24*FRAMES, function(inst)            if inst.sg.statemem.slow then                inst.sg:RemoveStateTag("attack")            end        end),                  
I know it's an example, but I still can't seem to figure out what to do with it. From what I can gather, I need to edit out "EXAMPLE_CHARACTER" and replace it with the prefab name of my own character.
Link to comment
Share on other sites

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.

×
  • Create New...