local N,j Tool.Equipped:connect(function(C)Character=Tool.Parent Player=game.Players:GetPlayerFromCharacter(Character)local f=(WaitFor(Tool)).HoldAnim()f.AnimationId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\056\056\055\052\051\053\057\050"local o=(WaitFor(Tool)).ThrowAnim()o.AnimationId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\056\056\055\052\051\053\054\054"N=Character.Humanoid:LoadAnimation(f)j=Character.Humanoid:LoadAnimation(o)if Now()>NextFireAt.Value then Handle.Transparency=0 C.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103"N:Play()else Handle.Transparency=1 Delay(NextFireAt.Value-Now(),function()C.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\087\097\105\116\067\117\114\115\111\114\046\112\110\103"Handle.Transparency=0 N:Play()end)end C.Button1Down:connect(function()if Now()>NextFireAt.Value then NextFireAt.Value=Now()+RELOAD_TIME local f=Handle:Clone()f.CanCollide=false local o=GrenadeScript:Clone()o.Parent=f o.Disabled=false;((WaitFor(o)).creator()).Value=Player local l=C.Hit.p-f.Position local b=l.y l=Vector3.new(l.x,0,l.z)local A=l.magnitude l=l.unit Velocity=math.min(120,40+A)local J=computeLaunchAngle(A,b,196.2)local R=math.sin(J)*Velocity local c=(l.x*math.cos(J))*Velocity local s=(l.z*math.cos(J))*Velocity f.CanCollide=false Delay(.1,function()f.CanCollide=true end)f.Velocity=Vector3.new(c,R,s)f.Parent=game.Workspace ThrowSound:Play()N:Stop(0)j:Play(0,1,1)Handle.Transparency=1 C.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\087\097\105\116\067\117\114\115\111\114\046\112\110\103"wait(RELOAD_TIME)N:Play()Handle.Transparency=0 C.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103"end end)end)Tool.Unequipped:connect(function()if ThrowSound then ThrowSound:Stop()end if j then j:Stop()end if N then N:Stop()end end)


local HoldAnim, ThrowAnim;

Tool.Equipped:connect(function(mouse)
	Character = Tool.Parent
	Player = game.Players:GetPlayerFromCharacter(Character)

	local HoldAnimSrc = WaitFor(Tool).HoldAnim()
	HoldAnimSrc.AnimationId = 'http://www.roblox.com/asset/?id=88743592'
	local ThrowAnimSrc = WaitFor(Tool).ThrowAnim()
	ThrowAnimSrc.AnimationId = 'http://www.roblox.com/asset/?id=88743566'

	HoldAnim = Character.Humanoid:LoadAnimation(HoldAnimSrc)
	ThrowAnim = Character.Humanoid:LoadAnimation(ThrowAnimSrc)

	--setup first anim / cursor cycle
	if Now() > NextFireAt.Value then
		Handle.Transparency = 0
		mouse.Icon = 'rbxasset://textures\\GunCursor.png'
		HoldAnim:Play()
	else
		Handle.Transparency = 1
		Delay(NextFireAt.Value - Now(), function()
			mouse.Icon = 'rbxasset://textures\\GunWaitCursor.png'
			Handle.Transparency = 0
			HoldAnim:Play()
		end)
	end

	mouse.Button1Down:connect(function()
		--we track the reload time like this so that the player can't fire faster with
		--rapid dis / re-equipping, which will actually be common usage with this gear.
		if Now() > NextFireAt.Value then
			NextFireAt.Value = Now() + RELOAD_TIME
			--
			local gr = Handle:Clone()
			gr.CanCollide = false
			local sc = GrenadeScript:Clone()
			sc.Parent = gr
			sc.Disabled = false
			WaitFor(sc).creator().Value = Player

			--calc velocity
			local toTarget = mouse.Hit.p - gr.Position
			local dy = toTarget.y
			toTarget = Vector3.new(toTarget.x, 0, toTarget.z)
			local dx = toTarget.magnitude
			toTarget = toTarget.unit

			Velocity = math.min(120, 40 + dx)

			local theta = computeLaunchAngle(dx, dy, 196.2)

			local vY = math.sin(theta)*Velocity
			local vX = toTarget.x * math.cos(theta) * Velocity
			local vZ = toTarget.z * math.cos(theta) * Velocity

			gr.CanCollide = false
			Delay(0.1, function()
				gr.CanCollide = true
			end)
			gr.Velocity = Vector3.new(vX, vY, vZ)
			gr.Parent = game.Workspace

			--play sound / anim
			ThrowSound:Play()
			HoldAnim:Stop(0)
			ThrowAnim:Play(0,1,1)

			--reload
			Handle.Transparency = 1
			mouse.Icon = 'rbxasset://textures\\GunWaitCursor.png'
			wait(RELOAD_TIME)
			HoldAnim:Play()
			Handle.Transparency = 0
			mouse.Icon = 'rbxasset://textures\\GunCursor.png'
		end
	end)
end)

Tool.Unequipped:connect(function()
	if ThrowSound then
		ThrowSound:Stop()
	end
	if ThrowAnim then
		ThrowAnim:Stop()
	end
	if HoldAnim then
		HoldAnim:Stop()
	end
end)
