freeslot("MT_PARRYTHINGIE","MT_PARRYTHINGIE2","sfx_parry", "S_STUNCELL2")
addHook("PlayerThink",function(player,mo)
 
 if player.isholdingm2 == nil
  then player.isholdingm2 = 0
   end
   
   if (player.cmd.buttons & BT_FIRENORMAL)
    then player.isholdingm2 = $ + 1
	 else player.isholdingm2 = 0
	  end
 
 
if (player.cmd.buttons & BT_FIRENORMAL) and player.isholdingm2 <= 1 and player.isparrying == 0 and player.parrycd == 0
    local ring = P_SpawnPlayerMissile(player.mo, MT_PARRYTHINGIE)
          player.isparrying = 9
		  player.parryiframes = 9
	end
	
	if player.parryiframes == nil
	 then player.parryiframes = 0
	  end
	  
	  
	if player.isparrying == nil
	 then player.isparrying = 0
	  end
	
	if player.isparrying > 0
	 then player.isparrying = $ - 1
	     end
		 
		 if player.parried == nil
		  then player.parried = false
		   end
		 
		 if player.parried == true
		  then player.parried = false
		      S_StartSound(player.mo, sfx_parry)
			  player.parryiframes = 32
			  player.didtheparry = true
			   end
			   
			   if player.parryiframes > 0
			    then player.parryiframes = $ - 1
				 end
				 
				 if player.isparrying == 1 and player.didtheparry == false
				  then player.parrycd = 32
				   end
				   
				  if player.isparrying == 1 and player.didtheparry == true
				   then player.didtheparry = false
				        player.isparrying = 0
						player.parrycd = 4
				    end
				   
				   
				  if player.parrycd == nil
		           then player.parrycd = 0
		             end
				   
				   if player.parrycd > 0
				    then player.parrycd = $ - 1
					 end
	  
	
 end)
 
addHook("ShouldDamage", function(player)
for player in players.iterate

if player.parryiframes > 0
 then return false end


end
end)

addHook("MobjThinker", function(mo)
for player in players.iterate

if mo.state == S_STUNCELL2
 then player.parried = true
  end

end
end, MT_PARRYTHINGIE)
