Jump to content

Custom Attack speed,


Recommended Posts

Hey there. I've been trying to figure out a way to increase attack speed, for both a duration, and for eternity for custom characters, at the moment, I want to add my own addition as a potion of some sorts that increases attack speed, though most of the code listen around the forums, (setattackperiod, or setminimumattackperiod etc) have not seemed to work. Any help would be appreciated in pointing me in the right direction! Those above by the way only work for slowing down weapons. In no way can you raise it.

Link to comment
Share on other sites

Are you sure? You might be cheated by the animation still running at the same speed. Or maybe the next attack is delayed until the attack animation has played. That could be something to look into. You might have to somehow make the animations shorter as well, or at least play faster if that's possible, to make this work.

Link to comment
Share on other sites

1 hour ago, thomas4845 said:

i believe state graphs are used for animations right 

or are you trying to just make the attacks faster

 

Well if making the animations faster makes the attacks go out faster, than yes.. I suppose so.

Link to comment
Share on other sites

Yes. The stategraphs handle all the cooldowns, using number of frames. "attack" is just one of the states. There's also "throw" and "blowdart" etc. Each has their own animation(s) being played (which are a certain number of frames) and they also adhere to the inst.components.combat.min_attack_period using math.max. It's no small feat what you're trying to do.

Also, there are usually animation chains, so there's a "pre_attack" animation, and then the actual attack-animation which is "pushed" to play after the "pre_attack" animation has finished. It's quite complex.

Edited by Ultroman
Link to comment
Share on other sites

The main things you'll need to modify in the stategraph is timeout and timeline.time to get it functioning that is.

Animation can be kind of dealt with using AnimState:SetDeltaTimeMultiplier(multiplier)--although the animation looks really choppy at high multipliers.

The problem is you'll need to do it for each seperate attack state

below is a example of how I made the code for one of my characters for a friend which allows him to punch significantly faster than other characters.

--"stark's rapid punch attack"
AddStategraphPostInit("wilson", function(sg)
	local _attack = sg.states["attack"]
	local _onenter = _attack.onenter
	_attack.onenter = function(inst,...)
		_onenter(inst,...)--"call the original"
		if inst.prefab == "stark" then
			local hand = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
			local speed = TUNING.STARK.PUNCH.SPEED--"3"
			if (hand == nil or hand:HasTag("punch") or hand:HasTag("punchweapon")) then
				inst.sg:SetTimeout(inst.sg.timeout/speed)--"overide the timeout"
				inst.AnimState:SetDeltaTimeMultiplier(speed)
				for k, v in pairs(_attack.timeline) do--"overide the timeline"
					v.time = v.time/speed
				end
			end
		end
		return
	end
	local _onexit = _attack.onexit
	_attack.onexit = function(inst,...)
		if inst.prefab == "stark" then
			inst.AnimState:SetDeltaTimeMultiplier(1)
		end
		return _onexit(inst,...)
	end)
end)

Feel free to ask some questions, you will have to replicate this concept for each attack state you want, in my case I only want to make punches to be faster.

Edited by IronHunter
fixing tabs
Link to comment
Share on other sites

4 hours ago, IronHunter said:

The main things you'll need to modify in the stategraph is timeout and timeline.time to get it functioning that is.

Animation can be kind of dealt with using AnimState:SetDeltaTimeMultiplier(multiplier)--although the animation looks really choppy at high multipliers.

The problem is you'll need to do it for each seperate attack state

below is a example of how I made the code for one of my characters for a friend which allows him to punch significantly faster than other characters.


--"stark's rapid punch attack"
AddStategraphPostInit("wilson", function(sg)
	local _attack = sg.states["attack"]
	local _onenter = _attack.onenter
	_attack.onenter = function(inst,...)
		_onenter(inst,...)--"call the original"
		if inst.prefab == "stark" then
			local hand = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
			local speed = TUNING.STARK.PUNCH.SPEED--"3"
			if (hand == nil or hand:HasTag("punch") or hand:HasTag("punchweapon")) then
				inst.sg:SetTimeout(inst.sg.timeout/speed)--"overide the timeout"
				inst.AnimState:SetDeltaTimeMultiplier(speed)
				for k, v in pairs(_attack.timeline) do--"overide the timeline"
					v.time = v.time/speed
				end
			end
		end
		return
	end
	local _onexit = _attack.onexit
	_attack.onexit = function(inst,...)
		if inst.prefab == "stark" then
			inst.AnimState:SetDeltaTimeMultiplier(1)
		end
		return _onexit(inst,...)
	end)
end)

Feel free to ask some questions, you will have to replicate this concept for each attack state you want, in my case I only want to make punches to be faster.

So this is just an example? As this won't really do anything without all the states being called, and the timeline, and etc, yes? I really only want to gain attack speed from using one weapon, which is a custom weapon.

Link to comment
Share on other sites

This works as is for my character who punches faster if all you want to do is make it apply to a specific weapon you can modify the if statements there which even conveniently check for a weapon in your hand. lols

You do know how to check for prefab name or tag right?

Link to comment
Share on other sites

36 minutes ago, IronHunter said:

This works as is for my character who punches faster if all you want to do is make it apply to a specific weapon you can modify the if statements there which even conveniently check for a weapon in your hand. lols

You do know how to check for prefab name or tag right?

I getcha, sort of. but, hey won't know till I knock it I suppose, thanks, Ill reply later after results.

Link to comment
Share on other sites

No.. I can't really figure it out.

AddStategraphPostInit("wilson", function(sg)
	local _attack = sg.states["attack"]
	local _onenter = _attack.onenter
	_attack.onenter = function(inst,...)
		_onenter(inst,...)--"call the original"
		if inst.prefab == "AAATool" then
			local hand = inst.components.inventory:GetEquippedItem(AAATool) --swapped to the prefab name, nad name in game.
			local speed = TUNING.AAATOOL.PUNCH.SPEED--"3"
			if (hand == nil or hand:HasTag("punch") or hand:HasTag("AAATool")) then --Added a tag, to maybe make it work? Failed.
				inst.sg:SetTimeout(inst.sg.timeout/speed)--"overide the timeout"
				inst.AnimState:SetDeltaTimeMultiplier(speed)
				for k, v in pairs(_attack.timeline) do--"overide the timeline"
					v.time = v.time/speed
				end
			end
		end
		return
	end
	local _onexit = _attack.onexit
	_attack.onexit = function(inst,...)
		if inst.prefab == "AAAku" then --Character Prefab, Not sure if this would go here or not, tried both the Tool and the character.
			inst.AnimState:SetDeltaTimeMultiplier(1)
		end
		return _onexit(inst,...)
	end
end)

I've tried messing around but.. It doesn't seem to make a difference.

Link to comment
Share on other sites

Ok what is your weapons prefab name?

Also changing names of stuff without defining them is just asking for crashes, if you don't know how to make it work you should ask and learn.

Anyways did you want this weapon to provide this attack speed boost for all characters if they are wielding it or only your specific character and how much faster attack speed do you want?

Link to comment
Share on other sites

9 minutes ago, IronHunter said:

Ok what is your weapons prefab name?

Also changing names of stuff without defining them is just asking for crashes, if you don't know how to make it work you should ask and learn.

Anyways did you want this weapon to provide this attack speed boost for all characters if they are wielding it or only your specific character and how much faster attack speed do you want?

My weapon prefab name is AAATool, the weapon is only weildable by my character so all characters is fine, I'd like it to be 50% faster than a normal attacking weapon.

Well I didn't get any crashes, How would I go about defining them, I thought i was doing fine but I guess not.

Link to comment
Share on other sites

--"Iron_Hunter Faster Attack Speed"
AddStategraphPostInit("wilson", function(sg)
	local _attack = sg.states["attack"]
	local _onenter = _attack.onenter
	_attack.onenter = function(inst,...)
		_onenter(inst,...)--"call the original"
		if inst.prefab == "AAAku" then --"Check the spelling of AAAku to make sure its the correct casing"
			local hand = inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
			local speed = 1.5 --"1.5 x speed, do not set at 0 or you will crash from division by 0"
			if (hand and hand.prefab == "AAATool") then --"Check the spelling of AAATool to make sure its the correct casing"
				inst.sg:SetTimeout(inst.sg.timeout/speed)--"overide the timeout"
				inst.AnimState:SetDeltaTimeMultiplier(speed)
				for k, v in pairs(_attack.timeline) do--"overide the timeline"
					v.time = v.time/speed
				end
			end
		end
		return
	end
	local _onexit = _attack.onexit
	_attack.onexit = function(inst,...)
		if inst.prefab == "AAAku" then --"Check the spelling of your character's prefab to make sure its correct, normally prefabs are made lowercase"
			inst.AnimState:SetDeltaTimeMultiplier(1)
		end
		return _onexit(inst,...)
	end)
end)

No idea why my previous post didn't save this...

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