Jump to content

Recommended Posts

So, here's one of my problems: I don't know how to code (At all, mostly) a weapon that attacks faster, by this I just mean a weapon that has a faster attack animation, I just wanted a spear that attacked 5% faster and one that attacked 25% faster, but I think that actually requires a code and not changing some value for what I've seen. (Any recommendations are also okay)

Edited by Nehuen721

So, I'm bringing this post again because I couldn't find a solution on the forums. 

I am trying to make this post's code, but it says I need to "Declare the stategraph", and with my little knowledge in programming it's confusing. 

The code looks like this:

--"Iron_Hunter Faster Attack Speed, thx"
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 == "bruno" 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.75 --"1.5 x speed, do not set at 0 or you will crash from division by 0"
			if (hand and hand.prefab == "custom_handitem") 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 == "bruno" 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)

and it gives me this crash:

Crash

2 hours ago, Chesed said:

Your code works fine for me (tested with my mod character and a hambat).

Your crash log suggests you're putting the code in your weapon's file. It should go in your modmain.lua.

Thanks so much, I couldn't make progress since I posted this, I'll try to learn a bit more of programming so I this dumb problems stop appearing, so yeah, thanks!

 

  • Health 1

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